Solution
There are several different reasons LabVIEW might crash while calling a DLL function. Methods to prevent this type of crash are discussed in the following sections of this document:
If the calling convention specified in the Call Library Function Node does not match the calling convention of the DLL, it can cause a crash. The calling convention is specified in the lower right portion of the Call Library Function node window, as seen below.
When using the C calling convention, the caller is responsible for cleaning up the stack. When using the standard calling convention, the called function is responsible for cleaning up the stack. If the caller (LabVIEW) and the called DLL function do not use the same calling convention, then they will either both take things off the stack or neither of them will. Either situation can cause LabVIEW to crash when the called function returns.
If the application works fine in the LabVIEW development environment and it crashes when run as a built executable, try running the executable as administrator.
- Double click on the Call Library Function Node to access its configuration window.
- Change from using the absolute file path for the library or object you are calling to either the relative file path or just the library name.
- For example, if you need to call User32.dll, you could use either the absolute file path C:\Windows\System32\user32.dll, the equivalent relative file path %windir%\System32\user32.dll, or user32.dll within the Call Library Function options menu. Either of the latter two will prevent this crash.
If using the relative path or the Library Name doesn't prevent the crash, you can also select Specify path on diagram in the configuration windows, as shown below:
In this case, in the path in input, you'll need to specify the library name instead of the path to the library:
If you do not wire all of the inputs and outputs of a Call Library Function Node, the DLL function will overwrite unallocated memory and cause LabVIEW to crash.
If you do not wire the inputs, the DLL function will overwrite unallocated memory. If you do not wire the outputs, LabVIEW assumes the DLL function does not need the allocated memory passed on the input side and will use it for something else.
Note: If your second input is a pointer to your first input, then your first input does not require an output.
If not enough memory is allocated or the DLL function writes more than has been allocated, the DLL will overwrite reserved LabVIEW memory space and cause LabVIEW to crash. Make sure that memory is allocated properly before passing in and reading out arrays, strings, or waveforms from DLLs.
Many DLL functions take allocated memory, passed by pointer or value, write to this memory, and return it. If the memory is not allocated properly, it may cause a crash. For example, consider the following function:
double *Waveform (double *waveform, uInt32 size); The proper way to allocate the memory, in this case, is to initialize the array with the number of elements specified by the size parameter, not by passing in an empty array. The image below demonstrates the proper method.
The most likely problem is that the DLL function being called has corrupted the memory. If you pass arrays or strings to the DLL, the DLL function cannot dynamically resize the array. Writing beyond the last element of the array or string could corrupt the memory and this may not be obvious until LabVIEW is closed.
Try using a different Error Checking level in the Call Library Function Node, as the
Maximum level can return a warning if the function being called in the shared library or DLL writes beyond the space allocated for the specified string or array parameter. For more information check the Error Checking section of the
Call Library Function Node dialog box.
Calling the DLL function from LabVIEW with incorrect parameter datatypes (by value, reference, handle, etc.) can cause the function to unintentionally point to an incorrect memory location resulting in faulty data, or even a crash of LabVIEW or Windows.
If a function attempts to perform an illegal operation, it might crash LabVIEW. If you are not the author of the function, contact the writer of the function.
If you built the DLL in LabVIEW and you want to show the front panel of the DLL VI, there are two requirements that you must follow, else you can experience exception 0xC0000005.
- The Call Library Function Node must be set so that the DLL call is allowed to run in any thread. This is set by changing the Thread radio button from Run in UI thread to Run in any thread. All calls to LabVIEW-built shared libraries should specify Run in any thread. If you configure the Call Library Function Node using LabVIEW-built shared libraries and specify Run in UI thread, LabVIEW might hang and require you to restart. For more information, reference Call Library Function Dialog Box.
- The calling VI must not be running in the User Interface thread. This can be checked by selecting File»VI Properties from the pulldown menu, selecting Execution from the Category list, and making sure that the Preferred Execution System is standard, instrument I/O, data acquisition, other 1, or other 2. The same as caller option should not be chosen because the parent VI could be running in the user interface thread.