【发布时间】:2012-10-05 10:30:39
【问题描述】:
我想使用来自WindowsCodecs.dll 的函数,但 MinGW 的 WinAPI 标头以及导入库不完整且缺失。考虑以下演示:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
// ---------- dummy declarations, because MinGW got no wincodec.h ----------
typedef REFGUID REFWICPixelFormatGUID;
typedef VOID IWICBitmapSource;
HRESULT WINAPI WICConvertBitmapSource(
REFWICPixelFormatGUID dstFormat,
IWICBitmapSource *pISrc,
IWICBitmapSource **ppIDst);
// -------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpLine, int nShow)
{
#ifdef LOAD_FROM_DLL
typedef HRESULT (WINAPI *PWICConvertBitmapSource)(
REFWICPixelFormatGUID, IWICBitmapSource *, IWICBitmapSource **);
HMODULE hDll = LoadLibrary("WindowsCodecs.dll");
PWICConvertBitmapSource pFunc =
(PWICConvertBitmapSource)GetProcAddress(hDll, "WICConvertBitmapSource");
printf("WICConvertBitmapSource: 0x%p.\n", pFunc);
pFunc(NULL, NULL, NULL);
FreeLibrary(hDll);
#else
WICConvertBitmapSource(NULL, NULL, NULL);
#endif
return 0;
}
当由gcc test.c -DLOAD_FROM_DEF 构建时,程序打印出函数的地址并正确终止。虽然,当从以下 def 链接到导入库时:
LIBRARY WindowsCodecs.dll
EXPORTS
WICConvertBitmapSource@12
,弹出这个错误:
The procedure entry point WICConvertBitmapSource@12 could
not be located in the dynamic link library WindowsCodecs.dll.
令人惊讶的是,如果我从源代码中删除 WICConvertBitmapSource 的声明并从 def 文件中删除 @12 的声明,程序链接并运行良好。
如何创建正确的导入库?
注意事项:我在 Windows 7 SP1 上运行 MinGW。我的 gcc 版本是 4.7.0,安装了 w32api 3.17。许多函数都会出现问题,例如GdiAlphaBlend 或SHCreateStreamOnFileEx。
【问题讨论】: