Domanda

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);
}
È stato utile?

Soluzione

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.

Altri suggerimenti

I think that's a documentation bug. It's been a long time since I used DirectDraw7, but I don't recall having to load it dynamically. It was just a method of the IDirectDraw7 interface and called like any other method.

Since DX9, ddraw.lib was completely removed from the SDK, so you need to call LoadLibrary/GetProcAddress to call DirectDrawCreate or DirectDrawEnumerate. Unfortunately MSDN got it wrong, and added the GetProcAddress remark to EVERY DirectDraw function, even the COM interfaces' methods.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top