gpt4 book ai didi

c++ - GetProcAddress 失败

转载 作者:行者123 更新时间:2023-11-30 05:02:58 26 4
gpt4 key购买 nike

<分区>

我在动态库中有一个函数,如下所示:

namespace Dll {
int MyDll::getQ() {
srand(time(0));
int q = rand();
while (!isPrime(q) || q < 100) {
q = rand();
}
return q;
}
}

.h 文件中的函数 getQ():

#ifdef _EXPORT
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif

namespace Dll
{
class MyDll
{
public:
static DLL_EXPORT int __stdcall getQ();
}
}

最后 LoadLibrary 来自另一个 consoleApp 的和平代码:

typedef int(__stdcall *CUSTOM_FUNCTION)();
int main()
{

HINSTANCE hinstance;
CUSTOM_FUNCTION proccAddress;
BOOL freeLibrarySuccess;
BOOL proccAddressSuccess = FALSE;
int result;

hinstance = LoadLibrary(TEXT("Dll.dll"));
if (hinstance != NULL)
{
proccAddress = (CUSTOM_FUNCTION)GetProcAddress(hinstance, "getQ");
if (proccAddress != NULL)
{
proccAddressSuccess = TRUE;
result = (*proccAddress)();
printf("function called\n");
printf("%d", result);
}
freeLibrarySuccess = FreeLibrary(hinstance);
}

if (!hinstance)
printf("Unable to call the dll\n");

if (!proccAddressSuccess)
printf("Unable to call the function\n");
}

所以我多次尝试修复此问题,但总是出现“无法调用该函数”。代码连接到库,因此问题出在函数附近。如果有人指出我的错误,我将不胜感激。

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