Solved

vb to foxpro conversion

Posted on 2011-03-04
8
861 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 60
clicking a shape in a frame array vb6 3 48
How to translate this 2-line while loop into C from Perl? 8 134
MySQL recovery 7 28
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

735 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