11-04-2019 07:42 AM
Hello All,
I wrote dll in Visual basic, and tried to open with call library function node. VI in att.
It should call only one function CalcCRC from dll, but labview collapse and shows error . in att.
Dll is written in c++.
Can anyone knows how to overcome this....?
Thanks.
Solved! Go to Solution.
11-04-2019 09:36 AM
Would you please provide your C++ source?
11-04-2019 07:18 PM
As a guess, I'd say you're carrying out an inappropriate operation on some memory in your C++ code.
Perhaps you have an out-of-bounds access (e.g. *(myPtr)[8] when *(myPtr)[7] is the last element) or misaccessing the pointer (see this link to a SO question: dereferencing-a-pointer-to-an-array)
Alternatively, you might be trying to free the memory or allocate new memory, and I think either of those would cause an issue for you here.
For better than a guess, please attach the C++ function as JICR suggested.
11-05-2019 12:18 AM
Hello,
please find code in visual studio in att.
Best regards.
11-05-2019 01:25 AM - edited 11-05-2019 01:35 AM
Compare the function prototype in LabVIEW with your source code. Data types don't match, and argument order is swapped. Also, you must not wire a constant to the size argument but the actual array size.
C
unsigned int CalcCRC(unsigned char *buf, unsigned char size)
LabVIEW
int32_t CalcCRC(uint32_t size, uint8_t *buf);
If you are still having trouble, I suggest using a debugger: https://forums.ni.com/t5/LabVIEW/Debugging-a-c-dll-from-visual-studio-2010/m-p/2347074/highlight/tru...
Or you could just implement the code in LabVIEW.
Edit: Calling convention should be C
11-05-2019 02:36 AM - edited 11-05-2019 02:38 AM
Hi milan,
Thanks for the code.
As cordm pointed out, the argument order was switched, and the calling convention was wrong.
Correctly just the first of these issues still produces a crash, but fixing both gives you a working VI.
I attached the example VI you gave, saved back to 2015.
You'll see the changes to the call here:
I also set the minimum size to "size", but this shouldn't be necessary so long as you're careful with the sizes of your array in LabVIEW and C(++). Essentially it ensures that if you pass an array with fewer than "size" elements, it will add elements to make sure that the array passed is actually large enough (i.e. "size" elements long).
Edit: I see looking at my image, that I didn't change the datatype of size. If you use an unsigned char in C, you should use a U8 in LabVIEW (not the U32 it currently has configured).
11-05-2019 04:05 AM
Hello,
thanks for your help. This is a progress. There is no error now.
But also there is no result.
I entered values {17,3,0,0,0,87} and should get 41990. But instead it gives always 0.
I tried this functions in visual studio as application, and it works on console.
But when I create dll with this functions, it doesn`t work from labview.
I also put InitCRC function into CalcCRC to call InitCRC when CalcCRC is called form LV.
Thanks.
In att.
11-05-2019 05:56 AM
Your InitCRC code has a nice bug in it: The outer loop does not terminate. Because mask is an unsigned char, it will always be <256 and will overflow from 255 to 0. In your console application you changed its datatype to int.