gpt4 book ai didi

c++ - GetProcAddress 无法获取 Void pascal Myfunction(BOOL) 形式的地址

转载 作者:行者123 更新时间:2023-11-28 03:41:36 24 4
gpt4 key购买 nike

我有 MyDll.dll,我想访问其函数 Myfunction,其形式为:

Void pascal Myfunction(BOOL);

这是我的代码:

#include "stdafx.h"
#include "iostream"
#include "windows.h"
using namespace std;
void calldll();

extern "C" __declspec(dllexport) void Myfunction(BOOL);

void calldll()
{
HINSTANCE hDll;
DWORD dwErrorCode=0;
LoadMe=LoadLibrary(_T("MyDll.dll"));


if(hDll!=NULL)
{
cout<<"\n DLL loaded successfully \n";
}

else
cout<<"\n Unable to load DLL \n";

Myfunction sp1=(Myfunction)GetProcAddress(hDll,"Myfunction");


if(sp1!=NULL)
{
cout<<"\n Process loaded successfully \n";
}
else
{
cout<<"\n Unable to load Process \n";

}


FreeLibrary(hDll);

}

报错如下:

1.syntax error : missing ';' before identifier 'sp1'

2.'sp1' : undeclared identifier

3.syntax error : missing ';' before identifier 'GetProcAddress'

我不明白。任何人都可以在这方面帮助我。

最佳答案

您需要声明一个变量,该变量是指向返回 void 并接受 BOOL 参数的函数的指针:

typedef void (pascal *MYFUNCTION_PTR)(BOOL);

MYFUNCTION_PTR fp = (MYFUNCTION_PTR)GetProcAddress(hDll,"Myfunction");

例如:

#include <stdafx.h>
#include <iostream>
#include <windows.h>

void calldll();

void calldll()
{
typedef void (pascal *MYFUNCTION_PTR)(BOOL);
HINSTANCE hDll;

hDll = LoadLibrary(_T("MyDll.dll"));

if(hDll!=NULL)
{
cout<<"\n DLL loaded successfully \n";

MYFUNCTION_PTR sp1=(MYFUNCTION_PTR)GetProcAddress(hDll,"Myfunction");

if(sp1!=NULL)
{
cout<<"\n Process loaded successfully \n";
}
else
{
cout<<"\n Unable to locate function: " << GetLastError() << \n";
}

FreeLibrary(hDll);
}
else
{
cout<<"\n Unable to load DLL \n";
}

}

关于c++ - GetProcAddress 无法获取 Void pascal Myfunction(BOOL) 形式的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9002580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com