08-10-2023 05:03 AM
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?
Solved! Go to Solution.
08-10-2023 06:19 AM
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.
08-10-2023 07:21 AM
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.
08-10-2023 07:39 AM - edited 08-10-2023 07:49 AM
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".
08-10-2023 07:46 AM - edited 08-10-2023 07:48 AM
@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:
08-10-2023 08:04 AM
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.
08-10-2023 08:35 AM
Wow, this turned out easier than I thought, since MoveBlock can dereference complex structures.
08-10-2023 08:39 AM
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.