LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I call a function from a dll in LabVIEW that returns:double*string and int.?

I have a function from a dll that return a double* string and an integer. How can I call this function from LabVIEW? There is a possibility to work in LabVIEW with a double* string?
0 Kudos
Message 1 of 10
(4,079 Views)
I don't know what you mean by this:
a function from a dll that return a double* string and an integer


Do you mean "a double*, a string, and an integer" ??
Do you mean "a double, a *string, and an integer" ??

The "return" value from a DLL has to be a simple value (can't return more than one).
Although you can have the DLL pass back several values.

Doubles and integers are directly passable back and forth. Strings are very different in LabVIEW than in other languages. See the CIN / External Code notes for details.


Or ask again.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 10
(4,066 Views)
Hello all,

The header of the function is: "HRESULT WRAPIEnumerateDevices(WRAPI_NDIS_DEVICE **ppDeviceList, long *plItems);" where WRAPI_NDIS_DEVICE have this form:

typedef struct WRAPI_NDIS_DEVICE
{
WCHAR *pDeviceName;
WCHAR *pDeviceDescription;

} WRAPI_NDIS_DEVICE;

The function is from WRAPI.dll, used for communication with wireless card.

For my application I need to call in LabVIEW this function.

Thanks a lot,

PCBV
0 Kudos
Message 3 of 10
(4,046 Views)
I don't see any DOUBLES in there, but anyway...
It looks like you need to pass a handle to a cluster, then a pointer to an integer.

Is this possibly an array of those clusters, with the integer being how many are in the array? ( how I hate C...)
If so, that would be difficult enough, as LabVIEW handles arrays differently than C ( thank you, Jeff Kodosky)
The handle to a LabVIEW array refers to a structure which includes the dimension size(s). In other words, for a 1-D array, the handle refers to a 4-byte integer indicating how many are in the array. The first data item is 4 bytes offset from the handle reference.

You might be able to fool it, if you're passing a fixed-size array, BUT

The killer is the WCHAR. As far as I know, LabVIEW as no support for Unicode (wide) characters. All characters are ASCII, 8 bits. You might be able to fake that with null characters every other byte, but that's way more than I can do in a help forum.

CHOICES:
1... Rewrite the DLL in a more LabVIEW-friendly way.
2... Write some glue code (in C) that handles the differences between ASCII / UNiCODE and LABVIEW/C arrays.
3... Do a serious amount of bit-twiddling to get everything to match. If you do that, I strongly suggest you create a dummy DLL with the same call interface, and some debugging code in it, so that you can test what comes across the interface.

I see no other choices.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 10
(4,038 Views)


pcbv 写:
I have a function from a dll that return a double* string and an integer. How can I call this function from LabVIEW? There is a possibility to work in LabVIEW with a double* string?





Please give the parameter or dLL you want to invoke
maincool
0 Kudos
Message 5 of 10
(4,028 Views)


pcbv 写:
I have a function from a dll that return a double* string and an integer. How can I call this function from LabVIEW? There is a possibility to work in LabVIEW with a double* string?





Please give the parameter or dLL you want to invoke
maincool
0 Kudos
Message 6 of 10
(4,028 Views)
Dear all,

Here is the dll and the source for this dll. In order that this dll work you have to first install ndisuioex protocol driver.
All of these can be found in the below zip archive. The sources are made in .NET.

Thanks,

PCBV
0 Kudos
Message 7 of 10
(4,013 Views)
Since you have source code for the DLL, I suggest you rewrite it to accomodate LabVIEW strings (convert them to UniCode in your DLL) and LabVIEW arrays (handle the dimension size). It's not that difficult. Look at the USING EXTERNAL CODE WITH LABVIEW manual for details.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 8 of 10
(4,010 Views)
pcbv wrote:

> Hello all,<br><br>The header of the function is:
>
> "HRESULT WRAPIEnumerateDevices(WRAPI_NDIS_DEVICE **ppDeviceList, long *plItems);"
>
> where WRAPI_NDIS_DEVICE have this form:
>
> typedef struct WRAPI_NDIS_DEVICE<br>{<br>
> WCHAR *pDeviceName;<br>
> WCHAR *pDeviceDescription;<br><br>}
> WRAPI_NDIS_DEVICE;<br><br>
>
> The function is from WRAPI.dll, used for communication with wireless card.
> For my application I need to call in LabVIEW this function.

Two difficulties I can see with this.

First the application seems to allocate the array of references
internally and return a pointer to that array. In that case there must
be another function which then deallocates that array again.

Then you would need to setup the function call to have a pointer to an
int32 number for the deviceList parameter and another pointer to int32
one for the plItems parameter.

Then create another function in your DLL similar to this:

HRESULT WRAPIEnumExtractDevice(WRAPI_NDIS_DEVICE *lpDeviceList, long i,
CHAR lpszDeviceName, LONG lenDeviceName,
CHAR lpszDeviceDesc, LONG lenDeviceDesc)
{
if (!lpDeviceList)
return ERROR_INV_PARAMETER;

if (lpDeviceList[i].pDeviceName)
WideCharToMultiByte(CP_ACP, 0,
pDeviceList[i].pDeviceName, -1,
lpszDeviceName, lenDeviceName,
NULL, NULL);

if (lpDeviceList[i].pDeviceName)
WideCharToMultiByte(CP_ACP, 0,
pDeviceList[i].pDeviceDescription, -1,
lpszDeviceDesc, lenDeviceDesc,
NULL, NULL);
return NO_ERROR;
}

Pass the int32 you got from the first parameter of the previous call as
a simple int32 passed by value to this function (and make sure you don't
call this function with a higher index than (plItems - 1) returned from
the first function.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 9 of 10
(3,982 Views)
Thanks a lot

I'll try it.
0 Kudos
Message 10 of 10
(3,972 Views)