Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using STRUCT CLASS
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Using STRUCT CLASS
Miscellaneous
Thread ID:
00259023
Message ID:
00259023
Views:
60
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


*** 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
Fred Besterwitch, MCP

The harder you work. The luckier you get.
Next
Reply
Map
View

Click here to load this message in the networking platform