2014年7月12日 星期六

Windbg: How to implement .frame command.

There is the windbg command .frame

.frame (Set Local Context)

The .frame command specifies which local context (scope) is used to interpret local variables or displays the current local context.
.frame [/c] [/r] [FrameNumber] 

There is the function in the dbgeng.dll can help us to implement it.

IDebugSymbols3::SetScopeFrameByIndex method

2013年11月18日 星期一

CoInitializeSecurity call fails with error code RPC_E_TOO_LATE

In the VC++ MFC MDI, the  CoInitializeSecurity call fails with error code RPC_E_TOO_LATE

1. We can check (http://msdn.microsoft.com/en-us/library/windows/desktop/aa394603(v=vs.85).aspx) for WMI troubleshooting.

2. There is the example code in the http://support.microsoft.com/kb/948829

3. The code here (http://www.codeproject.com/Articles/216077/Making-Your-Cplusplus-Code-Robust) can help us solve the WMI execquery problem.

4. Please check http://msdn.microsoft.com/en-us/library/windows/desktop/aa393609(v=vs.85).aspx.  The key point is CoSetProxyBlanket function.

hres = CoSetProxyBlanket(
   pSvc,                        // Indicates the proxy to set
   RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
   RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
   NULL,                        // Server principal name 
   RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx 
   RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
   NULL,                        // client identity
   EOAC_NONE                    // proxy capabilities 
);

2013年11月13日 星期三

SetFont for CButton

About the SetFont of the CButton, there is a example in the http://support.microsoft.com/kb/85518/en-us.

class CMyAboutBox : public CDialog
{
   CFont m_font;

   public:
      // Constructor -- This code assumes a dialog box
      // template named "ABOUTDLG" in the application's .RC file.

      CMyAboutBox(CWnd* pParentWnd = NULL) :
         CModalDialog("ABOUTDLG", pParentWnd) {};

      BOOL OnInitDialog();
};

It will be failed, if you put the CFont m_font in the OnInitDialog()

2013年10月13日 星期日

windbg local mode study

It will call dbgeng!LocalLiveKernelTargetInfo::InitDriver and then create kldbgdrv.sys in the c:\Windows\System32 folder.

2013年10月5日 星期六

PCI address to Device manager device description

TCHAR buf[MAX_DEVICE_ID_LEN];  // (Dynamically size this instead?)

PTSTR DriverNameToDeviceDesc (UCHAR bn, UCHAR dn, UCHAR fn, BOOLEAN DeviceId)
{
HDEVINFO  hDevInfo;
    SP_DEVINFO_DATA  DeviceInfoData;
    DWORD  i;
BOOL r;
int j=0;


    //  Create  a  HDEVINFO  with  all  present  devices.      
hDevInfo  =  SetupDiGetClassDevs(NULL,
               0,  //  Enumerator
               0,
               DIGCF_PRESENT    |  DIGCF_ALLCLASSES  );
 
    if  (hDevInfo  ==  INVALID_HANDLE_VALUE)
    {
               //  Insert  error  handling  here.
               return  NULL;
    }
       
    //  Enumerate  through  all  devices  in  Set.
    DWORD  DataT;
    DWORD  buffersize  =  0;
    DeviceInfoData.cbSize  =  sizeof(SP_DEVINFO_DATA);
   
for  (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,
               &DeviceInfoData);i++)
    {
 
           if(SetupDiGetDeviceRegistryProperty(
                       hDevInfo,
                       &DeviceInfoData,
                       SPDRP_BUSNUMBER,
                       &DataT,
                       (PBYTE)buf,
                       MAX_DEVICE_ID_LEN,
                       &buffersize))
  {
  if(buffersize == 4 && (UCHAR) buf[0] == bn)
  {
   if(SetupDiGetDeviceRegistryProperty(
                       hDevInfo,
                       &DeviceInfoData,
                       SPDRP_ADDRESS,
                       &DataT,
                       (PBYTE)buf,
                       MAX_DEVICE_ID_LEN,
                       &buffersize))
{
if (buffersize == 4 && (UCHAR) buf[0] == fn && (UCHAR) buf[2] == dn)
{
if(SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
SPDRP_DEVICEDESC,
&DataT,
(PBYTE)buf,
MAX_DEVICE_ID_LEN,
&buffersize))
{
return buf;
}
else
{
SetupDiDestroyDeviceInfoList(hDevInfo);
return NULL;
}
}
}
}
  }
}
    //    Cleanup
    SetupDiDestroyDeviceInfoList(hDevInfo);  
    return  NULL;
}

2013年7月31日 星期三

About the GRID control for the VS MFC

I don't understand why MS don't try to provide a MFC GRID control.  We can try to make CListCtrl to be the Grid control style.  You can refer the MSDN document here (http://msdn.microsoft.com/en-us/library/ms364048(v=vs.80).aspx), but it's not easy.  Anyway, we can use the code (http://www.codeproject.com/Articles/8/MFC-Grid-control-2-27) in the codeproject to be the base and modify it.

2013年5月7日 星期二

Windows AHCI Link power management setting

1. Run Registry Editor (type "regedit" in the search field on the Start Menu).

2. Navigate to "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Power\PowerSettings\0012ee47-9041-4b5d-9b77-535fba8b1442\0b2d69d7-a2a1-449c-9680-f91c70521c60".

3. Change value "Attributes" to 2. At this step you won't have modified ANY functionality in Windows (except for a tiny detail in the power management USER interface), so it's 100% safe.

4. Reboot.

5. Now go to "Power Management" in Control Panel and click "Change plan settings" of your power plan, then click "Change advanced power settings".

6. Expand the "Hard Disk" settings tree. You'll see that now there is and ADDITIONAL setting: "AHCI Link Power Management - HIPM/DIPM". Expand this one.



--------------------------------------------------------------------------------------------------------

The default power setting for Balanced about ALPM (AC,DC).
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\0012ee47-9041-4b5d-9b77-535fba8b1442\0b2d69d7-a2a1-449c-9680-f91c70521c60\DefaultPowerSchemeValues\381b4222-f694-41f0-9685-ff5bb260df2e]
"ACSettingIndex"=dword:00000001
"DCSettingIndex"=dword:00000001