LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

creating string pointer for dll

I'm trying to use a DLL to access a Reflective memory board using LV6.i
under Windows2000. The first call to the DLL takes a pointer to a string
that contains the device name and it returns a handle to that has to be
used in all other calls.

The syntax is - RFMHANDLE rfmOpen( char devPath );

The example in the documentation is;
RFMHANDLE rh;
char *devPath = "\\\\.\\RFM1"; This is the
W2000 name for the board

if( (rh = rfmOpen( devPath ) ) == NULL ){
....
exit(1);
}

All the other calls pass the handle rh as the calling parameter.

My question is how do I create the string pointer devPath?

Ed
0 Kudos
Message 1 of 12
(6,532 Views)
Ed,

I'm a Labview DLL rookie but I think all you have to do is in the DLL
configure define the arg Type as a "String" and the String Format as a "C
String Pointer". Then when you wire that terminal up, just connect it to
Sting Constant or Control. Then just pass that argument the device name
string. Labview will take care of actually passing the that string pointer
value to the DLL.

I just done something similar with an array of 16 bytes. I am supposed to
pass the function the pointer to the array and it will change the data in
that array. I defined the arg as Type "Array" of Data Type "Unsigned 8-bit
Integer", Dimension "1", and Array Format as an "Array Data Pointer". I
then connected that terminal to the Build Array function of 16 bytes. The
output terminal
directly accross from that input terminal was connected to
an array indicator. When I run the VI the data bytes were changed as
expected.

The point is that I never really had to deal with the pointer directly. So
you don't have to create the string pointer, just create the string and
connect it to the terminal defined as a string.

- David



Ed Bogart wrote:

> I'm trying to use a DLL to access a Reflective memory board using LV6.i
> under Windows2000. The first call to the DLL takes a pointer to a string
> that contains the device name and it returns a handle to that has to be
> used in all other calls.
>
> The syntax is - RFMHANDLE rfmOpen( char devPath );
>
> The example in the documentation is;
> RFMHANDLE rh;
> char *devPath = "\\\\.\\RFM1"; This is the
> W2000 name for the board
>
> if( (rh = rfmOpen( devPath ) ) == NULL ){
> ....
> exit(1);
> }
>
> All the other calls pass the handle rh as the calling paramete
r.
>
> My question is how do I create the string pointer devPath?
>
> Ed
0 Kudos
Message 2 of 12
(6,531 Views)
I have to do something similar. In the DLL I use, the syntax is:

int OpenCom (LPCSTR ComName, LPCSTR *Com_cr_mess);

Where Com_cr_mess is supposed to be the adress of a pointer to string. If I define it as 'C pointer to string' and pass a constant string with nothing written should it work or am I doing something wrong?


Thanks for help.
Raoul
Raoul Chodziesner-Bonne
Ingénieur Instrumentation
CRIL TECHNOLOGY - Groupe ALYOTECH

"Celui qui pose une question peut paraitre idiot sur le moment, celui qui n'en pose pas le reste toute sa vie!"
0 Kudos
Message 3 of 12
(6,483 Views)
Hi, I am having same problem. Can somebody please attach an example here?

I want to pass char pointer (char *) to my dll from labview and want to get value back from dll.

Sheetal
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 4 of 12
(6,455 Views)
If the DLL expects a char* or LPCTSTR, do as dcabernel says and configure the Call Library function to pass a C String Pointer. LabVIEW does the dirty work; you don't deal with the pointer directly (as there is no pointer type in LabVIEW).

LPCTSTR* is more tricky; it's really a char**, which LabVIEW can't pass through the Call Library function. You'd need a wrapper DLL to call a function that expects that.

Most of this is explained in the "Using External Code in LabVIEW" manual.

Steven H.
0 Kudos
Message 5 of 12
(6,441 Views)

Hi there

I'm also trying to work with a String pointer and a DLL, but it doesn't work!

I've got a small function like this:

void

__stdcall ReturnValue(char* pointer){
pointer =
"Test ok";
}

And I try to read out with the VI in the attached picture.

Does someone know what I'm doing wrong?

Regards

Using:

LV8, Visual Studio 05 and WinXP with SP2

0 Kudos
Message 6 of 12
(5,875 Views)
The return value of the function prototype is void, so it shouldn't return anything. Even if it did, we can only asume it will return the input string. If it returns the input string, LabVIEW will convert it to string, and you'll get the string, not the pointer. If you want the pointer, make the return value a I32 or U32.


Regards,


Wiebe.
0 Kudos
Message 7 of 12
(5,864 Views)

hm, thats a problem... In this case theres no difference between giving back a pointer or the String itself, its only more complicated! Or whats the advantage of this pointer?

My problem is that I need more than one return Value for an USB-Communication (Strings, numbers etc.). So thats NOT possible??

I already searched for direct USB-VI's (with Visa or something). But I found no examples nor an easy description how to get or set Reports and so on.

Do you know something about this functions?

Thanks for the answer!

0 Kudos
Message 8 of 12
(5,861 Views)
I don't know much about USB communication, but if you know a protocol, it shouldn't be more difficult then serial communication. There have been threads about USB communication with VISA before, they might be helpful. If not, you should start a new thread.


Passing more then one parameter is possible, and should be very simple. I looked wrong in your picture. You don't use the return value at all. The way you are doing it right now seems to be ok. The input string should be large enough for the output string to fit in. The dll doesn't know the string size (it can be passed in a seperate parameter), and you are also doing this correcly.


Try to get GetUserNameA working (in Advapi32.dll), or GetSystemWindowsDirectoryA (Kernel32.dll). Perhaps you'll notice what you're doing wrong.


BOOL GetUserName(
LPTSTR lpBuffer, // name buffer
LPDWORD nSize // size of name buffer
);


Can you specify what doesn't work? Do you get a crash? Also, are you sure you wired "Zeit" to the output connector of the dll? Or send the VI and dll...


Regards,


Wiebe.
0 Kudos
Message 9 of 12
(5,852 Views)

Hi Wiebe

No crash at all, but all i get is the value I gave in already...
so I attached the files, would be great if you have a litte time to have a look at!

Thanks alot
Regards

Humpe

0 Kudos
Message 10 of 12
(5,824 Views)