LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Having problems with the call library function to a 3rd party DLL

I am trying to develop an interface to a Campbell Scientific CR3000 using their BMP5 Direct interface in LV 7.1. BMP5 Direct consists of a dll with several simple calls to get data from the CR3000.  I am having problems correctly reading the return data values as strings.  I am using a Call Library Function to talk to the dll.  It appears from the example code provided with the dll, that the dll is passing a pointer to a pointer back from the call.  I suspect that I am misinterpretation the documentation and/or LV interface.

 

I have historically successfully used the Call Library Function writing interfaces to other 3rd party instrument dlls.

 

Is there any LV or other documentation that I can use to resolve the issue?

0 Kudos
Message 1 of 4
(2,605 Views)

There are numerous documents in the NI KnowledgeBase on calling DLLs. A search will yield them. There's also an example that ships with LabVIEW called "Call DLL" that has examples on calling DLLs with various types of parameters.

 

The thing you need to determine is whether the DLL expects the memory for the string to be allocated by the caller (likely), or if it allocates the memory internally. If it's the latter, then there must be a way to deallocate it, or you will get a memory leak. You said you think it's passing a pointer to a pointer. A pointer to what? Can you provide the header file, and indicate which function you're calling?

0 Kudos
Message 2 of 4
(2,588 Views)

Thank you for the reply.

 

I have looked in detail at the "Call DLL" vi from the examples.  I have confirmed I am properly managing the allocation of memory to the returning string.  I will search the NI knowledgebase for calling DLLs to see what else I may find.

 

 The 3rd party DLL I will interface with comes with example code to show how to call it in several environments.  These are C++, MSC++, Delphi6, and VB6.  In each of the examples there is an executable that, I assume, is the compiled version of the example code.

 

In the C++ example, it appears that the DLL function call is calling with a pointer to the C string pointer.  That is, instead it the DLL being called wih the pointer to the first character to the string, it is being called with a pointer to the string pointer.  I would normally expect it to be calling with a C string pointer.

 

When I use the Call Library Function with the 3rd party DLL and call a specific function with a String as the returning data type and select a C string pointer, the first time I run the LV vi, I get a number different than if I run it the second time.  Every time I run the vi I get the same number from then on.  I know what the function call should be returning as a result of using any of the example programs and calling the same function (DLL version).

 

 

I am left with the idea that I will need to generate another C++ DLL or program that will call the target DLL and pass the correct string pointer back to the LV vi.

 

I don't have much confidence in my above conclusion.  My gut tells me that I'm missing something, that when found, will resolve the issue.

 

As a note, the DLL package is completely portable and can run on any PC without the need for the Campbell CR3000 data logger.  The command that calls the DLL version will function correctly.

 

Perhaps, after looking though the knowledgebase I'll see something else.  Any other suggestions would be welcome.

0 Kudos
Message 3 of 4
(2,566 Views)

Does your C++ example allocate this string before it calls the function? If it does so, you will have to do the same which will be in fact a bit of a trouble in LabVIEW.

 

If it doesn't it will have to deallocate it later on somehow. Then you could configure the parameter to be a pointer sized integer passed as reference (pointer to Value). Then you do of course need a means to retrieve the information from that buffer. You can do so using another Call Library Node configured as follows:

 

Library: LabVIEW

Calling Convention: C

Function Name: MoveBlock

 

return value: void

1st parm: source, Numeric, Pointer sized Integer, Pass:Value

2nd param: dest, either C String pointer or C Array Pointer, whatever you want your resulting buffer to be

3rd param: length, Numeric, int32, Pass by Value

 

Wire the parameter from your function to the 1st parameter of this function.

Create a string or array of sufficient size (Initialize Array) and wire it to the 2nd parameter. Then wire the number of bytes to copy to the 3rd prameter

 

And don't forget to call whatever function your C++ example uses to deallocate the buffer to avoid memory leaks.

 

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 4
(2,555 Views)