![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi everybody, I'm trying to figure out the way to convert a small Visual Basic 6 project to Visual FoxPro 7, but I'm stuck in a couple of details. First, in VB6 I have a struct definition, plcadrtype, and a variable of that type. Type plcadrtype adr As Byte SEGMENTID As Byte SLOTNO As Byte RACKNO As Byte End Type Global plcadr(5) As plcadrtype In the same code module are defined the functions of a DLL to be used later. The function I'm stuck with involves the plcadrtype type definition. Declare Function load_tool Lib "w95_s7.dll" (ByVal nr As Byte, ByVal dev As String, adr As plcadrtype) As Long This function is then called at the beginning like this: plcadr(0).adr=2 plcadr(0).segmentid=0 plcadr(0).slotno=0 plcadr(0).rackno=2 res = load_tool(1, "S7ONLINE", plcadr(0)) ----- In VFoxPro I declared the function like this: Declare Long load_tool in w95_s7 Byte nr,String dev,Long adr Public plcadr[5,4] local res, nAdr plcadr[1,1]=2 plcadr[1,2]=0 plcadr[1,3]=0 plcadr[1,4]=2 nAdr=plcadr[1,1]*16777216+plcadr[1,2]*65536+plcadr[1,3]*256+plcadr[1,4] res=load_tool(1, "S7ONLINE", cAdr) I'm getting a persistent error message when I call the function: "Too few arguments". What am I doing wrong and how it should be done? Thanks for any help. |
#3
| |||
| |||
|
|
Antonio, Normally to duplicate an API structure, it's best to pass a properly stuffed string. In your case with just four Bytes, it's pretty easy. Declare Long load tool in w95 s7 Byte nr, String dev, String adr Public plcadr[1,4] && for this example local res, nAdr plcadr[1,1]=2 plcadr[1,2]=0 plcadr[1,3]=0 plcadr[1,4]=2 cAdr=chr(plcadr[1,1])+chr(plcadr[1,2])+chr(plcadr[1,3])+chr(plcadr[1,4] ) res=load tool(1, "S7ONLINE", cAdr) Note: Depending on how the API was written, you may need to add a "null" character on the end of either one or both passed strings. i.e. res=load tool(1, "S7ONLINE"+chr(0), cAdr) or res=load tool(1, "S7ONLINE"+chr(0), cAdr+chr(0)) In general, to use structures there are a number of utilities that can make that simpler. One is at http://fox.wikis.com/wc.dll?Wiki~ApiStructureClass~VFP, there's another available in the UT VFP Downloads - http://www.universalthread.com/VisualFoxPro/. Rick |
#4
| |||
| |||
|
|
Hi Rick, I also thought for a moment that it would be a simple task to stuff those four bytes and feed it to the function, but after trying several alternatives I'm really puzzled with it. I eagerly tried your sugestion and the possible variations but the error message was always the same: "Too many arguments". Funny thing is, it will give me that error even if I only pass the first parameter. Only without parameters it returns a different error message. The Visual Basic program works alright, so what's the secret? Is there another alternative or should I run and check those links about structures already? Thanks for your help! Antonio "Rick Bean" <rgbean (AT) NOSPAMmelange-inc (DOT) com> wrote Antonio, Normally to duplicate an API structure, it's best to pass a properly stuffed string. In your case with just four Bytes, it's pretty easy. Declare Long load tool in w95 s7 Byte nr, String dev, String adr Public plcadr[1,4] && for this example local res, nAdr plcadr[1,1]=2 plcadr[1,2]=0 plcadr[1,3]=0 plcadr[1,4]=2 cAdr=chr(plcadr[1,1])+chr(plcadr[1,2])+chr(plcadr[1,3])+chr(plcadr[1,4] ) res=load tool(1, "S7ONLINE", cAdr) Note: Depending on how the API was written, you may need to add a "null" character on the end of either one or both passed strings. i.e. res=load tool(1, "S7ONLINE"+chr(0), cAdr) or res=load tool(1, "S7ONLINE"+chr(0), cAdr+chr(0)) In general, to use structures there are a number of utilities that can make that simpler. One is at http://fox.wikis.com/wc.dll?Wiki~ApiStructureClass~VFP, there's another available in the UT VFP Downloads - http://www.universalthread.com/VisualFoxPro/. Rick |
#5
| |||
| |||
|
|
Antonio, Well I double checked, and there is no BYTE available for a DECLARE DLL statement, so you may need to use a STRING there two! Declare Long load tool in w95 s7 STRING nr, STRING dev, STRING adr ... res=load tool(chr(1), "S7ONLINE", cAdr) ... Rick |
#6
| |||
| |||
|
|
Antonio, Well I double checked, and there is no BYTE available for a DECLARE DLL statement, so you may need to use a STRING there two! Declare Long load tool in w95 s7 STRING nr, STRING dev, STRING adr ... res=load tool(chr(1), "S7ONLINE", cAdr) ... Rick |
![]() |
| Thread Tools | |
| Display Modes | |
| |