Solved

vb to foxpro conversion

Posted on 2011-03-04
8
870 Views
Last Modified: 2012-05-11
Can someone help me convert this function call to VFP?
I am calling CBW32.dll which is used with data aquisition card from omega.
VFP is not a specifically supported language but should work.
They give examples of how to use the DLL with C/C++, Visual Basic and Delphi.
the examples are:
C/C++
int cbDIn(int BoardNum, int PortNum, unsigned short *DataValue)
Visual Basic
Function cbDIn(ByVal BoardNum&, ByVal PortNum&, DataValue%) As Long
Delphi
function cbDIn(BoardNum:Integer; PortNum:Integer; var DataValue:Word):Integer; StdCall;
Arguments
BoardNum=1
PortNum=10
DataValue=Digital value returned here.
Returns
Error code or 0 if no errors
DataValue = place holder for the state of the port - (on or off)

When I issue this from VFP:
DECLARE integer cbDIn IN cbw32.dll integer,integer,integer
DataValue=0
nResult = cbDIn(1, 10, DataValue) &&foxpro whines "Declare DLL returned an exception"
If I issue:
DECLARE integer cbDIn IN cbw32.dll integer,integer,string
DataValue=""
nResult = cbDIn(1, 10, DataValue)

 nResult returns a 0 which means it completed okay but I cant get any value from DataValue. it remains "" no mater whether the port is on or off.
I know parameter 1 and 10 are correct. It seens to have a problem with DataValue.
I think it may have something to do with "unsigned short*DataValue" or maybe the dataValue is binary or somthing. I have been trying differrent stuff for two days and cant read the port.
Thanks
0
Comment
Question by:donrbrowning
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 35040743
The DataValue is output parameter passed by reference, so you have to use @ prefix and reserve two bytes for result:

DECLARE integer cbDIn IN cbw32.dll integer,integer,string
DataValue = CHR(0)+CHR(0)
nResult = cbDIn(1, 10, @DataValue)

To convert string result into a number you may use following expression (hope the byte order is correct):

lnResult = ASC(DataValue) + 256 * ASC(SUBSTR(DataValue, 2, 1))

or CTOBIN() function: http://msdn.microsoft.com/en-us/library/sfw383zh(VS.80).aspx
0
 
LVL 42

Expert Comment

by:pcelba
ID: 35040777
One correction - Even the function declaration should contain reference prefix:

DECLARE integer cbDIn IN cbw32.dll integer,integer,@string
DataValue = CHR(0)+CHR(0)
nResult = cbDIn(1, 10, @DataValue)

0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 35042149
Yes, pcelba is right.

Anytime the c declaration has a pointer *something in it's parameters this translates to a parameter passed in by reference and not by value. The declaration of the parameter needs a @ and usage too.

Bye, Olaf.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 35042161
Correction: Not all pointers need call by reference, eg a const char* simply is a string to VFP, but you can nevertheless then also pass in the string by reference, it does not hurt, it just won't be modidfied.

Bye, Olaf.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 35043083
It seems the string formal parameter declaration does not require @ prefix because all strings are passed by reference. The function call then requires @ prefix before output parameter to allow return value propagation back to the passed variable.

But I did not test above assumptions.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 35045185
Yes, pavel, I already corrected myself. In thecase of the cbDIn() function there is no other string parameter though, I assume you talk about the general case of a string paramter, not used as output parameter.

Bye, Olaf.
0
 

Author Comment

by:donrbrowning
ID: 35056470
thanks to all,
Here is what worked
DECLARE integer cbDIn IN CBW32.dll integer,integer, integer @ DataVale
DataValue=0
=cbDIn(1, 10, @DataValue)
DataValue now returns 255 or 254 depending on the state of the port.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 35056715
Good to see you've updated our solutions to your needs.
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question