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: 

return pointer dll

All,
 
I have an issue.
 
I am trying to call a function within a dll that is the following:
 
RtxGetPortEnumerationList()
 
This function is returning is either a Null pointer if devices have not been enumerated or a Non-zero pointer to a buffer allocated by the library and there are no input parameters.
 
The issue that i have is when creating the vi for it, i am only able to return a U32 value and do not have access to read a pointer. Why is this so?
 
Is there any way around it?
Thanks-N-Advance
FD
0 Kudos
Message 1 of 21
(4,194 Views)
The numeric you get back is the pointer. So you are reading it.... If you
want to know what is on the pointer, you have to use LabVIEW.exe functions
or winapi functions.

If the pointer points to a string, you can also change the return value to
string.

Regards,

Wiebe.


Message 2 of 21
(4,176 Views)
Thanks for the response.
 
do you know how i can access the winapi functions or Labview.exe ?
 
I couldn't find an example on how to use them.
 
 
Thanks!
0 Kudos
Message 3 of 21
(4,163 Views)
Accessing a windows API is pretty much the same as any api. Simply select
user32.dll or kernel32.dll (shell32, gdi32, etc), and select the desired
function. The function to use is the hard part. You can search the MSDN (ms
developers network) to see how each function works. I'd look at the lstrcpy
(in kernel32.dll) function. This function doesn't seem very sensible to use,
it copies one string to another. But in LabVIEW, you can use it to convert
the pointer (a numeric value, which points to a string) to a string (also a
pointer, but LabVIEW converts it to string). If you have an array of
strings, each string is terminated by a NULL (=0). So if you read a string,
add the string length +1 to the pointer to get the next string. Repeat
untill you get an empty string (the array is terminated by NULL NULL). It's
a hassle, but it works.

The LabVIEW API is a bit different. You don't select a dll, but LabVIEW.exe.
Executables can export functions just like dll's. The functions are not all
documented, but some are. The functions of interrest are probably one of
these: PToCStr, CToPStr, LToPStr or PToLStr. The prototypes are in the
LabVIEW directory under cintools\extcode.h.

Save your work before each run!

Regards,

Wiebe.



Message 4 of 21
(4,145 Views)

Hello,

I want to refresh the topic.

 

 Has anyone solved this problem? 

My function returns a pointer to a table of int. How can I convert the pointer to the real table and read its elements?

 

Przemek

0 Kudos
Message 5 of 21
(3,860 Views)
more detail with a structure here
0 Kudos
Message 6 of 21
(3,857 Views)

"przemmo" <x@no.email> wrote in message
news:1237284607636-872168@exchange.ni.com...
> Hello,I want to refresh the topic.&nbsp;&nbsp;Has anyone solved this
problem?&nbsp;My function returns a pointer to a table of int. How can I
convert the pointer to the real table and read its elements?&nbsp;Przemek

A solution was already given. What part is giving you problems?

Regards,

Wiebe.


0 Kudos
Message 7 of 21
(3,851 Views)

the problem: How to read (for example) the second element of the table the pointer my dll returns points at?

 

0 Kudos
Message 8 of 21
(3,834 Views)

Super!

 

Many thanks Wiebe for pointing me to the LabVIEW API. The MoveBlock is the hit for dealing with pointers (If an array has 0s, the StrCpyN of WinAPI stops). What a luck that  przemmo refreshed that thread. I was crawling the forum for ages on that...

 

Felix 

0 Kudos
Message 9 of 21
(3,830 Views)

"przemmo" <x@no.email> wrote in message
news:1237293605307-872232@exchange.ni.com...
> the problem: How to read (for example) the second element of the table the
pointer my dll returns points at? &nbsp;

Option 1) read all the data, and convert it to the labview type you want.
There is no telling how this should be done, since the data type can be
anything...

Option 2) add the data size to the pointer. The result will point to the
second element.

Regards,

Wiebe.



0 Kudos
Message 10 of 21
(3,819 Views)