LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with call library .dll

Solved!
Go to solution

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.

 

Download All
0 Kudos
Message 1 of 8
(2,833 Views)

Would you please provide your C++ source?

0 Kudos
Message 2 of 8
(2,797 Views)

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.


GCentral
0 Kudos
Message 3 of 8
(2,782 Views)

Hello,

 

please find code in visual studio in att.

 

Best regards.

0 Kudos
Message 4 of 8
(2,760 Views)

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

 

Message 5 of 8
(2,745 Views)

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:

changes.png

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).


GCentral
Message 6 of 8
(2,732 Views)

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.

Download All
0 Kudos
Message 7 of 8
(2,719 Views)
Solution
Accepted by milan87

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.

Message 8 of 8
(2,693 Views)