LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Integrate CVI into VC++ using DLL

Hello

Refering to NI app note AN094, I have been successfully done option1: define user interface callback in third-party compiler (Microsoft Visual C++ 6), but I have trouble with option 2: define user interface callback as DLL to be linked into external compiler (VC6).
I'm using the codes given in the app note. The errors that I'm getting are:

--------------------Configuration: OffOn - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/OffOn.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

OffOn.exe - 2 error(s), 0 warning(s)

I wonder if anyone has successfully done option 2 with VC6.

I guess one can get the job done knowing one of the two options mentioned in the App note, but my enquiring mind wants to know what I have done wrong. Any comments or advices are greatly appreciated.

Regards
hhnguyen
0 Kudos
Message 1 of 4
(3,578 Views)
CVI ships with several DLL examples. Look at ..\CVI\samples\dll\simple\readme.txt. mydll.prj, and simple.prj.
Do you still have a main in your DLL project? CVI DLL's use DllMain instead, but you don't call it directly. Put the code you want to call into another function and export that.
If you're calling your CVI DLL from C++, don't forget to extern "C" everything.
For some more details, look here.
0 Kudos
Message 2 of 4
(3,569 Views)
Thank Al S

Your inputs are very helpful. I have gotten the option 2 in the app to run in VC6. Here is a list of things, I had to change to make it work:

*Under Option 2, step 2: when use CodeBuiler in the CVI UIR editor to generate the code, the first function prototype should be: int __stdcall InitUIForDLL(void); instead of int InitUIForDLL(void);

*Under Option2, step 11: when asked to create source code .cpp for VC6, instead of using int __stdcall WinMain() as given in the app, use int main()

It took awhile, but I have learnt something.

Thanks
hnguyen
0 Kudos
Message 3 of 4
(3,566 Views)
You do need to specify a calling convention for exported functions. It can be either __stdcall or __cdecl. In the message I linked to my earlier response, it shows the following example.
extern int __cdecl MyFunction(int myInt);

VC++ should be able to create projects which call either main() or WinMain().
0 Kudos
Message 4 of 4
(3,553 Views)