From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a pointer location to a DLL called in labview

I have a dll that I am calling in LabVIEW using the Call Library Function Node.

As I have to pass in a pointer location to the function call, I tried using the move block based on inputs from other threads with no luck.

Any inputs to get this to work will be helpful.

 

Details below and attached as well.

 

Function

return value = function (&parameter1, &parameter2);

Where parameter1 is a pointer to a memory location and Pointer2 is a defined struct.

 

DLL expects to see a value being passed in for parameter1 and then it would return the updated value back. I have tried passing a NULL value (int I32) and I am getting a NULL PTR error. Since I don’t have the dll details, I am not sure if this is because of bad memory location that I am passing in to the DLL function call? To initialize memory for pointer1, I have tried using the Move block but it gives the 1097 error. VI attached (LabVIEW 2011). Tried changing the input to int I32, int U32 with no luck. Also changed the pass value to “Pointer to Value” and “Value” without any luck.

 

I have attached the move_block.vi and details about the function that I am calling.

Due to licensing issues I cannot provide the actual function call vi.

Download All
0 Kudos
Message 1 of 20
(5,192 Views)

Can you post the DLL? You probably need to use DSNewPtr. I have some old code where I figured this out. The external DLL call, DcamCapture, expected a pointer input, which it then used and put a 1d array at that pointer. This is what I did to get it:

 

Capture.PNG

0 Kudos
Message 2 of 20
(5,178 Views)

Unfortunately I cannot post the DLL due to licensing issues.

I will try out what you suggested to see if it helps.

0 Kudos
Message 3 of 20
(5,175 Views)

What is the signature/prototype of the function that you are trying to call? That is, how is the call defined in the .h file associated with the DLL?

 

If you cannot supply that information, then at least, what is the underlying datatype of parameter 1? You describe it as a pointer to a memory location, but you also show the function call with the parameter &parameter1. This means it's taking the address of parameter1 and passing that to the DLL. If parameter1 is simply a numeric value, then all you need to do is configure the call library node to pass it as a Pointer to Value, which is the LabVIEW equivalent of the & operation in C.

0 Kudos
Message 4 of 20
(5,161 Views)

Here are some more details.

 

;Parameter1 is an instance of struct_xyz (no struct definition is provided by the 3rd party)

 

struct_xyz parameter1 = NULL;

 

out = functionA (&parameter1, &parameter2);

 

parameter1 is a pointer to a memory location for struct_xyz where in it will have a space of 130h.

parameter2 is a defined struct.

0 Kudos
Message 5 of 20
(5,134 Views)

Again, is there a .h file associated with this DLL? Can you provide it, or at least provide the function prototype for the function you want to call?


VKC wrote:

struct_xyz parameter1 = NULL;


This line doesn't make any sense, from a C point of view, unless struct_xyz is actually defined to be a pointer to a struct. Do you ever need the underlying data behind the pointer to parameter1, or you just need to pass it around between different functions in the DLL? If you're just passing it around, then you can simply configure that parameter as a pointer-sized integer passed by pointer, because all you really need to pass around is a memory address. Wire a numeric constant to that input: a U32 constant on a 32-bit system, a U64 constant on a 64-bit system which should work on 32-bit as well so long as the parameter is configured as pointer-sized.

0 Kudos
Message 6 of 20
(5,129 Views)

Nathan

 

I understand the need for the .h file. But as previously mentioned the 3rd party has not provided the struct info in any of the .h files and it is highly unlikely that I will have the info in future either.

 

I do not need the data underlying the pointer location. I just need the location address that I have to pass to some other function calls.

 

I have tried configuring parameter1 as a Signed pointer sized int and connected a I32 as control by passed it as a pointer to value. When I do this dll gives back a bad parameter error. But when I change the pass option to value then I get a null pointer error.

 

Due to the enull pointer error I tried to initialize the pointer using the move block, but I am getting an error 1097 from it.

Also tried the DSNewPtr option suggested above, but getting 1097 error. Tired changing the calling convetion to C and WINAPI with no luck.

 

Let me know if you have any other suggestion or way to tackle this problem.

0 Kudos
Message 7 of 20
(5,122 Views)

VKC wrote:

I understand the need for the .h file. But as previously mentioned the 3rd party has not provided the struct info in any of the .h files and it is highly unlikely that I will have the info in future either.

 

I do not need the data underlying the pointer location. I just need the location address that I have to pass to some other function calls.


Did they provide a .h file at all? It doesn't need to contain the struct definition if you don't need to access the data in the struct, but a function prototype would be very helpful. Is there any other documentation about how to call the function?


VKC wrote:

I have tried configuring parameter1 as a Signed pointer sized int and connected a I32 as control by passed it as a pointer to value. When I do this dll gives back a bad parameter error. But when I change the pass option to value then I get a null pointer error.


Is this "bad parameter error" from LabVIEW, or from the DLL? Does it show up in the error out terminal, or the return value from the function? If the latter, I'm assuming that you must have some documentation about the meaning of return values from the function. Of course you will get a null pointer error if you pass 0 by value to a function that expects a memory location - you're passing the function a null address.


@VKC wrote:

Let me know if you have any other suggestion or way to tackle this problem.


Unfortunately without more documentation I can't suggest anything else.

0 Kudos
Message 8 of 20
(5,118 Views)

Nathan,

 

Find attached .h and .c files.

 

Hope this provides you the info you requested.

Download All
0 Kudos
Message 9 of 20
(5,105 Views)

Yes - that's what I needed. Now I can see that the .h file includes "typedef struct _struct_xyz *struct_xyz;" which is what I couldn't understand.

 

In that case, you need DSNewPClr, but not MoveBlock. Configure DSNewPClr to give you a pointer to either 4 or 8 bytes (32- or 64-bit platform). Pass the returned pointer value by pointer to your DLL function (so you're passing a pointer to a pointer, otherwise known as a handle). Don't forget to deallocate that pointer when you're done using DSDisposePtr.

 

If this doesn't work for you, please upload your VI; you don't need to include the DLL.

0 Kudos
Message 10 of 20
(5,097 Views)