Cyril Posted December 11, 2006 Report Share Posted December 11, 2006 Hello I am new to Labview and i am trying to experiment a bit with Call Library Function Node. I made a dll using Borland C++ 5.02 compiler. This is my Dll C code: void add(long x, long *y){*y=x+*y;} But when i try to call the add function from my VI i get the following error: "The function name specified for this node cannot be found in the library. Right-click the Call Library Function node and select Configure, then choose the correct function name." I read the examples that come with labview but coulden't find the difference. I am sure that i have the correct function name. Does anybody know what is the problem? I am 95% sure that my problem is the code in my DLL. Can anyone tell me what the correct code should look like. In the zip file are my VI and DLL. Download File:post-5740-1165832611.zip Quote Link to comment
Jeffrey Habets Posted December 11, 2006 Report Share Posted December 11, 2006 This is probably caused by the name mangling of your c++ compiler, you should export your code as a C function, e.g. : #ifdef __cplusplus extern "C" { #endifvoid add(long x, long *y){*y=x+*y;}#ifdef __cplusplus}#endif Quote Link to comment
Cyril Posted December 11, 2006 Author Report Share Posted December 11, 2006 Thanks it worked with a minor modification. : #include <stdio.h> #ifdef __cplusplus extern "C" { #endif void __export add(long x, long *y) { *y=x+*y; } #ifdef __cplusplus } #endif For me it didn't work without the __export. Could you explain me what these line are for? _____________________________ #ifdef __cplusplus } #endif _____________________________ Where do i have to place them if i have a DLL with more functions. Quote Link to comment
Cyril Posted December 12, 2006 Author Report Share Posted December 12, 2006 I also tried pass and receive strings to a DLL but not succesfull. Can anyone tell me what's wrong with the following DLL? Download File:post-5740-1165936619.zip Quote Link to comment
Jeffrey Habets Posted December 20, 2006 Report Share Posted December 20, 2006 First to answer your question, the #ifdef __cplusplus } #endif is the closing bracket for the Extern "C" { part.. I also tried pass and receive strings to a DLL but not succesfull. Can anyone tell me what's wrong with the following DLL? The reason why your dll call didn't work is that your return type is char and in the LV call library node you have it configured as pointer to string. The VI in the attached zip will work with your dll, I changed the return type of your function to U8. Also look at the comments I added to your .c file. There are faults in there too. (In LV you can compare strings that way, not in C. ) Download File:post-906-1166610996.zip Quote Link to comment
Rolf Kalbermatter Posted January 16, 2007 Report Share Posted January 16, 2007 For me it didn't work without the __export.Could you explain me what these line are for? _____________________________ #ifdef __cplusplus } #endif _____________________________ Where do i have to place them if i have a DLL with more functions. The __export is the Borland way of hinting to the linker that the function needs to be exported from the DLL. MS Visual C uses for that __declspec(dllexport). Another way of doing this is to create a .def file. But all of these things are highly compiler specific. The #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif are to tell the compiler to use standard C function name handling (disable C++ name mangling). You need to put these around the function prototype declarations of all functions that get exported from the DLL. Typically this is done at the begining and end of the header file(s) that define the exported function prototypes but for simple DLLs where you have only the C source file you can also put it around the function implementation itself. Please note that C++ name mangling is also compiler specific so if you want to create a library or DLL to be used in other compilers than the one that was used to create it disabling name mangling for exported symbols is usually a good idea. I'm sure 5 minutes of smart googling would have given you these answers too. Rolf Kalbermatter Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.