LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Visual C DLL/LIB problem in LabWindows

I'm having problems importing a DLL into LabWindows 5.5. The DLL was created in Visual C++ 6.0 and contains the declspec(dllexport) stdcall format. The .lib file won't import, and when I use the Generate Import Library function, everything will work good until I get into a large loop when creating a file...once the file is more than 30 MB, I get a stack overflow. If I use the same DLL source in Borland and import that DLL and LIB, I don't have any issues...even when shrinking the stack size in LabWindows. My copy of LabWindows is set up to be compatible with Visual C++ and to use the cdecl call (although changing that to stdcall does not change anything.) Any ideas as to what is going on?
0 Kudos
Message 1 of 3
(3,235 Views)
Never mind...closer inspection at the header file shows that the header is acually doing declspec(dllexport) cdecl when compiled with Visual C++. The moral of the story is that you must make CERTAIN that the DLLs you are importing and creating LIBs for are stdcall dlls and not cdecl. I guess I'm still curious as to why LabWindows gives the option to use cdecl since it apparently isn't always compible with it...like this case. ?
0 Kudos
Message 2 of 3
(3,235 Views)
Hello Scott,

Labwindows/CVI should not have a problem with compatibility with a DLL using the C calling convention. As you probably know, the differences in calling conventions determine how memory is allocated and deallocated by the processor. I would try the following things:

1. Make sure that when you are testing the code in CVI and in Boardland that you are using the exact same code.

2. If you still get different behavior between the two environments, try testing them on the same computer.

3. Make sure to be careful about what memory is being allocated by the DLL code itself and make sure that you keep track of deallocating correctly. It may be that you are calling a constructor multiple times that only needs to be called once (for example).
Or you could try to change the code in your loop so that memory is deallocated each iteration instead of all at the end of your program. Here is a link to a KnowledgeBase explaining how to free memory that is created in a DLL by malloc in CVI:

http://ae.natinst.com/operations/ae/public.nsf/fca7838c4500dc10862567a100753500/75abab24080b4eeb852563b60042cd14?OpenDocument

In addition, I will also provide some other relevant links. The first is a knowledge base explaining the differences in calling convention and the second goes through the steps of how to create an import library for a DLL in LabWindows/CVI.

http://ae.natinst.com/operations/ae/public.nsf/fca7838c4500dc10862567a100753500/97ec1ca826fffe0386256c710014290d?OpenDocument

http://ae.natinst.com/operations/ae/public.nsf/fca7838c4500dc10862567a100753500/ebce04f31cbb9ace862569290071cb28?OpenDocument

All three of these KnowledgeBases are public on our website at www.ni.com/support. I hope that these references will
be of help to you. Take care!

Aaron B.
National Instruments
0 Kudos
Message 3 of 3
(3,235 Views)