Labview 下建立dll及其使用
1、建立动态连接库的C代码调用
1.1建立函数原形
1)后面框图程序中,调用CLF节点;
2)配置一个函数原形,比如long add2(long a,long b),设置
调用规程为C,其它不变,确定,退出;
3)右键CLF节点,create C file,保存名字为code.cpp,以供
VC++编译使用;
1.2 编辑源代码文件
1)将所需要的labview头文件复制到code.cpp所在目录中,包括:extcode.h platdefines.h fundtype.h;
2) 打开code.cpp,添加关键词extern “c”、_declspec(dllexport)并包装;然后输入函数的功能代码,如果1个dll里面需要多个函数,则需要声明多个函数的原形。本例子采用了2个函数,add 和mult2.
/* Call Library source file */
#include "extcode.h"
extern "C"{
_declspec(dllexport) long add2(long a, long b);
_declspec(dllexport) long mult2(long a, long b);
}
_declspec(dllexport) long add2(long a, long b)
{
/* Insert code here 加法*/
return(a+b);
}
_declspec(dllexport) long mult2(long a, long b)
{
return(a*b); /* 乘法*/
}
2、VC++中编译产生dll
1)建立project ,file→new-> win32 Dyna,mic Link Library,输入工
程名,选择an empty dll project;
2)添加code.cpp到source file,添加extcode.h platdefines.h
fundtype.h到head files里面;
3)设置dll参数project→settings→c/C++中设置参数:category:
code generation ;根据函数要求可以选择1Byte\4 Byte\ 8Byte,采用默认就可以;multithread;其余默认可以;自己也可以微调;
4)Build Build code.dll;
5)Ok!
3采用Labview测试验证。