资源描述:
《CVI显性调用VC生成的DLL》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、CVI显性调用VC生成的DLL的详细步骤及注意事项2017/4/16Createby狄阁老Ifyouhaveanyquestion,pleasemailto:mlfannuaa@163.com关键字:CVI,VC++6.0,动态链接库DLL,CVI显性调用VC++6.0生成的DLL最近在忙于用Labwindows/CVI实现某种功能,需要用利用VC++6.0环境开发的dll,然后供Labwindows/CVI调用。详细步骤如下:步骤1,打开VC++6.0环境,文件->新建->选择Win32Dynamic-LinkLibrary,输入工程名,例如test04,见图1;图1,步骤1步骤
2、2,点击确定,选择一个“一个可以导出某些符号的DLL工程”,如图2,点击完成,出现一个确定界面,点击界面上的确定按钮,图2步骤2步骤3,清除test04.cpp中的默认代码(红色),再在test04.h中清除默认的定义(绿色)//ThisisanexampleofanexportedvariableTEST04_APIintnTest04=0;//Thisisanexampleofanexportedfunction.TEST04_APIintfnTest04(void){return42;}//Thisistheconstructorofaclassthathasbeenexpo
3、rted.//seetest04.hfortheclassdefinitionCTest04::CTest04(){return;}//Thisclassisexportedfromthetest04.dllclassTEST04_APICTest04{public:CTest04(void);//TODO:addyourmethodshere.};externTEST04_APIintnTest04;TEST04_APIintfnTest04(void);步骤4,在test04.cpp中添加自己的函数,例如:TEST04_APIintadd(intx,inty){returnx+
4、y;}TEST04_APIintmaxvalue(intx,inty){if(x>y)returnx;elsereturny;}TEST04_APIfloatsub(floatx,floaty){returnx-y;}TEST04_APIvoidhello(void){MessageBox(0,"LabWindowsCVI调用dll成功","欢迎",MB_ICONINFORMATION);}TEST04_APIchar*returnstr(constchar*s1,constchar*s2){intm1,m2;//两字符串长度m1=strlen(s1);m2=strlen(s2
5、);//求长度char*s=(char*)malloc(sizeof(char)*(m1+m2+1));//申请内存空间,多1字节strcpy(s,s1);//复制第一个字符串strcpy(s+m1,s2);//复制第二个字符串returns;//返回结果}步骤5,在test04.h添加定义TEST04_APIintadd(intx,inty);TEST04_APIintmaxvalue(intx,inty);TEST04_APIfloatsub(floatx,floaty);TEST04_APIvoidhello(void);TEST04_APIchar*returnstr(co
6、nstchar*s1,constchar*s2);步骤6,最重要的一步,需要添加.def文件在工程路径下新建一个.txt文本,在里面添加如下内容(红色),见图3;LIBRARY"testmydll"//引号内的随便写EXPORTSaddmaxvaluesubhelloreturnstr图3步骤6步骤7,将.def添加到工程中,见图4;图4步骤7步骤8,然后在工程下debug下找到test04.dll拷贝到CVI工程下,CVI工程代码如下://=======================================================================
7、=======////Title:testDLL//Purpose:Ashortdescriptionoftheapplication.////Createdon:2017/4/15at20:20:28bydigelao.//Copyright:.AllRightsReserved.////==============================================================================//==========