07-31-2018 10:04 AM
The following crashes LabVEW every time. Similar simple code with the other functions also crashes (e.g. DSSetHandleSize(), DSDisposeHandle(), etc) What am I doing wrong?
I'm using Windows 10, LabVIEW 2018, and Visual Studio 2017.
The C Code:
#include <windows.h> #include "extcode.h" #define DLL_EXPORT _declspec (dllexport) BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } DLL_EXPORT uint32_t handle_size(const UHandle h) { return DSGetHandleSize(h); }
The LabVIEW code:
The Result
07-31-2018 01:08 PM - edited 07-31-2018 01:15 PM
A cluster is NOT stored in a handle. Only strings and arrays are. So it is not strange that DSGetHandleSize() fatally crashes when given a pointer to a cluster.
Right click on your Call Library Node and select "Create .c file...". Then you will see in the resulting *.c file what is really passed to the DLL in terms of C datatypes for your cluster.
It will look something like this:
#include "extcode.h" #include "lv_prolog.h" typdef struct { int32_t elm1; int32_t elm2: } RefnumType; #include "lv_epilog.h" uint8_t FunctionName(RefnumType *refnum) { }