Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using STRUCT CLASS
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00259023
Message ID:
00259171
Vues:
15
>Im trying to use the foll code in VFP from VB. Is the VFP translation right and am I using the Struct class correctly..
>
>
>****VB Setup
>Public Declare Sub RUNENGINE Lib "Endev32.dll" (ByRef request As restruct, ByRef result As restruct)
>
>Public Type restruct ' Defining restruct to be a byte array
>temp(1 To 1024) As Byte
>End Type
>
>Public result As restruct ' result buffer is a byte array
>Public request As restruct ' request buffer is a byte array
>
>*******************************************************************************************
>** VFP 5.0 - Setup
>Set ClassLib to Struct
>Declare String RUNENGINE in Endev32.dll ;
> String @ResultArray,;
> String @RequestArray
>
>

There's no need to use STRUCT here; just init two variables cRequest and cResult and make them 1000 characters long; a VFP string is essentially a byte array from the perspective of an API; simply address members as

SUBST(variable name,array element member number,1), and pass them by reference as in your example:

x=RUNENGINE(@lcResult,@lcRequest)

You can use STUFF() or concatenation to build the array for you.

>*** Open Database in VB Code
>' Open database
>
>Private Sub Open_database_Click()
>
>' text contains the command O along with the facet name selected from the ListBox
>' plus the open mode (2) and ^Z as a terminator
>Text = "O" & Left(List2.Text, 8) & Chr(2) & Chr(26)
>
>' Copy ASCII characters to a byte array
>Call SetRequest(request, 1, Text)
>
>' Set the size of the results block to 1024 bytes
>result.temp(1) = 0
>result.temp(2) = 4
>
>' Call database engine
>Call RUNENGINE(result, request)
>
>' Display the status code for the O command
>Text3.Text = result.temp(3)
>*****
>** Open Database in VFP
>lcText="OWEBK"+CHR(2)+chr(26)
>loResult = CreateObject("Result")
>loRequest = CreateObject("Request")
>
>SetResult(loRequest,1,lcText)
>
>loResult.ResultArray[1]=0
>loResult.ResultArray[2]=4
>
>lcResult=loresult.GetString()
>lcRequest = lorequest.GetString()
>x=RUNENGINE(@lcResult,@lcRequest)
>? loresult.ResultArray[3]
>
>Define class Result as Struct
> Dime ResultArray[1024]
> cMembers = "b:ResultArray"
>EndDefine
>Define class Request as Struct
> Dime RequestArray[1024]
> cMembers = "b:RequestArray"
>EndDefine
>
>** VFP 5.0 Method
>Function Setresult
>lparameters toStruct,tStart,tString
>*** Fill passed Array
>
>local x,i
>
>x=len(allt(tstring))
>For i = 1 to x
> tostruct.RequestArray[i]=ASC(SUBSTR(tString,i,1))
>Endfor
>
>** VB Method
>** Generate request byte array for transfer to DLL
>Public Sub SetRequest(request As restruct, Start As Long, text As String)
>
>X = Len(text)
>For i = 1 To X
> ' Copy ASCII character to byte array
> request.temp(i) = Asc(Mid(text, i, i + 1))
>Next i
>End Sub
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
Répondre
Fil
Voir

Click here to load this message in the networking platform