相关疑难解决方法(0)

为什么GetProcAddress不起作用?

首先,我创建一个名为的简单dll SimpleDll.dll,其头文件:

// SimpleDll.h
#ifdef MYLIBAPI
#else
#define MYLIBAPI __declspec(dllimport)
#endif

MYLIBAPI int Add(int a. int b);
Run Code Online (Sandbox Code Playgroud)

其源代码:

// SimpleDll.c
#include <windows.h>

#define MYLIBAPI __declspec(dllexport)
#include "SimpleDll.h"    

int Add(int a, int b)
{
    return a + b;
}
Run Code Online (Sandbox Code Playgroud)

然后我在另一个项目中调用它,它工作正常:

// TestSimpleDll.c
#include "stdafx.h"
#include <windows.h>
#include "SimpleDll.h"

#pragma comment(lib, "SimpleDll.lib")

int _tmain(int argc, _TCHAR* argv[])
{
    printf("%d", Add(10, 30));    // Give the expected result 40
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,当我打电话GetProcAddress来获取它的地址时,它不起作用!

// TestSimpleDll2.c
#include "stdafx.h"
#include <windows.h>
#include "SimpleDll.h" …
Run Code Online (Sandbox Code Playgroud)

c++ windows winapi visual-studio name-decoration

5
推荐指数
1
解决办法
4840
查看次数

标签 统计

c++ ×1

name-decoration ×1

visual-studio ×1

winapi ×1

windows ×1