LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling DLL in LabVIEW

Solved!
Go to solution

Hi Rolfk,

 

Thank you for explaining reg. wrapper fn.

 

Please find an attachment of the VI (LabVIEW 8.5.1), in which I make the return type of the OLECreateObject() to Signed 32-bit integer.

And then I pass this returned value of OLECreateObject() to one of the parameters of OLEGetFASTVersionNumber().

The second parameter is a C String Pointer with minimum size of 300.

 

Have a look at it and kindly advice.

 

Thanking you,

 

Regards,

Vani

0 Kudos
Message 21 of 41
(2,529 Views)

Dear Rolfk,

 

Request you to kindly find the attachment of LabVIEW code and advice accordingly. I want to confirm that the equivalent of the Pointer sized integer (Only available for LabVIEW 8.6 and above) in LabVIEW 8.5 is a Signed 32-bit integer. And I have set the Char* to String and C String Pointer of minimum size 300.

 

Waiting for your reply.

 

Regards,

S.P.Vani

0 Kudos
Message 22 of 41
(2,507 Views)
Does it work? Do you get an error or crash? I don't see anything glaringly wrong with that VI but not knowing if you just want to hear that, or if you have still a problem, makes it hard for me to answer your "waiting for reply". Courtesy is a nice treat but in such technical discussion fora it is usually better to be more precise and clear as to what problems you still have, if you have them. Otherwise just state that this works and that you post this for the education of anyone else who might happen to stumble over this thread one day.
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 23 of 41
(2,498 Views)

Hi Rolfk, 

 

I am sorry for I do not have the hardware set-up for testing this VI and see the output of the function. So, I wanted to re-confirm it from you. As for now when I run it, I dont seem to see any errors or crashes either. But to verify the correct output, I should have the Hardware set-up for testing it.

 I hope this works and I shall post the results once I am finished done with the testing.  Thank you very much. Regards,S.P.Vani

 

0 Kudos
Message 24 of 41
(2,488 Views)

Dear All,

 

I get an error 1097 exception while trying to access the DLL. Smiley Sad

 

 

1.  typedef long __stdcall( *OLECREATEOBJECT)(char*);

     typedef long __stdcall( *LOADFASTAPP)(long,char*);

     static HINSTANCE Hinstlib,hinstlib;
     static long gvntISystem;

 

long CviCreateFastObjects (void) {

OLECREATEOBJECT procAdd;
pStrTempmem     = (char*)CA_AllocMemory(1);

 Hinstlib = LoadLibrary("FastTrio");
  if( Hinstlib != NULL){ 
  procAdd = (OLECREATEOBJECT) GetProcAddress(Hinstlib, "OLECreateObject");
  if(fRunTimeLinkSucess = (procAdd != NULL)){
   gvntISystem = (procAdd)("FAST.IMFASTSystemInterface");
   return 0;
  } 
  else
   return 1;
  }
 else
 {
  return 1;
 }
}

 

LabVIEW successfully compiles the above function and returns a long value when the DLL is loaded into the memory (i.e when the vi is loaded into the memory). This function loads or invokes FAST application (Loads the FAST software application). To call this dll, one input is Cstring and the return value is signed 32-bit integer which is gvntISystem.

 

2. long CviFASTLoadApplication (char *cString){
 
LOADFASTAPP procAdd;
long status = -99;
  if( Hinstlib != NULL){
  procAdd = (LOADFASTAPP) GetProcAddress(Hinstlib, "OLELoadApplication");
  if(fRunTimeLinkSucess = (procAdd != NULL)){
   status = (procAdd)(gvntISystem,cString);//call the function
  }
 }
 return status;
}  

   

When I try to access this function by passing the gvntISystem as an input, I get the above exception. To access this function, I am passing the gvntISystem as signed 32-bit integer and passing as value (not pointer to value) and a CString to which an application name is given.

Pls help me.

 

I have got LabVIEW 2009.

 

Regards,

Vani

 

 

 

 

0 Kudos
Message 25 of 41
(2,378 Views)

Hi,

 

Solved the error exception 1097 by changing the option "Run in any thread" to "Run in User interface thread" in the Call Library Node.

