LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call C++ Dll function from Labview

Hello,

 

I would like to drive a camera with Labview. I have the dll and a .h file. I never used C or C++ and I am unable to understand such topics on NI forum.

 

I tried to use the Import Sharded Library Wizard in Labview, but I have some errors due to unknown parameters (IN, HWND,LPCSTR).

 

Here under is a small extract of the .h filewith the CameraInit function is the most ununderstable for me, so if you have solutions or examples to propose, I will be quite happy to test them. I attached the complete .h file and the DSDefine.h file which define type and enum used in the header file.

 

Thanks in advance for your help.

 

Mathieu

 

#include "DSDefine.h"
//#include "stdafx.h"
// DECLDIR will perform an export for us
#define DLL_EXPORT

#ifdef DLL_EXPORT
    #define DT_API extern "C" __declspec(dllexport)
#else
    #define DT_API extern "C" __declspec(dllimport)
#endif

DT_API DS_CAMERA_STATUS CameraInit(DS_SNAP_PROC pCallbackFunction, DS_RESOLUTION uiResolution,HWND hWndDisplay, CWnd* pParent );

Download All
0 Kudos
Message 1 of 19
(4,768 Views)

Hi Mathieu,

 

Could you tell us what is your camera (type, manufacturer) and which version of Labview do you want to use with?

Other question: is it possible to post your dll?

 

Regards

Jean-Philippe C.
National Instruments France

0 Kudos
Message 2 of 19
(4,728 Views)

Hello Jean-Philippe,

 

thanks for your answer.

 

The web cam is made by M42Optics, a french company specialised in equipments for astronomy. I am in cantact with them, but they are not Labview/Matlab user, so it is quite complicated. My objectif is to drive this camera either with Labview or Matlab, especially, I would like to set the exposure time programmatically, and of course take picture and save them. 

 

Here is the SDK Package, I suppose it was given to M42 Optics by the CCD sensor supplier (Sony ICX204). I also included the demo source code supplied by M42Optics, but it is coded in C++ and I am unable to understand it. Maybe it can be usefull for you...

 

Thanks for your help;

 

Mathieu

Download All
0 Kudos
Message 3 of 19
(4,718 Views)

I forgot to tell you : I have Labview 2010, and also the vision toolbox.

 

Mathieu

0 Kudos
Message 4 of 19
(4,717 Views)

Unfortunately, if you've never used C or C++ before, this is not a good place to start.  There's no way to handle a callback parameter in LabVIEW so if you need to use that parameter of the CameraInit function, you'll need to write an additional C wrapper around it containing a callback function in C that can talk to LabVIEW, which isn't easy if you have no C experience.  Your best bet is to find someone with the appropriate experience or see if someone has already written a working LabVIEW driver for your camera.  Even if you don't need the callback (the one in the demo code does nothing and simply returns TRUE) you'll still need some understanding of C data structures and memory allocation.

0 Kudos
Message 5 of 19
(4,701 Views)

Basically you'll need a bunch of Call Library Functions, which i'd wrap into a small vi for each.

They can be found in Connectivity -> Libraries.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 19
(4,696 Views)

Hello,

 

thanks for your answer. In fact, I understand a little bit C language as I know Matlab (very similar), but I am unable to write a C code by myself.

 

I tried to call fonctions by using the "call a dll function" in labview and with the shared library wizard, but some types defined with the arguments are not known (ushort ?? IN ?). I suppose Labview should replace it by U16 or U8 or something like that...

 

Can I manually modify my header file and replace these types by Labview types ???

Other question : What does "IN" mean ?I didn't find any explantation in C/C++ books

For example :

CameraGetGain(IN int *pRGain, int *pGGain, int *pBGain); Labview don't understand this parameter when I import the dll library.

 

Thanks for your help.

 

Mathieu

0 Kudos
Message 7 of 19
(4,653 Views)

I have little experience with C++ specifically on Windows, but I believe you can ignore the IN and OUT qualifiers for the purpose of importing the header into LabVIEW.  Those qualifiers are not part of standard C.

 

For the standard datatypes (USHORT, BYTE) you would want to replace those with equivalent standard C data types (unsigned short, unsigned char).

 

There will be other types in your library that LabVIEW can't identify, because they are defined in the header file, for example the function

DT_API DS_CAMERA_STATUS CameraSetFrameSpeed(IN DS_FRAME_SPEED FrameSpeed);

 

takes an enumeration of type DS_FRAME_SPEED.  You can replace that with an unsigned int, then create a matching enumeration in LabVIEW and pass that to your library.

 

Once you get through all of that, you will still be unable to call the CameraInit function mentioned in your first message with anything other than a NULL value for the pCallbackFunction parameter, because there is no way to pass a pointer to a LabVIEW function.  To implement that callback parameter you will need to write and compile some C code.  If you do not actually need to implement a callback function (consult the documentation) then you may be able to get it working without that step.

0 Kudos
Message 8 of 19
(4,639 Views)

the IN and OUT keywords are used to define if it's an input or output of the function. If memory serves IN parameters cannot be changed and is thus secured while OUT is basically a reserved answer space/adress.

 

In this case it'd mean that you can set the camera gain and the in parameters should be protected.

(man it was a long time since i looked at C)

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 19
(4,613 Views)

Hello everybody,

 

thanks for your answer. I tried to delete the "IN" and "OUT" qualifiers and to replace the USHORT terms by Labview types and it seems to work for most of the dll subfunctions. I mean : I can use the different "get" and "set" subfunctions.

 

Now, I have still one problem to solve : the initialisation of the Camera. [ DT_API DS_CAMERA_STATUS CameraInit(DS_SNAP_PROC pCallbackFunction, IN DS_RESOLUTION uiResolution,IN HWND hWndDisplay, CWnd* pParent );]

 

The HWND and CWND parameters are typic of C++, I do not know exactly what they are. I read that HWND is the handle of the window which will display pictures coming from the camera.

I suppose I have to create this window object in Labview and pass the reference to the CameraInit function but how can I make this with Labview ?

 

Concerning CWND, I read it concerns error messages from the OS Windows.

 

If I try to make the init like : CameraInit(0,0,0,0), it works well, except that then when I call the CameraPlay subfunction, I can not see the video data, probably because the 0 value is bad for the hWndDisplay argument.

 

Anybody has an idea for this problem ???

 

Thanks in advance for your advices.

 

Mathieu

 

 

0 Kudos
Message 10 of 19
(4,604 Views)