LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using a LabView DLL in LabWindows

Hello,

I created a VI which have several connectors, in/out strings, enum ... and IN/OUT error clusters. With this VI I created a DLL. Now I want to call this DLL from labWindows/CVI with initialized input parameters. There is no problem for all parameters except for the IN clusters!!!
Ths cluster structure is:
typedef struct{
LVBoolean status;
int32 code
LStrHandle source;
} TD1;
When the structure is not initialized, there no problem to pass it to my LabView DLL function. LabView initializes it, but when I want to initialize it myself, it always fail!!!! The problem is for the initialization of the LStrHanlde parameter (LabView String handle).
I can initialize the handle and passe it to LabView; that is working fine
. But when I want to set it value it is returning an error: "Not called from a LabView Process".
I am using the functions in "extcode.h" header to initialize the parameters.

I haven't found any example on NI web site for this kind of parameter/problem.
How can I do to initialize this parameters with a fixed value ?

BR Pascal.
0 Kudos
Message 1 of 6
(4,299 Views)
Hello

I noticed you have a labview string handle in cluster. You would need to first use the LabVIEW memory manager functions ( refer to "using external code in LabVIEW for details) to allocate the memory for the string handle in the following way.

LStrHandle newStringHandle;

newStringHandle=(LStrHandle)DSNewHandle(sizeof(int32)+STRING_LENGHT*sizeof(uChar));

//Empties the buffer
memset(LStrBuf(*lvStringHandle),'\0',STRING_LENGHT);

//Fills the string buffer with stringData
sprintf((char*)LStrBuf(*lvStringHandle),"%s",stringData);

//Informs the LabVIEW string handle about the size of the size
LStrLen(*lvStr
ingHandle)=strlen(stringData);

After the memory is allocated for the string, you should be able to safely pass it to labview.

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(4,297 Views)
Hello,
Thanks for your response. I found another way to make the initialization of the LabView string Handle:

(UHandle) LStrHandle = (UHandle) DSNewHClr(1);
errResult = NumericArrayResize(uB, 1L, (UHandle *) &LStrHandle, iSize);
LStrLen (*ErrorInNoError.source) = iSize;
MoveBlock(cString, LStrBuf(*LStrHandle), iSize);

Can you tell me which method is better?

BR Pascal.
0 Kudos
Message 3 of 6
(4,297 Views)
It would be simpler to just create the buffer of the correct size in the first place instead of creating a small one and resizing it. But this should work as well. Check pg 109 of 312 of the manual i linked above. It states the following

"Create a handle using XXNewHandle, with which you specify the size of the memory block.
Create a pointer using XXNewPtr. XXNewHandleClr and XXNewPClr are variations that
create the memory block and set it to all zeros."

Bilal
Bilal Durrani
NI
0 Kudos
Message 4 of 6
(4,297 Views)
This example is exactly the information that I am needing.

This post does talk about an error about "LabVIEW dll not called from LabVIEW.exe process." It turns out my C application is getting this exact runtime error.

My application will compile, but not run.

When using this LStrHandle allocation code, what LabVIEW dll must be linked to and how? I can not find any documentation about linking to LabVIEW from C applications.

Thank you for any information.

Michael
0 Kudos
Message 5 of 6
(4,098 Views)

@mboyle wrote:
This example is exactly the information that I am needing.

When using this LStrHandle allocation code, what LabVIEW dll must be linked to and how? I can not find any documentation about linking to LabVIEW from C applications.

There really isn't. It's not just about linking to lvrt.dll an then you are done with it. lvrt.dll needs to be instantiated properly in order to have all its things properly setup. This typically happens if you start a LabVIEW build application.

 

labviewv.lib is the import library for the LabVIEW manager functions. It implements so called weak linking which means it only attempts to link to a function the first time it is called. It basically checks if the function pointer is already initialized and if that is not the case it checks if either labview.exe or lvrt.dll are already loaded into the process space and then imports the function from that module. And you can't just load lvrt.dll yourself into memory and hope to have its functions available since there is a whole series of initialization steps that the LabVIEW build executable does in order to setup all the different DLL resources.

 

When you see that error it basically means that the labviewv.lib loader routine tried to find labview.exe or lvrt.dll loaded into memory and it failed. That only really can happen if your process is not a LabVIEW application and then the big question actually is, WHY do you want to use LabVIEW memory management functions in C code that does not run in the context of a LabVIEW application (either the LabVIEW development environment or the LabVIEW runtime engine)? It doesn't really make much sense to create such data elements unless you want to pass them to LabVIEW somehow and that will only work if there is a LabVIEW engine already running in your process.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(2,034 Views)