LabWindows/CVI

取消
显示结果 
搜索替代 
您的意思是: 

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.
1 条消息(共 19 条)
6,517 次查看
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.
2 条消息(共 19 条)
6,517 次查看
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 项奖励
3 条消息(共 19 条)
5,764 次查看

@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 项奖励
4 条消息(共 19 条)
5,743 次查看
what library is this function DLLEXPORT _VI_FUNC located. also can you give me an example using this function?
0 项奖励
5 条消息(共 19 条)
5,738 次查看

#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
6 条消息(共 19 条)
5,733 次查看

@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 项奖励
7 条消息(共 19 条)
5,729 次查看

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 项奖励
8 条消息(共 19 条)
5,720 次查看
im getting one error on the old program, i sent a screen shot
0 项奖励
9 条消息(共 19 条)
5,714 次查看

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 项奖励
10 条消息(共 19 条)
5,695 次查看