dll文件中函数的调用(通过头文件和动态库文件dll)

版权声明:原创作品请注明出处: Ma_Hong_Kai CSDN https://blog.csdn.net/Ma_Hong_Kai/article/details/85016072

1、需要定影的dll动态库文件 比如 : FileEncryption.dll

2、需要该动态库的头文件 

头文件为  interface.h

#ifndef __INTERFACE_H__
#define __INTERFACE_H__
#ifndef __PUBLIC_H__
#include "public.h"
#endif

/*************************************************************************************
函数名称:StartingR
函数说明:通知***绑定给定进程,该进程应该是控制台的主进程,
		一旦调用了该函数,***拒绝执行相应
特别说明:
	调用该函数成功后,***
	
参数说明: 
	Pid:  要绑定程序的进程号,用StopingR停止绑定
	Password:   调用该接口的密码,
		
返回FALSE,失败,TRUE, 成功
*************************************************************************************/

BOOL StartingR(ULONG Pid, ULONG Password);

dll函数调用文件 DLLFunctionCall.cpp

#include "DLLFunctionCall.h" 

typedef BOOL (*pStartingR)(ULONG Pid, ULONG Password); // 指针函数
 
void dllFunctionCall()
{
    pStartingR dllStartingR;
    // 获取函数地址
	dllStartingR = (pStartingR)GetProcAddress(m_hInstLibrary, "StartingR");
	if (dllStartingR== NULL)
	{
		std::cout << "get StartingR function  address  fail" << std::endl;
	}
	else
	{
		std::cout << "get StartingRfunction address succeed" << std::endl;
	}
	if ( dllStartRelate(processid,Lpassword) == TRUE)
	{
		std::cout << "StartingR ok" << std::endl;
	}
	else
	{
		std::cout << "StartingR fail" << std::endl;
	}
}

头文件 DLLFunctionCall.h (部分头文件可能不需要)

#pragma  once

// 头文件
#include <stdio.h>
#include <tchar.h>

#include <Windows.h>
#include <tlhelp32.h>
#include <atlstr.h>

#include <iostream>
//, toolhelp.h

#include <WinNT.h>
#include "interface.h"

主文件  main.cpp

#include "DLLFunctionCall.h" 

int main()
{
    dllFunctionCall();
    system("pause");
}

猜你喜欢

转载自blog.csdn.net/Ma_Hong_Kai/article/details/85016072