DLL 导入类

将LIB文件复制到testB文件夹里(textB与Debug和Release文件夹平级)

将DLL文件复制到Debug文件夹里(不复制编译能通过但不能运行)

头文件也复制到 lib 所在的文件夹下


空白win32 DLL工程中 新建CPP 和H

.h

#ifndef __JISUAN_0709B__  
#define __JISUAN_0709B__ _declspec(dllimport)  
#endif  

//#include <afxwin.h>
#include <Windows.h>	//这样win32 DLL工程也能用WINAPI
#include <stdio.h>

class __JISUAN_0709B__  student
{
public:
	void output(int x,int y);
};
.cpp

#define __JISUAN_0709B__ _declspec(dllexport)

#include "jisuan0709B.h"

void student::output(int x,int y)
{
	//返回调用者进程当前正在使用的那个窗口的句柄
	HWND hwnd=::GetForegroundWindow();
	//获取DC
	HDC hdc=::GetDC(hwnd);

	char buf[20];
	::memset(buf,0,20);
	::sprintf_s(buf,"x=%d,y=%d",x,y);

	//输出坐标
	::TextOutA(hdc,0,0,buf,strlen(buf));
	//释放DC
	::ReleaseDC(hwnd,hdc);
}
编译 生成lib  dll 还有.h 复制到测试程序相应的位置

在测试工程中

stdafx.h

#pragma comment (lib,"0709B.lib")  
#include "jisuan0709B.h"	//新加的  

dlg.cpp中

void Ctest0709BDlg::OnBnClickedButton1()
{
	// TODO: Add your control notification handler code here
	student A;<span style="white-space:pre">	</span>//使用从DLL 导入的类
	A.output(123,456);
}



风行者引领群雄者行风

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值