Question

I'd like to use a function from WindowsCodecs.dll, but MinGW has incomplete and missing WinAPI headers, as well as import libraries. Consider the following demo:

#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;
}

When built by gcc test.c -DLOAD_FROM_DEF, the program prints address of the function and terminates correctly. Although, when linked against the import library from the following def:

LIBRARY WindowsCodecs.dll
EXPORTS
    WICConvertBitmapSource@12

, this error pops out:

The procedure entry point WICConvertBitmapSource@12 could
not be located in the dynamic link library WindowsCodecs.dll.

Surprisingly enough, if I remove the declaration of WICConvertBitmapSource from the source and @12 from def file, the program links and runs fine.

How can I create a correct import library?

Notes: I'm running MinGW on Windows 7 SP1. My gcc version is 4.7.0 with w32api 3.17 installed. The problem appears with many functions, like GdiAlphaBlend, or SHCreateStreamOnFileEx.

Was it helpful?

Solution

The import library should've been created with --kill-at flag, like this:

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

This article clarified everything for me: http://wyw.dcweb.cn/stdcall.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top