LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert c++ code to labview dll

Hi,

 

I have some code written in C++ that calls a dll and I I need to change this into Labview. Somebody has tried before and it works for some messages (there are 10 messages (Num_Msg) and this was using message number 5) but not all of the messages work.

I don't really understand C++ but can almost see what is going on compared to the labview but I think the labview code is wrong

 

Can anyone help?

Download All
0 Kudos
Message 1 of 5
(3,218 Views)

The example C++ code that you've provided is not very helpful, since it doesn't include how pMsg is defined. It does, however, include a massive amount of C++ code that doesn't relate to the question you're asking. Can you please post only the relevant information about how to call the function, including any documentation you might have about it?

 

You have a couple of issues. It appears that you believe pMsg is an array of U32. In that case, you should preallocate the array in LabVIEW (for example using Initialize Array). You also tried to set the minimum array size of pMsg to msgLength, but you didn't wire a value to the input, so LabVIEW will default it to 0 and use that as the minimum array size. As a result, you're passing a 0-length array. Your DLL may then try to write more than 0 elements to the pointer, which will likely later crash LabVIEW.

0 Kudos
Message 2 of 5
(3,155 Views)

Hi, thanks for the reply. I'm the middle man here so will find out what i can tomorrow and see if i can get more of the c++ code. Thanks

0 Kudos
Message 3 of 5
(3,129 Views)

I think the C code shown is not what is in the DLL that he tries to call but rather a command line program that calls the DLL. The relevant part is here:

 

// call BMO message reading function preparation
pfn_IPLectMsgBMO = (DLL_Function_IP_Lect_MsgBMO)GetProcAddress(hDLL,"IP_Lect_MsgBMO");
// call BMO message reading function
returnCode = pfn_IPLectMsgBMO((void *)p_Msg,&msgLength, l_MsgNum);		

Other than that I fully agree that the buffer allocation is wrong. The configuration to allocate a buffer with msgLength elements seems to be well meant but the msgLength is not initialized with a valid value and therefore 0 is used and the buffer is allocated with 0 elements.

 

Aside from that there are a few potential problems. Most likely msgLength is meant to be in number of bytes, not number of int32, eventhough you may want to define the buffer preferably as array of init32 since the elements in it should be interpreted as int32 and 4 byte floats. So better would be probably to remove the configuration to allocate a minimum size for the p_Msg buffer and instead allocate that array explicitedly with Initialize Array but with a 4 times smaller number than what you pass to msgLength.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 5
(3,088 Views)

Hi beam7,

I am an Application Engineer at National Instruments UK. I was wondering if your problem has been solved? It seems like the other forum users gave you some relevant information, have you tried what they advised you?

Some advice I could give you is to read the documentation of the function from your .dll file carefully, if it is available. Usually this gives the information to format your dll call properly.  Also the return type of the .dll call contains often a reference to a certain error. Try to use this error message to find out what the error of the function is. Even so the error terminal of the call function  gives a could indication of what the problem might be.

The issue I’m seeing on your screenshot right now is the following. As you specify that the Array format of the p_Msg parameter is an Array Data Pointer, which points to the first value of your array, you have to create another parameter to indicate the size of the array.  This parameter turns out to be msgLength but instead of reading this parameter with an indicator, you should write to it with a control.

I hope this information could help you with your problem. If you have any more questions,  I am happy to help you.

Best regards,
Jonas Laenens

Application Engineer
National Instruments UK

0 Kudos
Message 5 of 5
(2,970 Views)