LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a Visual C++ dll in labwindows

I am using a calibre PCI I2C card to program an EPROM. They sent me a driver which consists of a .h, .lib, and .dll files written for Visual C++. In the header file there is a line: "extern __declspec(dllimport) int WINAPI setup (int, int, int);" When I compile the program I wrote in labwindows it says "setup syntax error found 'identifier expecting ';' and it high lights the WINAPI word. I deleted the WINAPI word and regenerated a new dll import source and the program works...almost. The program freezes everytime I try to do a read and once in a while when I do a write. I used the same program in Visual C++ and it works fine so the software is written right. What do I do so I can use the Visual C++ .h, .lib,
and .dll in labwindows?
Download All
0 Kudos
Message 1 of 2
(2,924 Views)
Greetings tEng,
The identifier "WINAPI" is defined in windows header files, generally as "__stdcall". "__stdcall" defines the calling convention of the functions (it is the norm on Windows, whereas "__cdecl" is the norm elsewhere). The calling convention tells the compiler how to setup the stack before calling the function and how to clean it up afterwards. If the caller and callee are built with different calling conventions, a crash is likely to occur (either quickly or unpredictably). I bet the problem here is that CVI's default calling convention is __cdecl. Either change CVI's default calling convention (Options >> Build >> Default Calling Convention) or replace all instances of WINAPI with __stdcall. I would recommend doing this through the use of "
#define WINAPI DLLSTDCALL". See KnowledgeBase "2RCKK3TL: What is a Calling Convention in CVI and what is it Used For?" <> for more information.

Sincerely,
Jeremiah Cox
Platform Services Product Support Engineer
National Instruments
Message 2 of 2
(2,924 Views)