Click here to Skip to main content
15,885,839 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Global key press Pin
Valentinor14-Jul-18 10:58
Valentinor14-Jul-18 10:58 
QuestionOnDeviceChange dbcc_name length Pin
Member 138991789-Jul-18 4:34
Member 138991789-Jul-18 4:34 
GeneralRe: OnDeviceChange dbcc_name length Pin
Richard MacCutchan9-Jul-18 5:26
mveRichard MacCutchan9-Jul-18 5:26 
GeneralRe: OnDeviceChange dbcc_name length Pin
Member 138991789-Jul-18 20:37
Member 138991789-Jul-18 20:37 
GeneralRe: OnDeviceChange dbcc_name length Pin
Richard MacCutchan9-Jul-18 21:04
mveRichard MacCutchan9-Jul-18 21:04 
GeneralRe: OnDeviceChange dbcc_name length Pin
Member 138991789-Jul-18 21:06
Member 138991789-Jul-18 21:06 
SuggestionRe: OnDeviceChange dbcc_name length Pin
David Crow9-Jul-18 16:24
David Crow9-Jul-18 16:24 
AnswerRe: OnDeviceChange dbcc_name length Pin
Jochen Arndt9-Jul-18 22:57
professionalJochen Arndt9-Jul-18 22:57 
The handler is called multiple times for a single event with different parameters, and also upon specific device changes even when not registered. So you have to check always if the device type matches and cast then to the corresponding broadcast structure (because all structures have the common _DEV_BROADCAST_HDR | Microsoft Docs[^] header, casting can be done initially when checking for the matching type).

So your code should look like (based on your code snippet posted in the above sub thread):
C++
// FTDI_D2XX_Device Class GUID
// To be used with RegisterDeviceNotification()
/*static*/ const GUID CTesterDlg::GUID_DEVINTERFACE_FTDI_D2XX =
{ 0x219D0508, 0x57A8, 0x4FF5, { 0x97, 0xA1, 0xBD, 0x86, 0x58, 0x7C, 0x6C, 0x7E }};

BOOL CTesterDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwPtrData)
{
    BOOL bReturn = CWnd::OnDeviceChange(nEventType, dwPtrData);

    PDEV_BROADCAST_DEVICEINTERFACE b = reinterpret_cast<PDEV_BROADCAST_DEVICEINTERFACE>(dwPtrData);
    // Check if dwPtrData is not NULL and for type BROADCAST_DEVICEINTERFACE.
    // When having registered an event with a GUID, that should be also compared here.
    // Comparing the GUID must be done when having registered multiple events.
    if (b && 
        b->dbcc_devicetype == DBT_DEVTYP_DEVICEINTERFACE &&
        b->dbcc_classguid == GUID_DEVINTERFACE_FTDI_D2XX)
    {
        //MessageBox(b->dbcc_name);

        // Handle events here
        // switch (nEventType)
    }
    return bReturn;
}
Regarding the encoding of the name, see _DEV_BROADCAST_DEVICEINTERFACE_A | Microsoft Docs[^]:
Quote:
When this structure is returned to a window through the WM_DEVICECHANGE message, the dbcc_name string is converted to ANSI as appropriate.
That means you will get an ANSI string with ANSI builds and a Unicode string with Unicode builds when having called RegisterDeviceNotification().

Portions of the above (like the GUID) are from some testing code I have written in 2012 where I have logged the name using
// Log using the full name from device change notification.
App()->Log(TRACE_LOG_DEBUG,
    _T("Device %s has been %s"), 
    pDev->dbcc_name,
    nEventType == DBT_DEVICEARRIVAL ? _T("added") : _T("removed"));
As far as I remember, the name was displayed properly .
GeneralRe: OnDeviceChange dbcc_name length Pin
Member 138991789-Jul-18 23:26
Member 138991789-Jul-18 23:26 
GeneralRe: OnDeviceChange dbcc_name length Pin
Jochen Arndt9-Jul-18 23:42
professionalJochen Arndt9-Jul-18 23:42 
GeneralRe: OnDeviceChange dbcc_name length Pin
Member 138991789-Jul-18 23:44
Member 138991789-Jul-18 23:44 
QuestionChanging Display gamma [SOLVED] Pin
Valentinor9-Jul-18 0:48
Valentinor9-Jul-18 0:48 
AnswerRe: Changing Display gamma Pin
Jochen Arndt9-Jul-18 1:05
professionalJochen Arndt9-Jul-18 1:05 
GeneralRe: Changing Display gamma Pin
Valentinor9-Jul-18 2:42
Valentinor9-Jul-18 2:42 
GeneralRe: Changing Display gamma Pin
Jochen Arndt9-Jul-18 2:59
professionalJochen Arndt9-Jul-18 2:59 
GeneralRe: Changing Display gamma Pin
Valentinor9-Jul-18 10:51
Valentinor9-Jul-18 10:51 
GeneralRe: Changing Display gamma Pin
Jochen Arndt9-Jul-18 21:00
professionalJochen Arndt9-Jul-18 21:00 
GeneralRe: Changing Display gamma Pin
Valentinor9-Jul-18 22:36
Valentinor9-Jul-18 22:36 
GeneralRe: Changing Display gamma Pin
Valentinor9-Jul-18 23:33
Valentinor9-Jul-18 23:33 
GeneralRe: Changing Display gamma Pin
Jochen Arndt9-Jul-18 23:50
professionalJochen Arndt9-Jul-18 23:50 
GeneralRe: Changing Display gamma Pin
Valentinor10-Jul-18 1:10
Valentinor10-Jul-18 1:10 
QuestionMouse Wheel scrolling support for MFC application. Pin
Member 139038189-Jul-18 0:01
Member 139038189-Jul-18 0:01 
AnswerRe: Mouse Wheel scrolling support for MFC application. Pin
Jochen Arndt9-Jul-18 0:52
professionalJochen Arndt9-Jul-18 0:52 
GeneralRe: Mouse Wheel scrolling support for MFC application. Pin
Member 139038189-Jul-18 19:16
Member 139038189-Jul-18 19:16 
GeneralRe: Mouse Wheel scrolling support for MFC application. Pin
Victor Nijegorodov9-Jul-18 20:37
Victor Nijegorodov9-Jul-18 20:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.