LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C++ & dll & labview

i still have 1~2  months for this project.
The instrument company do offer the software written in c++, i do hope can throw to them to make my life better but too bad i also hire to do all the test related task. However, i would also like to learn new things.. ~no pain, no gain~
From my understanding, i do need to write one upper layer above to counter all the C++ code, I know how to create those vi from dll & header if under ansi C platform but not to convert c++ to c platform, appreciate if can show me example here at the same time i going to go through some reference.
 
Simon
0 Kudos
Message 11 of 21
(1,194 Views)


@simon76 wrote:
i still have 1~2  months for this project.
The instrument company do offer the software written in c++, i do hope can throw to them to make my life better but too bad i also hire to do all the test related task. However, i would also like to learn new things.. ~no pain, no gain~
From my understanding, i do need to write one upper layer above to counter all the C++ code, I know how to create those vi from dll & header if under ansi C platform but not to convert c++ to c platform, appreciate if can show me example here at the same time i going to go through some reference.
 
Simon


Well I'm not writing this for you and C++ is anything but well known area to me but I can give you an example that should give you an idea:

#include "iqapi.h"

#define IQHLP_API_C extern "C" __declspec(dllexport)

IQHLP_API_C iqapiModulationWave* iqapiModulationWave_create(void);
IQHLP_API_C void iqapiModulationWave_delete(iqapiModulationWave* obj);
IQHLP_API_C int iqapiModulationWave_GetLength(iqapiModulationWave* obj, int index);
IQHLP_API_C void iqapiModulationWave_SetLength(iqapiModulationWave* obj, int index, int length);


IQHLP_API_C iqapiModulationWave* iqapiModulationWave_create(void)
{
      return new iqapiModulationWave();
}

IQHLP_API_C void iqapiModulationWave_delete(iqapiModulationWave* obj)
{
      delete obj;
}

IQHLP_API_C int iqapiModulationWave_GetLength(iqapiModulationWave* obj, int index)
{
   if (index >= 0 && index < N_MAX_TESTERS)
        return obj->length[index];
   else
        return 0;
}

IQHLP_API_C void iqapiModulationWave_SetLength(iqapiModulationWave* obj, int index, int value)
{
    if (index >= 0 && index < N_MAX_TESTERS)
        obj->length[index] = value;
}

I'm sure you do get the idea of this. Basically you need to wrap any C++ public method and variable you want to be able to access into standard C exported functions.

Rolf Kalbermatter


Message Edited by rolfk on 05-06-2008 11:36 AM
Rolf Kalbermatter
My Blog
Message 12 of 21
(1,183 Views)

Do you accept any student, master.. ")

btw, i roughly understand but still long way to go..

Thanks for the explaination

Regards,

Simon

0 Kudos
Message 13 of 21
(1,177 Views)
Yes, to clarify:  writing a wrapper DLL can be compared to writing a completely separate program in C that calls into your original DLL.  Your original DLL was designed to be accessed from C (or similar low-level languages) and not LabVIEW, so it is helpful to write a C program to access it which is itself designed to be accessed from LabVIEW.  In this sense, your new C program "wraps" around the original C program (DLL) and provides a layer of compatibility.

Since you are accessing the original DLL from C/C++, as the original author intended, there should be no need for you to modify its original source code.
Eric V
National Instruments
Applications Engineer
Certified LabVIEW Associate Developer


"I'm a Ramblin' Wreck from Georgia Tech and a helluva (NI Applications) Engineer!"
Message 14 of 21
(1,164 Views)
Hi,
I get the error 1097 when trying to call dll, any idea what happen here??
 
regards,
simon
0 Kudos
Message 15 of 21
(1,107 Views)

It seems you have made some wrong initilaization for the dll inputs in the InitTester.vi

Could you please attach that vi or a screenshot of it so that we can easily trace it out.

Thanks,

Mathan

0 Kudos
Message 16 of 21
(1,101 Views)

Hi Mathan,

Attach with the vi & related files.

If run individually, the error wouldn't show but combine them together, then sometime the error show. If the error show, when run the last dll (disconnect from tester/deiniatilization tester function -- term.dll), the labview crash and exit.

regards,

 

Download All
0 Kudos
Message 17 of 21
(1,094 Views)


@simon76 wrote:

Hi Mathan,

Attach with the vi & related files.

If run individually, the error wouldn't show but combine them together, then sometime the error show. If the error show, when run the last dll (disconnect from tester/deiniatilization tester function -- term.dll), the labview crash and exit.

regards,



I guess your hook DLL is a wrapper DLL written by you. As far as the LP Init Tester VI is concerned and looking at the header file everything seems to be right so I guess it must be something you are doing in your C code in that wrapper DLL that is wrong.

Since you do not export any aspect of the C++ objects in those function AFAICS you must be using global variables to store your objects inside the DLL. That can be rather tricky if not done right with resource leaks and more.

Rolf Kalbermatter


Message Edited by rolfk on 05-20-2008 08:46 AM
Rolf Kalbermatter
My Blog
0 Kudos
Message 18 of 21
(1,091 Views)

Attach with the code here.

 

0 Kudos
Message 19 of 21
(1,087 Views)

Hi Rolf,

May I know what's the mean of "not done right with resource leaks and more" ??

regards

 


 

0 Kudos
Message 20 of 21
(1,063 Views)