Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem calling a DLL function
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00166967
Message ID:
00167123
Views:
26
>Hi Ed,
>
>Here's the Visual Basic code that calls the function SLS_REQUEST in the DLL SlsApi.dll. This sample code was supplied by the dll vendor.
>
>Type SLS_REQUEST
> UnitsReserved As Long
>End Type

This is a VFP INTEGER parameter; if embedded in a structure, it's a 4 byte string that can be converted/deconverted with a small VFP-only piece of code.

>
>Type SLS_PERMIT
> 'State as integer 'state of licence permit
> UnitsGranted As Long
> AccessKey As Long
>End Type

This will be represented as an 8 byte string

>
>Type SLS_CHALLENGE
> Protocol As Long
> Size As Long
> ChallengeData As SLS_CHALLDATA
>End Type


Oops. This will be a string, but we need to know what SLS_CHALLDATA looks like before we can construct it.
>
>Declare Function SLS_REQUEST Lib "SlsApi" Alias "SLS_Request" ( _
> ByVal pszProductID As String, _
> ByVal pszUserName As String, _
> pRequest As SLS_REQUEST, _
> pPermit As SLS_PERMIT, _
> plLicenceHandle As Long, _
> pChallenge As SLS_CHALLENGE) As Long
>


VFP equivalent declaration, and converters for DWORDs:
DECLARE INTEGER SLS_REQUEST IN SLSAPI.DLL ;
      STRING @ lpszProductID, ;
      STRING @ lpsUserName, ;
      INTEGER SLS_REQUEST, ;
      STRING SLS_PERMIT, ;
      INTEGER plLicenseHandle, ;
      STRING SLS_CHALLENGE

FUNCTION DWORDToNum
	* Take a binary DWORD and convert it to a VFP Numeric
	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)

FUNCTION NumToBinDWORD
*
*  Creates a 4 byte binary string equivalent to a C DWORD from a number
*
*  Parameters:
*
*	tnNum			(R)  Number to convert
*
 	LPARAMETER tnNum
 	LOCAL x,n,i,b[4]
	x=INT(tnNum)
	FOR i=3 TO 0 STEP -1
		b[i+1]=INT(x/(256^i))
		x=MOD(x,(256^i))
	ENDFOR
	RETURN CHR(b[1])+CHR(b[2])+CHR(b[3])+CHR(b[4])
I'm not sure about VB's declarations against structure that contain atoms; you might have to change INTEGER SLS_REQUEST to INTEGER @ SLS_REQUEST. There are examples in lots of places here on UT that show how to convert an integer to/from a 4 byte section of a string; ULONGS and DWORDs are simply represented as 4 byte long hexadecimal values, low-order byte to high-order byte ordered; you can convert using the two sample functions I gave above (for the rest of the world, yes it ain't pretty, but the two functions do work.)

>Dim vRequest As SLS_REQUEST
>Dim vPermit As SLS_PERMIT
>Dim vChallenge As SLS_CHALLENGE
>
>vRequest.UnitsReserved = 0
>vPermit.AccessKey = 0
>vPermit.UnitsGranted = 0
>
>m_Error = SLS_REQUEST(m_strProductID, m_strUserName, vRequest, vPermit, m_hLicence, vChallenge)
>
>I know you asked for C code but I fumble around a bit better with VB than C. Hope this is sufficient.
>
>Thanks,
>Carl
>
>
>>>I'm trying to call a function in a DLL provided by a third party using VFP5. The sample code provided includes implementations for C++, VB and Delphi but none for VFP. The sample code for some of the function calls reference structures (instead of Short, Long, String) as the parameter type. Knowing nothing about structures, I'm stuck.
>>>
>>>Anybody ever handled something like this before ?
>>
>>All the time. Typically, strings are used to construct structures; things get a bit more complicated where the structure contains embedded pointers to other things. If you post the typedef for the structure in C and the C prototype for the function, we might be able to help.
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform