« 料理鼠王(Ratatouille)--只要有心~ 人人都可以成為食神 | 回到主頁面 | links for 2007-08-06 »

August 06, 2007

Use VC8 create ATL Service will failed in CoInitialize


將此網頁加入【百度收藏】... 加入此網頁到【del.icio.us 書籤】 technorati

Use VC8 (Visual Studio 2005) to create project is more easy than VC6(VC98), but however we may not CoInitialize ATL service as well. It always happen failed since you use your API to CoInitialize this service. But it iswork if you use VC6 to create the ATL service. The root cause is the sercurity issue as follow:

http://msdn2.microsoft.com/en-us/library/xe2dxx5c(VS.80).aspx

class CATL_SERVERModule : public CAtlServiceModuleT< CATL_SERVERModule, IDS_SERVICENAME >
{
public :
    DECLARE_LIBID(LIBID_ATL_SERVERLib)
    DECLARE_REGISTRY_APPID_RESOURCEID(IDR_ATL_SERVER, "{C08654FF-A0F1-4CFD-8A09-93D4768BCF14}")
    HRESULT InitializeSecurity() throw()
    {
        // TODO : Call CoInitializeSecurity and provide the appropriate security settings for 
        // your service
        // Suggested - PKT Level Authentication, 
        // Impersonation Level of RPC_C_IMP_LEVEL_IDENTIFY 
        // and an appropiate Non NULL Security Descriptor.
        return S_OK;
    }
};

The problem is VC8 move the the security implement the base-class and you at-least implement one security check in this section of code. The easy way to implement it is copy code from VC6 as follow:

        // TODO : Call CoInitializeSecurity and provide the appropriate security settings for 
        // your service
        // Suggested - PKT Level Authentication, 
        // Impersonation Level of RPC_C_IMP_LEVEL_IDENTIFY 
        // and an appropiate Non NULL Security Descriptor.

            // This provides a NULL DACL which will allow access to everyone.
        CSecurityDescriptor sd;
        sd.InitializeFromThreadToken();
        hr = CoInitializeSecurity(sd, -1, NULL, NULL,
             RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);

        return S_OK;

Powered by Zoundry



VC6相關問題 / VS2005 (俗稱的VC8)相關問題

由 Evan 發表於 August 06, 2007 將此網頁加入【百度收藏】... 加入此網頁到【del.icio.us 書籤】 technorati
引用
本文的引用網址:


以下是前來引用的連結 'Use VC8 create ATL Service will failed in CoInitialize' 來自 Blog E
迴響
發表迴響









記住我的資訊?




(請輸入以下的驗證碼)