LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to programm dll using CVI?

I know how to create a dll. But how to make a dll programm? How to denify the parameters in programming? I use CVI.
Message 1 of 19
(6,127 Views)
While creating your DLL, you need to identify which functions you want to make available to other programs. These are the functions your DLL will export as described below.
1. In your DLL project, create a .h file which includes only the function prototypes for the exported functions and declarations for exported constants or globals.
1.1 These functions may have prototypes in other .h or .c files, but prefix the ones in the exports .h files with extern int __cdecl.
For example, if your existing function prototype is
int MyFunction(int myInt);
your exports .h file prototype would be
extern int __cdecl MyFunction(int myInt);
1.2 If you want the option of calling your DLL functions from a C++ project, wrap all your functions if the following:
// call everything extern C if a C++ compiler is used
#ifdef __cplusplus
extern "C" {
#endif
// all your function prototype go here
// ...
// end of extern C block if a C++ compiler is used
#ifdef __cplusplus
extern "C" }
#endif
2. Add the exports .h file to your DLL project. From the CVI project window in your DLL application, goto Edit >> Add Files to Project >> Include (*.h). The exports .h file is typically not included (#include) in another .h or .c file in your project.
3. Tell CVI to export everything in the exports .h file: from the CVI project window in your DLL project, goto Build >> Target Settings >> Change (in the Exports box). Select the exports .h file you created in step 1. If you don't see the file, click on Cancel >> Cancel, then make sure your added the file to your project and saved your project, then try again.
4. Build your project.
5. Add the .LIB file from your DLL project to the project that will use the DLL functions.
6. #include the exports.h file in a .h or .c file in the project that will use your DLL functions.
7. Make sure that the project that will use your DLL functions can find the DLL file. Either put the DLL file in a directory on the executable search path or in the project directory for the project that will use your DLL functions.
Now you're ready to call your DLL functions.
Message 2 of 19
(6,127 Views)
also when i run my program its not generating my lib file ,its only generating my dll file and obj file, do you know why that is?
0 Kudos
Message 3 of 19
(5,374 Views)

@darnell,

 

You must prefix each declaration of the functions  you want to export, with "DLLEXPORT _VI_FUNC". In this case your dll target setting for exports should be set to "symbols marked for export". Only these functions will be exported.

 

If you want to export all the files in an include file, your dll target settings for exports should be set to "include file symbols" than choose the desired include file.

 

Only than your lib file will be also created.

 

Regards.

0 Kudos
Message 4 of 19
(5,353 Views)
what library is this function DLLEXPORT _VI_FUNC located. also can you give me an example using this function?
0 Kudos
Message 5 of 19
(5,348 Views)

#define DLLEXPORT __declspec(dllexport)

(this is defined in <cvidef.h>, which should be automatically included...)

 

on the other hand, _VI_FUNC is nowhere to be found. but i would suggest using DLLSTDCALL (which i bet resolves to the same function decorator):

#define DLLSTDCALL __stdcall

(this is also defined in <cvidef.h>)

 

use those when declaring the functions you want to export:

int DLLEXPORT DLLSTDCALL sample_function(void);

Message Edited by dummy_decoy on 09-25-2009 03:16 AM
Message 6 of 19
(5,343 Views)

@darnell,

 

Assume, that inside a dll,  we have following functions:

 

void myFunc1 (int i);
void myFunc2(int i);

 

 

If want to export function just myFunc1, you have to change its declaration as follows:

 

void DLLEXPORT _VI_FUNC myFunc1 (int i);

 

If Exports is set to: Symbols marked for export, than only myFunc1 will be exported. "DLLEXPORT" is defined in cvidef.h and "_VI_FUNC" is defined in visatype.h 

 

Regards

 

0 Kudos
Message 7 of 19
(5,339 Views)

okay its coming together , i started over from scratch and tried a basic program, I have two functions that i call, only function is working.

 

my PRINT(); is not working, meaning its not print out my string;

 

check the cvi pro out . to see what im talking about.

0 Kudos
Message 8 of 19
(5,330 Views)
im getting one error on the old program, i sent a screen shot
0 Kudos
Message 9 of 19
(5,324 Views)

you need the DLLEXPORT to compile the DLL, in order to tell the compiler you want to export the function.

 

once it is in the dll, the function declaration does not need the DLLEXPORT anymore, so remove it from your CVI code. in the program which is using the dll, you don't need to export anything, you need to import the function.

0 Kudos
Message 10 of 19
(5,305 Views)