c++winapidlldirectxdirectdraw

DirectDraw get procedure address using GetProcAddress


As stated in the documentation for the IDirectDraw7::SetCooperativeLevel method, it states

You must use LoadLibrary to explicitly link to Ddraw.dll and then use GetProcAddress to access the SetCooperativeLevel method.

in the remarks. However when I attempt to do so (code below), it fails to work. Am I doing something wrong?

typedef HRESULT (*pSetCooperativeLevelFunc)(HWND, DWORD);
HMODULE ddrawLib = LoadLibrary(L"ddraw.dll");
pSetCooperativeLevelFunc SCL = (pSetCooperativeLevelFunc) GetProcAddress(
                                 ddrawLib,
                                 "SetCooperativeLevel"
                                 );

if (SCL == NULL) {
    // this happens
    int error = GetLastError(); // 127 (ERROR_PROC_NOT_FOUND)
    printf("Error getting SetCooperativeLevel function address: %i", error);
}

Solution

  • There is no exported SetCooperativeLevel function in ddraw.dll. Use DUMPBIN utility and check it yourself. You can get DirectDrawCreate/DirectDrawCreateEx and similar functions using GetProcAddress, but you can't extract individual methods of COM object.

    Article is quite ridiculous and doesn't make sense. Perhaps it was supposed to tell you to get DirectDrawCreate from ddraw.dll or something like that, but there's little reason to do that.

    Link with ddraw.lib, call DirectDrawCreate and access methods provided by IDirectDraw7 interface.

    P.S. If you aren't familiar with dumpbin, I'd suggest to learn at least basic usage of this utility.