LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

error when calling DLL

Hi
I wrote a DLL file from visual C++ and I test run it in Visual C++, it's running fine. I stick it to labview by using call library function node, and run it. I got an error

Debug Assertion Failed!
C:\Program Files\National Instruments\LabVIEW 7.1\LabVIEW.exe
File afxwin1.inl
line 19

I tried both C and standard call (WINAPI), they don't work.

this is from the h file that I export

extern "C" int PASCAL EXPORT StartSessionWrapper(CString* SessionName);
extern "C" int PASCAL EXPORT ReceiveDataFromServerWrapper(CString* Data);
extern "C" int PASCAL EXPORT SendDataToServerWrapper(CString* Data);
extern "C" int PASCAL EXPORT CloseWrapper();



Anyone has any idea why this error happens and how I can fix it?
0 Kudos
Message 1 of 4
(2,572 Views)
It appears that you have made an MFC DLL. There are likely two problems: one, you need to call AFX_MANAGE_STATE(AfxGetStaticModuleState( )); inside all of your entry points. This should fix the assertion. The second problem you will run into is that the MFC CString* data type and the call library node CStr data type are not compatible. A call library node CStr is a char* data type, which is vastly different than the MFC CString. You need to change the CString* parameter to a char* if you want to pass in a LabVIEW string.
0 Kudos
Message 2 of 4
(2,570 Views)
The AFX_MANAGE_STATE(AfxGetStaticModuleState( )); works! Thank you so much. I changed CString to char* by adding some conversion code. The conversion seems to work only when I convert from char* to CString (when I send data from LabVIEW to C DLL), but it doesn't work when I convert from CString to char (when I send the data from C DLL to LabVIEW). I wonder how you usually convert CString to whatever text data type that labview accepts?
0 Kudos
Message 3 of 4
(2,549 Views)
You can pass a string from LabVIEW into a char* and use strcpy to copy the CString into the char*. The most important thing, however, is to make sure that there is enough memory allocated for the LabVIEW string. What I usually do to ensure this is create a U8 array of the correct size (using the Initialize Array function) and then use the Byte Array to String function to convert it to a string.
0 Kudos
Message 4 of 4
(2,544 Views)