09-21-2018 01:15 PM
Hello,
I am trying to call c++ function SendCANMessage from .lib file into my CVI project by following steps from this link:
Link (Part: 2nd way to use a DLL).
I have included 2 .h and 2 .c++ files into DLL project in Visual Studio, added __declspec(dllexport) in front of functions that I want to use in CVI
and built project successfully. Then I have added .lib and .dll files that I got from this build into my CVI project. and tried to call one of functions from .c file (from CVI). When i build project, it says:
Function declaration in .h file is: CAN_ERROR SendCANMessage(CAN_msg *pMsg, DWORD dwTimeout); and I have
defined CAN_ERROR, CAN_msg and DWORD earlier in my .c file.
I found that -10 means this: "Identifier not defined globally in the module.", but i don't know what to do about it.
I think that CVI don't see any of functions in .lib and .dll files and i need help how to include it properly, because I just added
these files by Edit->Add Files To Project and added files. I provided archive with all files that are included in CVI project.
Best regards,
Igor
Solved! Go to Solution.
09-22-2018 08:57 AM
Are you sure you create the DLL and lib file in Visual C as the same bitness than what you run in LabWindows/CVI?
09-24-2018 03:33 AM
Make sure that the functions exported from the VC dll are C-style functions.
See http://www.ni.com/white-paper/3341/en/#toc9 for details.
Also, why don't you use the 1st part in the document you linked? It is easier.
09-24-2018 07:17 AM
Thank you for your answers,
the problem was that I have generated bad dll and lib files.
I couldn't include extern "C" in front of functions because that functions are members of class and I got linkage error, so I needed new .h file
where I have put all definitions from two header files (RT_COM.h and RT_CAN.h) and wrap it with extern "C" {}. Also I have added declarations of functions with extern "C" __declspec(dllexport) in front of them. When I built this in VS i got new dll and lib files, copied dll, lib and h files to CVI project folder, added lib to project and included h file in my c file. Example of usage this c++ functions in c program is shown bellow:
You can see .h file in attachment.