Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


vb to foxpro conversion

Posted on 2011-03-04
Medium Priority
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:
int cbDIn(int BoardNum, int PortNum, unsigned short *DataValue)
Visual Basic
Function cbDIn(ByVal BoardNum&, ByVal PortNum&, DataValue%) As Long
function cbDIn(BoardNum:Integer; PortNum:Integer; var DataValue:Word):Integer; StdCall;
DataValue=Digital value returned here.
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
nResult = cbDIn(1, 10, DataValue) &&foxpro whines "Declare DLL returned an exception"
If I issue:
DECLARE integer cbDIn IN cbw32.dll integer,integer,string
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.
Question by:donrbrowning
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
LVL 43

Accepted Solution

pcelba earned 2000 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:
LVL 43

Expert Comment

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)

LVL 30

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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 30

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.
LVL 43

Expert Comment

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.
LVL 30

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.

Author Comment

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

Expert Comment

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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

721 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