Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem calling a DLL function
Message
De
14/12/1998 18:31:30
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00166967
Message ID:
00167473
Vues:
17
>Ed,
>
>I haven't hit an API call that needed a negative integer input. My code only converts positive integers. Besides if I needed more than the simple functions I posted I'd just use a VC++ DLL wrapper instead.
>

Same here, however, he's using something written by somone else, and I'd be hard pressed to deny that I've never had someone pass in a -1 to do something in a .DLL that I've written...

In any case, here are two functions for signed LONGs:
FUNCTION NumToBinLong
*
*  Creates a 4 byte signed binary int equivalent to a C long from a number
*
*  Parameters:
*
*	tnNum			(R)  Number to convert
*
 	LPARAMETER tnNum
 	LOCAL x,n,i,b[4],neg
 	IF tnNum<0
		x=INT(-tnNum)
		neg=.t.
	ELSE
		x=INT(tnNum)
		neg=.f.
	ENDIF
	FOR i=3 TO 0 STEP -1
		n=INT(x/(256^i))
		b[i+1]=IIF(neg, IIF(i=0, 256, 255)-n, n)
		x=MOD(x,(256^i))
	ENDFOR
	IF neg
		FOR i = 1 TO 3
			IF b[i] = 256
				b[i] = 0
				b[i+1] = b[i+1] + 1
			ENDIF
		ENDFOR
	ENDIF
	RETURN CHR(b[1])+CHR(b[2])+CHR(b[3])+CHR(b[4])


FUNCTION LongToNum
	* Take a binary Long and convert it to a VFP Numeric
	LPARAMETER tcLong
	LOCAL b0,b1,b2,b3,nRetVal
	b0=asc(tcLong)
	b1=asc(subs(tcLong,2,1))
	b2=asc(subs(tcLong,3,1))
	b3=asc(subs(tcLong,4,1))
	if b3<128
		nRetVal = ( ( (b3*256 + b2)*256 + b1) * 256 + b0)
	else
		b3=255-b3
		*Note this is 2's complement, thus 255!
		b2=255-b2
		b1=255-b1
		b0=256-b0
		nRetVal= -( ( (b3*256 + b2)*256 + b1) * 256 + b0)
	endif
	RETURN nRetVal
>>One followup here - the QUAD code I left converts between DWORDs and VFP; the code will work fine as long as the number being converted is a positive integer in the range 0 to (2^31 - 1); if you have negative numbers, they'll convert incorrectly to values 2^31 or greater. I can post code for NumToBINLong and BINLongToNum if there's any need (I don't know what the code on your Web page does; I'm sure everyone and his brother has code that does this correctly by now...)
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform