hallo alle zusammen,
ich habe folgende versucht:
Mit Hilfe dieses link "http://labviewwiki.org/DLL/shared_library", einen
DLL von C++ zu erstellen und dann dieses DLL in Labview zu importieren.
Die normale Klasse "Header File"
1 | #ifndef _BASE_CLASS_H_
|
2 | #define _BASE_CLASS_H_
|
3 |
|
4 | class base
|
5 | {
|
6 | public:
|
7 | base(double x_in);
|
8 | virtual ~base(void);
|
9 | void set_x(double x_in);
|
10 | void get_x(double* x_out);
|
11 | void sqr_x(void);
|
12 |
|
13 | private:
|
14 | double x;
|
15 | };
|
Cpp File:
1 | #include "base_class.h"
|
2 | #include <windows.h>
|
3 |
|
4 | base::base(double x_in)
|
5 | {
|
6 | x = x_in;
|
7 | }
|
8 |
|
9 | base::~base ()
|
10 | {
|
11 | /* clean up */
|
12 | }
|
13 |
|
14 | void base::set_x(double x_in)
|
15 | {
|
16 | x = x_in;
|
17 | }
|
18 |
|
19 | void base::get_x(double* x_out)
|
20 | {
|
21 | *x_out = x;
|
22 | }
|
23 |
|
24 | void base::sqr_x(void)
|
25 | {
|
26 | x*=x;
|
27 | }
|
c_DLL_Wrapper Header File:
1 | #ifndef _C_DLL_WRAPPER_H_
|
2 | #define _C_DLL_WRAPPER_H_
|
3 |
|
4 | /* building a DLL */
|
5 | #define DLLIMPORT __declspec (dllexport)
|
6 |
|
7 | #ifdef __cplusplus
|
8 | extern "C" { /* using a C++ compiler */
|
9 | #endif
|
10 |
|
11 | typedef struct base base; /* make the class opaque to the wrapper */
|
12 |
|
13 | DLLIMPORT base* create_base(double x_in);
|
14 | DLLIMPORT void set_x(base* LV_ref, double x_in);
|
15 | DLLIMPORT void get_x(base* LV_ref, double* x_out);
|
16 | DLLIMPORT void destroy_base(base* LV_ref);
|
17 | DLLIMPORT void sqr_x(base* LV_ref);
|
18 |
|
19 | #ifdef __cplusplus
|
20 | }
|
21 | #endif
|
22 |
|
23 |
|
24 | #endif /* _C_DLL_WRAPPER_H_ */
|
25 |
|
26 |
|
27 | #endif /* _BASE_CLASS_H_ */
|
CPP File der C_DLL_Wrapper
1 | #include "c_dll_wrapper.h"
|
2 | #include "base_class.h"
|
3 | #include <windows.h>
|
4 |
|
5 | DLLIMPORT base* create_base(double x_in)
|
6 | {
|
7 | return new base(x_in);
|
8 | }
|
9 |
|
10 | DLLIMPORT void set_x(base* LV_ref, double x_in)
|
11 | {
|
12 | LV_ref->set_x(x_in);
|
13 | }
|
14 |
|
15 | DLLIMPORT void get_x(base* LV_ref, double* x_out)
|
16 | {
|
17 | LV_ref->get_x(x_out);
|
18 | }
|
19 |
|
20 | DLLIMPORT void destroy_base(base* LV_ref)
|
21 | {
|
22 | delete LV_ref;
|
23 | }
|
24 |
|
25 | DLLIMPORT void sqr_x(base* LV_ref)
|
26 | {
|
27 | LV_ref->sqr_x();
|
28 | }
|
Das DLL konnte es erstellt werden.
Nur beim Importieren von der DLL File in Labview bekomme ich folgende
Fehlermeldung(seh bitte Anhang).
Das Importieren an sich ist kein Problem und ich konnte auch alle
Methode exportieren.Problem tritt bei Ausführung eine der Funktion.