




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
CVI显性调用VC生成的DLL的详细步骤及注意事项2017/4/16 Create by 狄阁老If you have any question ,please mailto:关键字:CVI,VC+6.0 ,动态链接库DLL,CVI显性调用VC+6.0生成的DLL最近在忙于用Labwindows/CVI实现某种功能,需要用利用VC+6.0环境开发的dll,然后供Labwindows/CVI调用。详细步骤如下:步骤1,打开VC+6.0环境,文件-新建-选择Win32 Dynamic-Link Library ,输入工程名,例如test04,见图1;图1, 步骤1步骤2,点击确定,选择一个“一个可以导出某些符号的DLL工程”,如图2,点击完成,出现一个确定界面,点击界面上的确定按钮,图2 步骤2步骤3,清除test04.cpp中的默认代码(红色),再在test04.h中清除默认的定义(绿色)/ This is an example of an exported variableTEST04_API int nTest04=0;/ This is an example of an exported function.TEST04_API int fnTest04(void)return 42;/ This is the constructor of a class that has been exported./ see test04.h for the class definitionCTest04:CTest04() return; / This class is exported from the test04.dllclass TEST04_API CTest04 public:CTest04(void);/ TODO: add your methods here.;extern TEST04_API int nTest04;TEST04_API int fnTest04(void);步骤4,在test04.cpp中添加自己的函数,例如:TEST04_API int add(int x,int y) return x+y;TEST04_API int maxvalue(int x,int y) if(xy) return x; else return y;TEST04_API float sub(float x,float y) return x-y;TEST04_API void hello(void)MessageBox (0, LabWindowsCVI调用dll成功n, 欢迎, MB_ICONINFORMATION);TEST04_API char * returnstr(const char * s1, const char * s2)int m1,m2; /两字符串长度m1=strlen(s1); m2=strlen(s2); /求长度char * s=(char *)malloc(sizeof(char)*(m1+m2+1); /申请内存空间,多1字节strcpy(s,s1); /复制第一个字符串strcpy(s+m1,s2); /复制第二个字符串return s; /返回结果步骤5,在test04.h添加定义TEST04_API int add(int x,int y);TEST04_API int maxvalue(int x,int y);TEST04_API float sub(float x,float y);TEST04_API void hello(void);TEST04_API char * returnstr(const char * s1, const char * s2);步骤6,最重要的一步,需要添加.def文件在工程路径下新建一个.txt文本,在里面添加如下内容(红色),见图3;LIBRARY testmydll /引号内的随便写 EXPORTS add maxvaluesubhelloreturnstr图3 步骤6步骤7,将.def添加到工程中,见图4;图4 步骤7步骤8,然后在工程下debug下找到test04.dll拷贝到CVI工程下,CVI工程代码如下:/=/ Title: testDLL/ Purpose: A short description of the application./ Created on: 2017/4/15 at 20:20:28 by digelao./ Copyright: . All Rights Reserved./=/=/ Include files#include #include #include #include #include testDLL.h#include toolbox.h/=/ Constants/=/ Types/=/ Static global variablesstatic int panelHandle;HINSTANCE hDll;/句柄 typedef int (*myfuction)(int,int);myfuction mf=NULL;typedef void (*hello)(void);hello hl=NULL;typedef char* (*returnstr)(const char *,const char *);returnstr rs=NULL;typedef int (*maxvalue)(int,int);maxvalue mx=NULL;typedef float (*sub)(float,float);sub sb=NULL;/=/ Static functions/=/ Global variables/=/ Global functions/ HIFN The main entry-point main (int argc, char *argv) int error = 0; /* initialize and load resources */ nullChk (InitCVIRTE (0, argv, 0); errChk (panelHandle = LoadPanel (0, testDLL.uir, PANEL);/以下至 /* display the panel and run the user interface */之间是加载dll中的函数hDll=LoadLibrary(test04.dll);/动态加载DLL模块句柄mf=(myfuction) GetProcAddress(hDll,add);/得到所加载DLL模块中函数的地址if(mf=NULL)MessagePopup (, 调用函数add失败!);hl=(hello) GetProcAddress(hDll,hello);/得到所加载DLL模块中函数的地址if(hl=NULL)MessagePopup (, 调用函数hello失败!);rs=(returnstr) GetProcAddress(hDll,returnstr);/得到所加载DLL模块中函数的地址if(rs=NULL)MessagePopup (, 调用函数returnstr失败!);mx=(maxvalue) GetProcAddress(hDll,maxvalue);/得到所加载DLL模块中函数的地址if(mx=NULL)MessagePopup (, 调用函数maxvalue失败!);sb=(sub) GetProcAddress(hDll,sub);/得到所加载DLL模块中函数的地址if(mx=NULL) MessagePopup (, 调用函数sub失败!); /* display the panel and run the user interface */errChk (DisplayPanel (panelHandle);errChk (RunUserInterface ();Error: /* clean up */ DiscardPanel (panelHandle); return 0;/=/ UI callback function prototypes/ HIFN Exit when the user dismisses the CVICALLBACK panelCB (int panel, int event, void *callbackData, int eventData1, int eventData2) if (event = EVENT_CLOSE) QuitUserInterface (0); return 0;int CVICALLBACK OkCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)int m=0;float tmp=0;char str1000;switch (event)case EVENT_COMMIT: /SetWaitCursor (0); m=mf(100,9000);/调用add函数SetCtrlVal (panelHandle, PANEL_NUMERIC, m);/Delay(1);hl();/调用hello函数strcpy(str,rs(fml,dyp);/调用returnstr函数returnstrSetCtrlVal (panelHandle, PANEL_TEXTMSG, str);m=mx(5,15); /调用maxvalue函数SetCtrlVal (panelHandle, PANEL_NUMERIC, m); tmp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 校园招聘护士真题及答案
- 松茸创新创业项目商业计划书
- 热压延工中秋节后复工安全考核试卷含答案
- 水解蒸馏工中秋节后复工安全考核试卷含答案
- 外来车辆培训课件
- 报备购房合同(标准版)
- 牛配种合同(标准版)
- 陶瓷压制成型工中秋节后复工安全考核试卷含答案
- 新型医患关系定义探析
- 地层测试工中秋节后复工安全考核试卷含答案
- 校长讲法治课课件
- 2025年全国中小学校党组织书记网络培训示范班在线考试题库及答案
- GB/T 34875-2017离心泵和转子泵用轴封系统
- GB/T 21063.4-2007政务信息资源目录体系第4部分:政务信息资源分类
- GA/T 1081-2020安全防范系统维护保养规范
- 02药物不良反应adr课件
- 施工项目成本管理课件
- 文物建筑保护修缮专项方案
- 营销与2008欧锦赛ktv渠道方案
- 故障录波器课件
- DB32-T 2665-2014机动车维修费用结算规范-(高清现行)
评论
0/150
提交评论