LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL call: null pointer on string

Solved!
Go to solution

Hello all!

Searching this forum before I found a similar thread which unfortunately didn't solve my problem.

 

Goal: the function int dcp_check(char **info) is supposed to return a string when getting a null pointer. This works nice in C compiled code in Visual Studio. This is a Profinet DCP check for a PCAP installation. So everyone willing to try this and has any PCAP installed, should be able to run it with error code 0.

  

Problem: I have tried everything in LV and cannot figure it out. Either the DLL call crashes LV or the returned data isn't a string.

What did I try:

1. Defining it as U8 array, with and without array pointer setting. That makes it actually impossible to feed a null pointer, unless I feed 4 bytes of 0. But doesn't work.

2. Defining it as string, with C string pointer setting or handle, where any handle setting crashes LV. The C string pointer seems logical, but can only feed a string, empty or not.

 

Is there any chance to get this working?

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

There is this (sort of) KB article: https://forums.ni.com/t5/Developer-Center-Resources/Passing-and-Receiving-Pointers-with-C-C-DLLs-fro...

Clear so far, but not fully. My case is case 2, pointer reception by reference. In other DLL calls I need the pointer, in some the value. So the dereferencing

int dcp_open(const char *name, dcp_dev_t *dev, char **errmsg) should be done as "Numeric" and "Unsigned pointer-sized integer" and "Pointer to value", a situation which isn't depicted here, because the screenshot under "Receving pointers" only references to case 1.

0 Kudos
Message 2 of 8
(1,860 Views)
Solution
Accepted by topic author MaSta

I cannot run your example succesfully, getting return value 6 from dcp_check.

 

But I think this should work. You pass a zero as pointer sized integer by reference and should receive the pointer to the string. Then you can get the string length and copy it into LabVIEW's memory space using MoveBlock.

Message 3 of 8
(1,841 Views)

Thanks. I actually tested dpc_check() without my licence dongle to not return error 6. Error 6 means "no licence found". 

 

I got further, trying different things. Since some of the calls initiate frames on the Ethernet, I can see the reaction on wireshark. The other functions like dcp_open(), dcp_close or dcp_initiateall() work, since they have a simpler definition.

 

Currently I'm struggling on the function call for struct dcp_resp *dcp_poll_resp(dcp_dev_t dev), because in the DLL call node I cannot define the return type as struct pointer or, what LV usually uses in this case, "Adapt to type". 

0 Kudos
Message 4 of 8
(1,835 Views)

@cordm:

That really worked. I found the pointer to data conversion with MoveBlock also, like, 1-2 hours ago, tried it in another VI, but didn't succeed at that point.

Here's the expected string:

MaSta_0-1691671559695.png

 

0 Kudos
Message 5 of 8
(1,829 Views)

I dug further, finding https://forums.ni.com/t5/Developer-Center-Resources/Calling-C-C-DLLs-Containing-Simple-and-Complex-D...

The return type of the dcp_pollresp() is a struct. The one example (Returning A Value Complex Struct Added.vi) shows how the dereference the struct pointer, but it looks a hell of an effort for only three struct members.

0 Kudos
Message 6 of 8
(1,819 Views)

Wow, this turned out easier than I thought, since MoveBlock can dereference complex structures.

 

MaSta_0-1691674507601.png

 

0 Kudos
Message 7 of 8
(1,806 Views)

The examples overcomplicates things a bit. The first three MoveBlocks could be replaced with another GetValueByPointer (or MoveBlock as you discovered) and an intermediate struct.

 

In your case the struct is simple in that there are no pointers to chase. It is just big.

0 Kudos
Message 8 of 8
(1,802 Views)