LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Pointers to DLL

I am trying to write a DLL called by another application written in C or C++ I am unsure which. Everything is running under NT. The application calls functions from this DLL and passes various pointers. When the app loads my DLL it craches due to bad memory reference.
The main app expects to pass (char* error) type pointers. These are pointing to strings. I don't know how to create these nor how to define them. It appears that labview only uses handles which con't appear to be the same things.

If anyone has any solutions or general tips for DLL creation and handling of pointers please feel free to Contact me.

Kevin Wagner
0 Kudos
Message 1 of 4
(3,158 Views)
Hello Kevin,

Labview expects strings to sometimes be handled by using LStrHandles.
These data types are leftovers from the days when LabVIEW only ran on Macintosh.
It's unclear from your question if you are trying to create a DLL for use
inside LabVIEW or not..but I will work under the assumption you are.

Firstly, on the LabVIEW side..make sure that the string you pass to
your DLL (the allocated memory for the string) is "Adapt to Type" Type
and "Handles by Value" for the Data format. After configuring the DLL,
generate the .c code.. you will notice that your string gets passed as
"LStrHandle ErrResponse" (or whatever you named it).

In order to actually pass back your string to LabVIEW (w/o it crashing)
You must resize the passed in block of memory, tel
l LabVIEW how long the
string is, and copy the char* into it. You do this in 3 steps..

char *errBuffer//
your internal error string

NumericArrayResize(uB,1L,(UHandle*)&ErrResponse, strlen(errBuffer));

MoveBlock(errBuffer,LStrBuf(*ErrResponse),strlen(errBuffer));

LStrlen(*ErrResponse)=strlen(errBuffer);

..and that should legally pass back your string. Make sure you pass
back the right size!

0 Kudos
Message 2 of 4
(3,158 Views)
HI Thank You for your answer. I have to explain a little better. I am writing some code to create a DLL for some third party software (written in ?). I have choose to do it in Labview since I am fairly proficient and have less fear than doing it in C++. Anyway the third party app expects a function like this

void QueryErrorString(int nError,char* szError,unsigned int uBuffersize);
I have created a labview funtion that recieves the error number. Looks it up and Generates a string. But I cannot get the app builder to generate the correct prototype. This is only 1 of about 5 functions. When I initially created them it hung the machine I tried it on.

I see in this particular instance I could use a CString Pointer with a len argument. Is a CString Pointer the s
ame as char* ? Also some of the functions don't provide any indication of the buffersize (i.e No Len argument).

If you like email me directly. kwagner1@west.raytheon.com

Kevin Wagner
0 Kudos
Message 3 of 4
(3,158 Views)
Hi Kevin-
We do have a wonderful samples of how to create dlls, pass variables via dlls, and how to access dlls in other environments on our external webiste. If I understand your question correctly, it seems that you just want to create a dll in LabVIEW and pass a string into C/C++?? No Biggee.
Go to www.ni.com/support, under Option 3 and Example Code search for "dll +labview +string", you will get different examples for passing and accessing strings in CVI, VC++, VB, etc.

Hope this helps,
ben schulte
ae
national instruments
0 Kudos
Message 4 of 4
(3,158 Views)