LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Import DLL

Solved!
Go to solution

Good morning everyone I have been working with LabVIEW for some time, but I had never imported a DLL, I have seen how it is done in a tutorial so that it automatically generates all the wrappers and organizes it in a library. I have followed all the steps adding my dll and my header but I have not obtained all the functions, I think it may be because LabVIEW works in UNICODE and the dll is made in ANSI. I do not know if this has a solution and if you can help me. (I attached the DLL(64 bits) and the header). On the other hand I wanted to ask you, I have not worked a lot with C, my doubt is how the pointers are defined, when the entries are a numerical value, its a obviously operation but I do not know how to define a pointer, if you can give me a bit of light on this subject I thank you. Thank you very much in advance.

Download All
0 Kudos
Message 1 of 16
(5,200 Views)

First: No LabVIEW only supports ANSI strings, just as your DLL seems to use (LPSTR rather than LPWSTR). Can you be more specific about what doesn't work?

 

I see two problems in the header:

 

1) C++ style reference operator & in parameter declaration. The LabVIEW import library wizard only supports standard C syntax so you would have to modify the header to use * instead of & for all reference parameters in the functions.

 

2) Any function that makes use of one of the Callback function pointers as parameter can NOT be imported in LabVIEW. LabVIEW does NOT support function pointers!

Rolf Kalbermatter
My Blog
Message 2 of 16
(5,190 Views)

Hi Obli33,

 

I was able to create a library for quite a few of those functions. However, as you also saw I got errors on maybe half of them:

extern "C" __declspec(dllimport) INT CalculatePrnu (LPCSTR strFileName, BYTE nInterpolation);

The following symbols are not defined:
LPCSTR;

Undefined symbols can prevent the wizard from recognizing functions and parameters. To correct this problem, check the header file to determine if you must add preprocessor definitions. Click the Back button to return to the previous page of the wizard to add a preprocessor definitionsl (for example, "NIAPI_stdcall = __stdcall" or "NIAPIDefined = 1").

 

If you have the source code, try recompiling the dll and may close attention to the settings - the compiler should do a better job of defining the variables than us doing it manually.

 

I'm not an expert in this, hopefully someone will shed some light on this

0 Kudos
Message 3 of 16
(5,188 Views)

LPCSTR and BYTE and all the other full uppercase type definitions are Windows API definitions, they are not part of the standard C datatypes and the import library wizard can therefore not know about them. You can either get the Windows SDK headers from Microsoft and point the import library wizard to use them, and add an #include "windows.h" at the start of your header, or you can start defining those declarations yourself in the first step of the import library wizard.

 

Adding statements like this in the Preprocessor Definitions box:

LPCSTR=char*;BOOL=int;BYTE=unsigned char;WORD=unsigned short;UINT=unsigned int;DWORD=unsigned long;CHAR=char;SHORT=short;INT=int;LONG=long;LONGLONG=int64_t

Rolf Kalbermatter
My Blog
Message 4 of 16
(5,163 Views)

Good morning Rolf

 

Thank you very much for your response, first to begin to programate the camera, i need import all the functions in labview to work. Your tips have been very useful:

 

1) I changue all the "&" operators for "*" in the header

2) How could I solve this problem? for use this type of functions.

 

In the header i have also include new libraries

 

#include <stdio.h>
#include <Windows.h>
#include <winnt.h>
#include <ansi_c.h>
#include <ctype.h>
#include <string.h>
#include <except.h> 

 

and the preprocesors:

 

LPCSTR=char*;BOOL=int;BYTE=unsigned char;WORD=unsigned short;UINT=unsigned int;DWORD=unsigned long;CHAR=char;SHORT=short;INT=int;LONG=long;LONGLONG=int64_t

 

With this LabVIEW has found almost all the functions, but I have been worried about it does not work for being functions "callback"

 

0 Kudos
Message 5 of 16
(5,140 Views)

Good morning Rolf

 

Thank you very much for your response, first to begin to programate the camera, i need import all the functions in labview to work. Your tips have been very useful:

 

1) I changue all the "&" operators for "*" in the header

2) How could I solve this problem? for use this type of functions.

 

In the header i have also include new libraries

 

#include <stdio.h>
#include <Windows.h>
#include <winnt.h>
#include <ansi_c.h>
#include <ctype.h>
#include <string.h> 
#include <except.h> 

 

and the preprocesors:

 

LPCSTR=char*;BOOL=int;BYTE=unsigned char;WORD=unsigned short;UINT=unsigned int;DWORD=unsigned long;CHAR=char;SHORT=short;INT=int;LONG=long;LONGLONG=int64_t

 

With this LabVIEW has found almost all the functions, but I have been worried about it does not work for being functions "callback"

 

Thanks for your answer

0 Kudos
Message 6 of 16
(5,136 Views)

Good mornign Tom

 

I can't rebuild the dll because I'don't have the library (.lib) to do this. i probe to include news libraries ans preprocesors:

 

#include <stdio.h>
#include <Windows.h>
#include <winnt.h>
#include <ansi_c.h>
#include <ctype.h>
#include <string.h> 
#include <except.h> 

 

and the preprocesors:

 

LPCSTR=char*;BOOL=int;BYTE=unsigned char;WORD=unsigned short;UINT=unsigned int;DWORD=unsigned long;CHAR=char;SHORT=short;INT=int;LONG=long;LONGLONG=int64_t

 

With this finds more functions!

 

Thanks for your answer

0 Kudos
Message 7 of 16
(5,134 Views)
Solution
Accepted by topic author Obli33

You shouldn't really need to add all those include files if you do the definition of the preprocessor defines yourself.

 

As to callbacks, yes there is a possibility to incorporate them but no the import library wizard can't do it and I do not recommend to try it. It requires very detailed knowledge about what a C compiler normally does for you, how to apply that to LabVIEW and more importantly it is VERY error prone (you need to be proficient in C programming way beyond being able to compile your own DLL) and last but not least a complete maintenance nightmare (it is not easily portable to another LabVIEW version without lots and lots of handholding and redoing some of the work you already did).

 

The only solution I can fully recommend when needing to implement callback functions is to write a wrapper DLL in C that implements those callback functions and translates the invocation of that callback function into a LabVIEW User Event or similar. But yes that requires you to write C code and compile a DLL and yes that is not trivial. Considering that you try to interface to a camera interface you also need to know that this is one of the more tricky devices to interface anyways and you often anyhow don't get around writing some helper code in C to efficiently translate some of the data to more LabVIEW friendly formats.

Rolf Kalbermatter
My Blog
Message 8 of 16
(5,126 Views)

The truth that to program in C I do not have much idea so I really appreciate your advices. I'm going to try to make a DLL wrapper, Do you know any tutorial or example of making a warpper DLL in C of a callback function with which i can guide?

 

Again thank you very much for your help

0 Kudos
Message 9 of 16
(5,119 Views)

Basically if you look for PostLVUserEvent here on this forum and/or lavag.org you should find quite a few posts that detail the principle. But callback functions is one of the more advanced features of C programming. Many C programmers do not really know how that works and never really need to either.

If you don't have serious C programming knowledge I would advise you to find someone who has and let him do this work.

Rolf Kalbermatter
My Blog
Message 10 of 16
(5,114 Views)