#ifndef BASE_H
#define BASE_H
#include <iostream>
#include "Debug\dm.tlh"
int find_pic(long x, long y, long x1, long y1, _bstr_t path, double sim, VARIANT* intX, VARIANT* intY);
#endif
#include "base.h"
extern Idmsoft* dm;//因为这个时注册在main.c中,需要用extern声明一下
using namespace std;
/*
功能: 查找屏幕中的图片
参数:
x, y, x1, y1: 屏幕坐标
path: 图片路径
sim: 图片精度
intX: 一个数据结构,如果想要获取坐标点则需要 intX->boolVal
intY: 一个数据结构,如果想要获取坐标点则需要 intY->boolVal
返回值:
0: 表示没找到
1: 表示找到了
*/
int find_pic(long x, long y, long x1, long y1, _bstr_t path, double sim, VARIANT* intX, VARIANT* intY)
{
int ret = 0;
long dm_ret = dm->FindPic(x, y, x1, y1, path, "000000", sim, 0, intX, intY);
if (intX->boolVal > 0 && intY->boolVal > 0)
{
//cout << "找到了" << endl;
//cout << intX.boolVal << endl << intY.boolVal << endl;
ret = 1;
}
else
{
//cout << "没找到了" << endl;
ret = 0;
}
return ret;
}
测试代码:
#include <iostream>
#include "Debug\dm.tlh"
#include "base.h"
using namespace std;
Idmsoft* dm;
Idmsoft* GetDmObject()
{
Idmsoft* m_dm = NULL;
bool m_bInit = false;
//直接加载dll创建对象,避免进行注册文件
typedef HRESULT(_stdcall* pfnGCO)(REFCLSID, REFIID, void**);
pfnGCO fnGCO = NULL;
HINSTANCE hdllInst = LoadLibrary("dm.dll");
fnGCO = (pfnGCO)GetProcAddress(hdllInst, "DllGetClassObject");
if (fnGCO != 0)
{
IClassFactory* pcf = NULL;
HRESULT hr = (fnGCO)(__uuidof(dmsoft), IID_IClassFactory, (void**)&pcf);
if (SUCCEEDED(hr) && (pcf != NULL))
{
hr = pcf->CreateInstance(NULL, __uuidof(Idmsoft), (void**)&m_dm);
if ((SUCCEEDED(hr) && (m_dm != NULL)) == FALSE)
return NULL;
}
pcf->Release();
m_bInit = true;
}
else
m_bInit = false;
return m_dm;
}
int main()
{
dm = GetDmObject();
cout << dm->Ver() << endl;
//dm->Reg(L"注册码", L"dass");//收费版本需要注册后才能使用
/*6.1538版本修改内存可直接调用*/
DWORD pid = GetCurrentProcessId();
int handle = (int)GetModuleHandle("dm.dll");
cout << "进程ID:" << pid << "模块句柄:" << handle << endl;
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
int value = 1;
bool is = WriteProcessMemory(hProcess, LPVOID(handle + 1078240), &value, 1, NULL);
/*调用大漠插件内函数*/
dm->MoveTo(0, 0);
dm->delay(3000);
dm->KeyPressStr("1234567890", 10);
VARIANT intX, intY;
if (find_pic(0, 0, 2000, 2000, "D:/大漠插件/DM/picture/test/1.bmp", 0.9, &intX, &intY) == 1)
{
cout << "找到了" << endl;
cout << intX.boolVal << ", " << intY.boolVal << endl;
}
else
{
cout << "没找到" << endl;
}
while (1);
return 0;
}