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()