0

我想使用来自 的函数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从源文件和@12def 文件中删除声明,程序链接并运行良好。

如何创建正确的导入库?

注意:我在 Windows 7 SP1 上运行 MinGW。我的 gcc 版本是 4.7.0,安装了 w32api 3.17。许多函数都会出现问题,例如GdiAlphaBlendSHCreateStreamOnFileEx

4

1 回答 1

0

导入库应该是用--kill-at标志创建的,像这样:

dlltool --kill-at -D WindowsCodecs.dll -d WindowsCodecs.def -l libwindowscodecs.a

这篇文章为我澄清了一切:http ://wyw.dcweb.cn/stdcall.htm

于 2012-10-15T14:24:12.157 回答