Win32调用大漠插件dm.dll教程

大漠插件:下载地址

提示:必须以管理员身份运行,否则regsvr32.exe dm.dll 会失败。

一、首先在stdafx.h中加入下列代码导入dm.dll

#import "dm.dll" no_namespace

二、win32中,在应用程序初始化处插入这段代码

	WinExec("regsvr32.exe dm.dll /s", SW_HIDE);
	CoInitialize(NULL);
	CLSID clsid;
	CLSIDFromProgID(OLESTR("dm.dmsoft"), &clsid);
	Idmsoft* dme;
	CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,__uuidof(Idmsoft), (LPVOID*)&dme);

简单的调用代码为:

	dme->KeyDown('A');
	dme->MoveTo(100, 100);

三、MFC中

        1、在App::InitInstance函数中如下:

	WinExec("regsvr32.exe dm.dll /s", SW_HIDE);
	CoInitialize(NULL);

        2、在App::ExitInstance函数中如下:

	CoUninitialize();
        3、在对话框的初始化函数中:

	CLSID clsid;
	CLSIDFromProgID(OLESTR("dm.dmsoft"), &clsid);
	CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(Idmsoft), (LPVOID*)&dme);
        4、在对话框类中添加一个成员变量:

	Idmsoft* dme;
        5、调用方法如下:

	dme->MoveTo(100, 100);
	dme->LeftClick();

        6、常用的循环找图、找色、找字的函数封装如下:

BOOL findBmp(LPCSTR bmp, CPoint & pt, double timeout) {
	VARIANT x, y;
	time_t t_start, t_end;
	time(&t_start);

	while (true)
	{
		dme->FindPic(0,0,2000,2000,bmp,"000000",0.9,0,&x,&y);
		if (x.intVal > 0 && y.intVal > 0) {
			pt.x = x.intVal;
			pt.y = y.intVal;
			return TRUE;
		}
		// 判断是否超时
		time(&t_end);
		if (timeout < difftime(t_end, t_start)) {
			pt.x = 0;
			pt.y = 0;
			return FALSE;
		}
		Sleep(50);
	}
}
BOOL findColor(LPCSTR color, CPoint & pt, double timeout) {
	VARIANT x, y;
	time_t t_start, t_end;
	time(&t_start);

	while (true)
	{
		dme->FindColor(0, 0, 2000, 2000, color, 0.9, 0, &x, &y);
		if (x.intVal > 0 && y.intVal > 0) {
			pt.x = x.intVal;
			pt.y = y.intVal;
			return TRUE;
		}
		// 判断是否超时
		time(&t_end);
		if (timeout < difftime(t_end, t_start)) {
			pt.x = 0;
			pt.y = 0;
			return FALSE;
		}
		Sleep(50);
	}
}
BOOL findStr(LPCSTR str, LPCSTR color, CPoint & pt, double timeout) {
	VARIANT x, y;
	time_t t_start, t_end;
	time(&t_start);

	while (true)
	{
		dme->FindStr(0, 0, 2000, 2000, str, color, 0.9, &x, &y);
		if (x.intVal > 0 && y.intVal > 0) {
			pt.x = x.intVal;
			pt.y = y.intVal;
			return TRUE;
		}
		// 判断是否超时
		time(&t_end);
		if (timeout < difftime(t_end, t_start)) {
			pt.x = 0;
			pt.y = 0;
			return FALSE;
		}
		Sleep(50);
	}
}








你可能感兴趣的:(CC++)