dbTalk Databases Forums  

How to convert Visual Basic dll function call to FoxPro?

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss How to convert Visual Basic dll function call to FoxPro? in the comp.databases.xbase.fox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Antonio Vieira
 
Posts: n/a

Default How to convert Visual Basic dll function call to FoxPro? - 10-12-2004 , 12:10 PM






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.

Reply With Quote
  #2  
Old   
Rick Bean
 
Posts: n/a

Default Re: How to convert Visual Basic dll function call to FoxPro? - 10-12-2004 , 02:38 PM






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

"Antonio Vieira" <apv (AT) netvisao (DOT) pt> wrote

Quote:
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.

Reply With Quote
  #3  
Old   
Antonio Vieira
 
Posts: n/a

Default Re: How to convert Visual Basic dll function call to FoxPro? - 10-13-2004 , 12:23 PM



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

Quote:
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


Reply With Quote
  #4  
Old   
Rick Bean
 
Posts: n/a

Default Re: How to convert Visual Basic dll function call to FoxPro? - 10-13-2004 , 02:41 PM



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

"Antonio Vieira" <apv (AT) netvisao (DOT) pt> wrote

Quote:
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


Reply With Quote
  #5  
Old   
Antonio Vieira
 
Posts: n/a

Default Re: How to convert Visual Basic dll function call to FoxPro? - 10-14-2004 , 08:30 AM



Rick,

Oh my god, you're absolutely right!
I'm shocked for not seeing this myself before, someone that
works with me pointed out that to me but I didn't check it,
I seldom do this kind of DLL function declaration and wasn't
sure about it. Anyway, it worked just fine and it really
tought me once more that the devil is in basic details.

Thank you very much for your insight Rick!


"Rick Bean" <rgbean (AT) NOSPAMmelange-inc (DOT) com> wrote

Quote:
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


Reply With Quote
  #6  
Old   
Antonio Vieira
 
Posts: n/a

Default Re: How to convert Visual Basic dll function call to FoxPro? - 10-14-2004 , 09:26 AM



Rick,

I've found a very useful web page with info about using API functions
with Visual FoxPro which serves as a nice tutorial on such matters.
The page address is

http://www.news2news.com/vfp/?article=1

Regards,

Antonio

"Rick Bean" <rgbean (AT) NOSPAMmelange-inc (DOT) com> wrote

Quote:
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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.