BOOL (WINAPI *gmse)(LPMEMORYSTATUSEX) = GetProcAddress(
kernel32, "GlobalMemoryStatusEx");
Run Code Online (Sandbox Code Playgroud)
这是一个.cpp文件.在编译上面的代码时,我收到以下错误.
error C2440: 'initializing' : cannot convert from 'FARPROC' to 'BOOL (__cdecl *)(LPMEMORYSTATUSEX)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚我应该将该GetProcAddress
函数转换为什么.有人可以指点我正确的方向吗?
谢谢
您需要将其强制转换为函数指针类型.要simplfy,请使用a typedef
作为函数指针类型:
typedef BOOL (WINAPI *gmse_t)(LPMEMORYSTATUSEX);
gmse_t gmse = (gmse_t)GetProcAddress(kernel32, "GlobalMemoryStatusEx");
Run Code Online (Sandbox Code Playgroud)
GetProcAddress()
MSDN上的参考页面提供了示例代码.