Skip to main content
GameDev.net gamedev.net
🔒 Locked

DDraw device enumeration callback never gets called

Started by Skylark Jan 23, 2007 at 2:33 PM 0 replies 1.4k views
Original Post
Skylark
Skylark
Hello, I'm writing an app that needs to run both on single and multiple monitor setups. I am trying to call DirectDrawEnumerateEx() to enumerate valid DDraw devices, and from that decide if I'm on a single or multiple monitor machine and create my DirectDraw objects from the GUIDs in the latter case. The problem is that my callback never gets called. Here's the relevant code snippets: The call to DirectDrawEnumerateEx:

    if (DirectDrawEnumerateEx(DDEnumCallback, NULL, 
                              DDENUM_ATTACHEDSECONDARYDEVICES | 
                              DDENUM_DETACHEDSECONDARYDEVICES | 
                              DDENUM_NONDISPLAYDEVICES) != DD_OK)
    {
	AfxMessageBox(_T("Failed to enumerate DirectDraw devices"));
    }
The callback function itself:

BOOL WINAPI DDEnumCallback(GUID FAR* lpGUID, LPWSTR lpDriverDescription, 
                           LPWSTR lpDriverName, LPVOID lpContext, HMONITOR hm)
{
    // Empty for now, to see if it's being called
    log_message("Enumeration callback called.");
    return DDENUMRET_OK;
}
The problem is that the messagebox is displayed (hence, the call to DirectDrawEnumerateEx returns something other than DD_OK) and the callback is never called. What could cause this? The DDENUM_ constants should be valid according to the docs, and I don't need anything in the lpContext parameter since my callback doesn't do anything (yet)... Any ideas? Thanks in advance, Skylark
-----------------------------Skylark-----------------------------
Skylark
Skylark
Hm, seems I fixed my own problem. For other peoples' information, it seems that the UNICODE version of DirectDrawEnumerateEx (DirectDrawEnumerateExW) does not call its callback, but the ANSI version (DirectDrawEnumerateExA) does. So I just changed my callback's parameters to normal strings:

BOOL WINAPI DDEnumCallback(GUID FAR* lpGUID, LPSTR lpDriverDescription,                            LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm){    // Empty for now, to see if it's being called    log_message("Enumeration callback called.");    return DDENUMRET_OK;}


and called the ANSI version explicitly:
    if (DirectDrawEnumerateExA(DDEnumCallback, &_devices,                                DDENUM_ATTACHEDSECONDARYDEVICES |                                DDENUM_DETACHEDSECONDARYDEVICES |                               DDENUM_NONDISPLAYDEVICES) != DD_OK)    {	AfxMessageBox(_T("Failed to enumerate DirectDraw devices"));    }


And that seems to work well. If any wizard can tell me why this happens (or if someone else got the UNICODE version to work), I would like to hear about it, but right now it's not that important since it works and I can just convert the strings if I need to (since I only enumerate once per run it isn't that bad).

Thanks,

Skylark
-----------------------------Skylark-----------------------------

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.