Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing GUIDs

Tags:

guid

winapi

I'm trying to capture an event and reference a GUID to see which event it is. The code is below:

DWORD WINAPI AvisionEventProc(LPVOID lpParam){
    //HANDLE hEvent = * (HANDLE *) lpParam;   // This thread's read event
    STINOTIFY pStiNotify;

    if (debug){
        wprintf(L"Avision Event\n");
    }
    while(true){
        WaitForSingleObject(hAvisionEvent, INFINITE);
        wprintf(L"Event");
        pStiDevice->GetLastNotificationData(&pStiNotify);
        if (pStiNotify.guidNotificationCode == GUID_STIUserDefined1){
            wprintf(L"User defined 1");
        }else if (pStiNotify.guidNotificationCode == GUID_STIUserDefined2){
            wprintf(L"User defined 2");
        }else if (pStiNotify.guidNotificationCode == GUID_STIUserDefined3){
            wprintf(L"User defined 3");
        }

        ResetEvent(hAvisionEvent);
    }
    return 1;
}

This compiles just fine but I get the errors below when linking:

1>sti.obj : error LNK2001: unresolved external symbol _GUID_STIUserDefined3
1>sti.obj : error LNK2001: unresolved external symbol _GUID_STIUserDefined2
1>sti.obj : error LNK2001: unresolved external symbol _GUID_STIUserDefined1

The strange thing is that sti.h is linked in as I am pulling other constants from it. I did notice by the GUID decleration the following:

#if defined( _WIN32 ) && !defined( _NO_COM)

/*
 * Class IID's
 */

// B323F8E0-2E68-11D0-90EA-00AA0060F86C
DEFINE_GUID(CLSID_Sti, 0xB323F8E0L, 0x2E68, 0x11D0, 0x90, 0xEA, 0x00, 0xAA, 0x00, 0x60, 0xF8, 0x6C);

/*
 * Interface IID's
 */

// {641BD880-2DC8-11D0-90EA-00AA0060F86C}
DEFINE_GUID(IID_IStillImageW, 0x641BD880L, 0x2DC8, 0x11D0, 0x90, 0xEA, 0x00, 0xAA, 0x00, 0x60, 0xF8, 0x6C);

<snip>

/*
 * Standard event GUIDs
 */

// {740D9EE6-70F1-11d1-AD10-00A02438AD48}
DEFINE_GUID(GUID_DeviceArrivedLaunch, 0x740d9ee6, 0x70f1, 0x11d1, 0xad, 0x10, 0x0, 0xa0, 0x24, 0x38, 0xad, 0x48);

<snip>

#endif

Does the "if defined" line stop the GUIDs being referenced (I am writing a win32 console app) or is there something more fundamental I have wrong here to do with a lack of understanding on GUIDs?

Thanks, in advance for your help.

Cheers,

Neil

like image 467
Neil Benn Avatar asked Jun 11 '12 13:06

Neil Benn


1 Answers

The DEFINE_GUID macro either defines a named GUID as a static, or just does a forward declaration to actually be done somewhere else, depending on if #include <initguid.h> has been previously declared. Your code perhaps only have the latter, and the symbols don't have actual initialization within the project.

See:

  • How to avoid error "LNK2001 unresolved external" by using DEFINE_GUID
  • INITGUID: An Explanation
  • How does the DEFINE_GUID macro work? - at the bottom of the page
like image 113
Roman R. Avatar answered Sep 28 '22 06:09

Roman R.