11-30-2010 03:16 AM
Hello everyone,
actually I'm facing little difficulties on how to get an external function getting called from within CVI (Version 2009).
I was supplied with a .H file and a .LIB file to call an external function from within my CVI project. The .H file looks like this:
void exportedFunction(double *parameter);
As far as I know, the external function was written with MS Visual C++ 6.
So I tried to statically link to the extern al function like this:
- Add the .H file and the .LIB file to the CVI project
- #include the .H file where I needed to call the external function
- do the external function call
When building I get an unresolved external function call error from CVI so this seems not to be working.
I made some searches around and got up with two possible issues. Maybe one of you can help me get a bit further and get things working.
1) The "real" function code is located in the DLL file which was not delivered to me. Or is there a way to get things done (call external functions) just with a .H and a .LIB file (without any .DLL file included)?
2) The external function does not export according to "C-Style" rules. The function signature in the .H file shows no things like
extern "C" __declspec(dllexport) void __stdcall ...
Or maybe it's a combination of both issues (missing .DLL + wrong export style of function)?
I guess I could get around the wrong export style of the function when I manage to write a wrapper around the original function that actually uses C-Style exporting. But I guess I need the .DLL file for this try as well.
Thank you for your answers.
Best regards,
Bernd
Solved! Go to Solution.
12-03-2010 05:23 PM
I don't think it is the fact that you don't have the DLL - it's not loaded until runtime, the compiler / linker shouldn't know or care if the DLL itself is on the system and available.
Do you get the error at compile time (CTRL-K) or when you link it (CTRL-M) ?
Mismatched calling convention seems more likely the culprit to me.
You can tell CVI which convention to use with the DLLEXPORT and DLLSTDCALL macros - have you tried using these with the function prototypes in the header file?
Menchar
12-06-2010 12:34 AM
There is no need for the dllexport stuff. There is also the option for a static library without any DLL. But the 'extern "C"' is essential, because it forces the C++ compiler, which was probably used to compile the library , to use C calling convention.
If you can't ask the provider of the library to provide a version which was compiled using C calling convention the way to go is to write a wrapper with VC++6 around that library which reexports the functions using C calling convertion. Something like
extern "C" type0 myfunc1(type1 arg1, ...) {
return func1( arg1,...);
}
for every function , you need to use.
BTW. "unresolved symbol" is the linker error message, you can expect if you try to link C code against a library build with C++ calling convention.
12-06-2010 03:44 AM
Thank you both for your input.
I managed to find out that the .LIB file is a statical library (that comes without a .DLL file).
Also I tried to write a wrapper in VC++ around the .LIB to export the needed functions in C-Style, like Markus suggested.
This seems to work quite well as far as I can see.
So I'll call this issue resolved, pending further notice.
Best regards,
Bernd