如何书写动态连接库
来源:互联网 发布:电脑软件停止工作 编辑:程序博客网 时间:2024/04/30 20:20
1.DIL文件代码如下
// TestDll.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
extern "C" __declspec( dllexport ) int AddFunction(int x, int y);
extern "C" __declspec( dllexport ) int JanFunction(int x, int y);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int AddFunction(int x, int y)
{
return x+y;
}
int JanFunction(int x,int y)
{
return x-y;
}
2.如何调用
#include <iostream>
#include <conio.h>
using namespace std;
extern "C" __declspec(dllimport) int AddFunction(int x, int y);
extern "C" __declspec(dllimport) int JanFunction(int x, int y);
int main(void)
{
int x;
int y;
cout<<"请输入X的值:";
cin>>x;
cout<<"请输入Y的值:";
cin>>y;
int sum=AddFunction(x,y);
cout<<"x+y="<<sum<<endl;
int dum=JanFunction(x,y);
cout<<"x-y="<<dum<<endl;
getch();
return 0;
}
这样就OK了
// TestDll.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
extern "C" __declspec( dllexport ) int AddFunction(int x, int y);
extern "C" __declspec( dllexport ) int JanFunction(int x, int y);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int AddFunction(int x, int y)
{
return x+y;
}
int JanFunction(int x,int y)
{
return x-y;
}
2.如何调用
#include <iostream>
#include <conio.h>
using namespace std;
extern "C" __declspec(dllimport) int AddFunction(int x, int y);
extern "C" __declspec(dllimport) int JanFunction(int x, int y);
int main(void)
{
int x;
int y;
cout<<"请输入X的值:";
cin>>x;
cout<<"请输入Y的值:";
cin>>y;
int sum=AddFunction(x,y);
cout<<"x+y="<<sum<<endl;
int dum=JanFunction(x,y);
cout<<"x-y="<<dum<<endl;
getch();
return 0;
}
这样就OK了
- 如何书写动态连接库
- MFC如何使用动态连接库DLL
- oracle存储过程如何定义,动态判断条件sql如何书写
- linux下静态库、动态库编译及makefile书写
- 在linux下如何制作自己的动态连接库
- 如何在Qt中写自己的动态连接库
- 如何书写概要设计
- 如何书写Use Case
- 如何书写Use Case
- 我是如何书写SQL
- 如何书写Use Case
- 如何书写make file
- 如何书写css 注释
- 如何书写Openstack命令行
- 如何书写UserCase
- ADO连接字符串的书写
- jquery操作连接式书写
- mybatis动态sql的书写
- ASP.NET Event Validation
- 使用Tomcat+Myeclipse搭建J2EE开发平台
- C#学习总结
- WEB标准
- VPN突破校园网访问屏障 实现信息共享
- 如何书写动态连接库
- 如何才能成为一名真正的Web程序员
- Evil搬迁至博客园
- SOS。。急救。。严重急救
- 文件内容读取
- MVC
- 这才是我们的生活!!!
- 尽可能使用 const
- 还原卡的热键