Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I use this DLL?
Message
From
17/07/2007 16:55:59
 
 
To
17/07/2007 12:42:51
Elyse Pomerantz
Dynamic Data Concepts, Inc.
Brooklyn, New York, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01241170
Message ID:
01241286
Views:
34
This message has been marked as the solution to the initial question of the thread.
Hi,

try this one ...
returning and passing structure types directly on the stack is very uncommon.
Hard to translate to VFP code, had to look at the disassembly to see what the C compiler produced.
&& the pointers to the structures are passed as hidden parameters
DECLARE CivilToHebrew IN kdate.dll STRING @ retval, INTEGER day, INTEGER month, INTEGER year
DECLARE GetParsha IN kdate.dll STRING @ retval, INTEGER dayandmonth, INTEGER year, INTEGER diaspora 

LOCAL lcHDate
lcHDate = SPACE(6)
CivilToHebrew(@lcHDate,5,1,2002)

LOCAL lnDay, lnMonth, lnYear
lnDay = WordToNum(SUBSTR(lcHDate,1,2))
lnMonth = WordToNum(SUBSTR(lcHDate,3,2))
lnYear = WordToNum(SUBSTR(lcHDate,5,2))

&& to pass a structure by value on the stack we have to split it into several
&& parameters, a VFP string will not work cause it's never put on the 
&& stack directly, only it's pointer (memory address) is passed
LOCAL lcReading, lnDayMonth
lcReading = SPACE(12)
&& combine the first two WORD values of the HDATE_T struct into an integer
lnDayMonth = BITOR(BITLSHIFT(lnMonth,16),lnDay)
GetParsha(@lcReading, lnDayMonth, lnYear, 0)

LOCAL lnReading1, lnReading2, lnSpecial
lnReading1 = DWORDToNum(SUBSTR(lcReading,1,4))
lnReading2 = DWORDToNum(SUBSTR(lcReading,5,4))
lnSpecial = DWORDToNum(SUBSTR(lcReading,9,4))

FUNCTION NumToWORD
*
*  Creates a C USHORT (WORD) from a number
*
*  Parameters:
*
*	tnNum			(R)  Number to convert
*
	LPARAMETER tnNum
	*
	*  x holds an int
	*
	LOCAL x
	x=INT(tnNum)
	RETURN CHR(MOD(x,256))+CHR(INT(x/256))
ENDFUNC

FUNCTION WORDToNum
	*	Take a binary WORD (16 bit USHORT) and convert it to a VFP Numeric
	LPARAMETER tcWORD
	RETURN (256 *  ASC(SUBST(tcWORD,2,1)) ) + ASC(tcWORD)
ENDFUNC

FUNCTION DWORDToNum
	* Take a binary DWORD and convert it to a VFP Numeric
	* use this to extract an embedded pointer in a structure in a string to an nPtr
	LPARAMETER tcDWORD
	LOCAL b0,b1,b2,b3
	b0=asc(tcDWORD)
	b1=asc(subs(tcDWORD,2,1))
	b2=asc(subs(tcDWORD,3,1))
	b3=asc(subs(tcDWORD,4,1))
	RETURN ( ( (b3 * 256 + b2) * 256 + b1) * 256 + b0)
ENDFUNC
NumToWord, WordToNum etc are from download #9482 -> credits to Ed Rauh

Shalom :)

Christian
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform