Visual C++免注册调用大漠插件

1、 注册调用

一、下载大漠插件,并注册到系统
下载地址:https://pan.baidu.com/s/1nCc5jB4izcp_I2J6JLqEKA
提取码:tf1f

二、创建一个空项目
添加main.cppmain.h,导入插件中的obj.cppobj.h文件
三、修改obj.cpp中引入的头文件
#include "stdafx.h"去除
#include "main.h要放前面"
在这里插入图片描述

三、更改运行库为“多线程(/MT)”
在这里插入图片描述

四、main.h

#ifndef MAIN_H
#define MAIN_H

#include <afx.h>
#include <afxwin.h>
#include <afxext.h>
#include <atlbase.h>
#include <atlstr.h>
#include <afxdtctl.h>
#include <afxcmn.h>
#include <afxdisp.h>
#include "obj.h"

#endif

五、main.cpp

#include "main.h"
#include "obj.h"
#include <iostream>

using namespace std;



int main()
{
    
    
	

	CoInitializeEx(NULL, 0);//初始化
	AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0);
	dmsoft* pDm = new dmsoft;
	pDm->MoveTo(0, 0);	
	pDm->RunApp(L"notepad", 1);
	pDm->delay(3000);
	pDm->KeyPressStr(L"123456789011", 20);
	wcout << (LPCTSTR)(pDm->Ver())<< endl;
	
	return 0;

}

2、免注册调用

一、创建一个空项目
在这里插入图片描述
在这里插入图片描述
二、添加main.cpp

#include <iostream>
#import "dm.dll" no_namespace

int main()
{
    
    
	return 0;
}

三、添加dm.dll
在这里插入图片描述
四、生成解决方案
在这里插入图片描述
五、编译成功后会生成dm.tlhdm.tli文件
在这里插入图片描述
六、修改dm.tlh

修改前
在这里插入图片描述
修改后
在这里插入图片描述
七、main.cpp

#include <iostream>
//#import "dm.dll" no_namespace
#include "Debug\dm.tlh"
using namespace std;

Idmsoft* GetDmObject()
{
    
    
	Idmsoft* m_dm = NULL;
	bool m_bInit = false;
	//直接加载dll创建对象,避免进行注册文件
	typedef HRESULT(_stdcall* pfnGCO)(REFCLSID, REFIID, void**);
	pfnGCO fnGCO = NULL;
	HINSTANCE hdllInst = LoadLibrary(L"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()
{
    
    
	Idmsoft* pDm = GetDmObject();
	cout << pDm->Ver() << endl;
	//dm->Reg(L"注册码", L"dass");//收费版本需要注册后才能使用
	/*6.1538版本修改内存可直接调用*/
	DWORD pid = GetCurrentProcessId();
	int handle = (int)GetModuleHandle(L"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);
	/*调用大漠插件内函数*/
	pDm->MoveTo(0, 0);
	pDm->delay(3000);	
	pDm->KeyPressStr("1234567890", 10);

	return 0;
}

猜你喜欢

转载自blog.csdn.net/chuhe163/article/details/112745590