The problem is solved and I am able to access the Dll successfully. The credit goes to all of you.

I would also like to thank Rolfk, D F Gray and H Sh for guiding and assisting me all along.

 

With Kind Regards,

S.P.Vani

 

0 Kudos
Message 26 of 41
(2,315 Views)

Hi,

Solution is in the message posted by DFGray and Rolfk: -

 

1. All the information you need is in the C code. 

  •  OLECREATEOBJECT is typedefed right after all the #includes at the top.  It returns a long integer (typically I32 in LabVIEW, but could be I64 on a 64-bit operating system) and takes a string as input.  It uses standard window calling conventions, not C calling convention.
  • LoadLibrary and GetProcAddress are used to get a pointer to the function (procAdd).  This is handled in LabVIEW by filling in the library location and function in the call library node.
  • The call library node in LabVIEW must also be set to standard calling convention and the return value (I32) and parameter list (one string) must be set.
  • the function is used to set gvntISystem with a constant input "FAST.IMFASTSystemInterface".  In LabVIEW, wire a string constant to the input and read the return value.
  • you can implement the error checking, as well, by using the error output of the call library node.

2. One recommendation (if you would use LabVIEW 8.5 or better):

 

Make the return value of the CreateObject function to be a pointer sized integer. As it is now you do assume 32 Bit Windows and DLL and that might bite you later on when you upgrade to a 64 Bit Windows, LabVIEw and DLL.

 

As to the implementation itself you make the typical LabVIEW Call Library Node starter error. The string to the second function is an output buffer. From LabVIEW you are used that it will take care to resize any string or array automatically to whatever size is needed. That does not work for DLL calls.

Did you notice the CA_AllocMemory(300) call in the CVI source code? For what might this be necessary??

 

Indeed it allocates a memory buffer for the function to write in the version string. LabVIEW has no way to know that this function wants a buffer to write in this information so you have to explicitedly tell LabVIEW that.

 

You do this with Initialize Array by creating a byte array large enough for the function parameter and then using the Byte Array To String function to turn it into the string. If you had LabVIEW 8.5 or better you could also simply configure this parameter in the Call Library Node configuration dialog to be of the desired minimum size and LabVIEW will take care about allocating that buffer automatically.

 

Ohh and by the way you should put a Delay function in the False case. Otherwise the loop does try to do very hard nothing and that has a rather nasty effect under LabVIEW for Windows of monopolizing the CPU almost completely.

 

 

 

 

0 Kudos
Message 27 of 41
(2,318 Views)

Hello to everyone ,

 

i have problem creating a code and calling this code to Labview via DLL.

I would like to create this code in LabView:

 

typedef struct

{

UINT32               dwTime;

UINT32              dwMsgId;

CANMSGINFO   uMsgInfo;

UINT8               abData[8];

} CANMSG,  *PCANMSG;

 

 dwTime

: [in/out] With receive messages, this field contains the relative reception time of the message in ticks. The resolution of a tick can be calculated from the fields dwClockFreq and dwTscDivisor of the structure CANCAPABILITIES in accor-dance with the following formula:

Resolution [s] = dwTscDivisor / dwClockFreq

 

 

dwMsgId

: [in/out] CAN ID of the message in Intel format (right-aligned) without RTR bit.

uMsgInfo: [in/out] Bit field with information on the message type. A description of the bit field is given in section 5.2.5.

abData: [in/out] Array for up to 8 data bytes. The number of valid data bytes is defined by the field uMsgInfo.Bits.dlc.

 

Can someone please advice me how can i do that?I can use the call function librabynode to do this and how?I have never done something like this and i need guidenance

0 Kudos
Message 28 of 41
(1,820 Views)

This is not a C code but simply a structure datatype definition. As such it is most easily resembled by a LabVIEW Cluster. If you create a Cluster that has two uInt32, another SOMETHING for the CANMSGINFO, followed by 8 uInt8 then you have basically created a cluster that resembles this C struct. But this is no code, just a datatype.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 29 of 41
(1,814 Views)

Can you provide an example to understand what you are saying please.I must use this Vi to change the delay time between message i am receiving through the CANBus

0 Kudos
Message 30 of 41
(1,812 Views)