LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to translate C++ declaration to C

Solved!
Go to solution

Hello,

 

I have a DLL that I want to use in a program developped by CVI (FDS version 8.5.1). The DLL comes with some documentation including an include file (*.h), where all the function declarations are given. So usually I would simply include this header file, unfortunately this file was written for C++ and contains function declarations of the following type:

 

typedef void (__stdcal *fp SOMETYPE) (double &, double &, long &, long ) .

 

Me and the compiler are confused by the '&', I know 'double' and 'double *', but not 'double &'... The same for CVI which complains with a syntax error, found '&' expecting ')'.

 

So obviously I have to manually translate this C++ header file into C style - but I have no idea how to do this... May be somebody could assist me? Thanks!  

0 Kudos
Message 1 of 3
(3,695 Views)
Solution
Accepted by topic author Wolfgang

It's been a while since I've done any C++, but AFAIK, you can re-declare the function as:

 typedef void (__stdcal *fp SOMETYPE) (double *, double *, long *, long )

in the header, and call it from your code by passing pointers or "address of" variables. 

 

In this case the '&' in the function declaration means "by-reference".  It's kind of like pointers in C, but allows for more error checking (eg - can't be NULL, can't be re-assinged, etc), and probably aids the compiler in optimizations.  If you're interested, search google for C++ references, or you can check out wikipedia:

http://en.wikipedia.org/wiki/Reference_(C%2B%2B)

 

Message 2 of 3
(3,687 Views)

Thank you, this indeed solved my problem.

 

To summarize it for some future reference:

 

1) in the function declaration, replace the '&' with an '*':

typedef void (__stdcal *fp SOMETYPE) (double &) should be changed to typedef void (__stdcal *fp SOMETYPE) (double *)  

2) in the function call, then use the address, '&': DLLfunctioncall (&value)

 

Wolfgang

0 Kudos
Message 3 of 3
(3,645 Views)