文档详情

vs2010创建Dll例子.doc

发布:2017-06-03约2.58千字共2页下载文档
文本预览下载声明
vs2010创建Dll例子,并解决运行错误:应用程序正常初始化(0xc000000d)失败。请单击“确定”,终止应用程序。 调用Dll的工程遇到应用程序正常初始化(0xc000000d)失败。请单击“确定”,终止应用程序。 我的开发环境是Win32 XP,VS2010 最终找到原因,之前使用的是Debug模式,应该使用Release来编译生成Dll,使用才不会出错,特此记录整个配置过程以备忘,折腾免疫HOHO~:1、新建Win32工程,选择Dll,工程名叫MyDll 2、添加Header Files:testdll.h,内容如下: [cpp] view plaincopyprint? #ifndef?TestDll_H_ ?? #define?TestDll_H_ ?? ?? #ifdef?MYDLL_EXPORTS ?? #define?MYLIBDLL?extern?C?_declspec(dllexport)? ?? #else ?? #define?MYLIBDLL?extern?C?_declspec(dllimport)? ?? #endif ?? ?? extern?C??? {?? ????MYLIBDLL?int?Add(int?plus1,?int?plus2);?? };?? #endif??#ifndef TestDll_H_ #define TestDll_H_ #ifdef MYDLL_EXPORTS #define MYLIBDLL extern C _declspec(dllexport) #else #define MYLIBDLL extern C _declspec(dllimport) #endif extern C { MYLIBDLL int Add(int plus1, int plus2); }; #endif 3、添加Source Files:testdll.cpp,内容如下: [cpp] view plaincopyprint? #include?stdafx.h ?? #include?testdll.h ?? #include?iostream ?? using?namespace?std;?? ?? int?Add(int?plus1,?int?plus2)?? {?? ????int?add_result?=?plus1?+?plus2;?? ????return?add_result;?? }??#include stdafx.h#include testdll.h #include iostream using namespace std; int Add(int plus1, int plus2) { int add_result = plus1 + plus2; return add_result; } 4、选择编译类型为:Release?(注意,之前我一直使用Debug模式就会遇到各种错误无法使用,为什么请知道的大侠赐教,不胜感激?) 5、编译输出.lib和.dll文件。 6、将testdll.h、MyDll.lib、MyDll.dll三个文件放在新建的目录libs中,并放在下一个工程的项目文件夹里(和?MyDllDemo.sln 同在一个文件夹下)。 =============================================== 1、新建Win32 Console工程,命名为MyDllDemo 2、修改MyDllDemo.cpp文件内容如下: [cpp] view plaincopyprint? #include?stdafx.h ?? ?? #include?iostream ?? using?namespace?std;?? ?? #include?testdll.h ?? //#pragma?comment(lib,MyDll.lib) ?? ?? int?main()?? {?? ????int?a?=?1;?? ????int?b?=?2;?? ????int?c?=?Add(a,b);?? ????printf(%d?+?%d?=?%d\n,a,b,c);?? ?? ????getchar();?? ????return?0;?? }?? #include stdafx.h #include iostream using namespace std; #include testdll.h //#pragma comment(lib,MyDll.lib) int main() { int a = 1; int b = 2; int c = Add(a,b); printf(%d + %d = %d\n
显示全部
相似文档