首页 | 新闻 | 交流 | 问吧 | 文档 | 手册 | 下载 | 博客

Visual C++ 2011-5-30

作者:  时间: 2011-06-15

 

一.UNREFERENCED_PARAMETER的用处

http://blog.csdn.net/liuchanghe/archive/2006/12/31/1471302.aspx

二.RegCopyTree(Windows Vista+)

Copies the specified registry key, along with its values and subkeys, to the specified destination key.


HRESULT CTBSCFCT::CopyRegTree(/*from*/ HKEY hKeyFrom, LPCWSTR lpSubKeyFrom, /*to*/ HKEY hKeyTo, LPCWSTR lpSubKeyTo)
{
    HRESULT hr = S_FALSE;
    HKEY hOpenKeyFrom = NULL,hOpenKeyTo = NULL;
    DWORD dwDisp = 0;
    hr = ::RegCreateKeyEx(hKeyTo,
        lpSubKeyTo,
        0,
        NULL,
        REG_OPTION_NON_VOLATILE,
        KEY_ALL_ACCESS,
        NULL,
        &hOpenKeyTo,
        &dwDisp);
    if( hr != ERROR_SUCCESS)
    {
        hr = E_FAIL;
        goto Exit;
    }

    hr = ::RegOpenKey(hKeyFrom,lpSubKeyFrom,&hOpenKeyFrom);
    if( hr != ERROR_SUCCESS)
    {
        hr = E_FAIL;
        goto Exit;    
    }
    hr = ::RegCopyTree(hOpenKeyFrom,NULL,hOpenKeyTo);
    if( hr != ERROR_SUCCESS)
    {
        hr = E_FAIL;
        goto Exit;
    }

    hr = S_OK;
Exit:
    if(hOpenKeyTo)
    {
        ::RegCloseKey(hOpenKeyTo);
        hOpenKeyTo = NULL;
    }
    if(hOpenKeyFrom)
    {
        ::RegCloseKey(hOpenKeyFrom);
        hOpenKeyFrom = NULL;
    }
    return hr;
}

三. .rgs注册文件

http://blog.csdn.net/idiszerg/archive/2009/02/11/3875934.aspx

四.注册dll

class CAtlSafeArrayModule : public CAtlDllModuleT< CAtlSafeArrayModule >
{
public :
    DECLARE_LIBID(LIBID_AtlSafeArrayLib)
    DECLARE_REGISTRY_APPID_RESOURCEID(IDR_ATLSAFEARRAY, "{623C3042-B3D2-4F3E-856B-CC75B6CF7AF9}")
};

CAtlSafeArrayModule _AtlModule;


// DLL Entry Point
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
    hInstance;
    return _AtlModule.DllMain(dwReason, lpReserved); 
}


// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
    return _AtlModule.DllCanUnloadNow();
}


// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
    return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}


// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
    // registers object, typelib and all interfaces in typelib
    HRESULT hr = _AtlModule.DllRegisterServer();
    return hr;
}


// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
    HRESULT hr = _AtlModule.DllUnregisterServer();
    return hr;
}

五.注册Server(.exe)

class CServerDemoModule : public ATL::CAtlExeModuleT< CServerDemoModule >
    {
public :
    DECLARE_LIBID(LIBID_ServerDemoLib)
    DECLARE_REGISTRY_APPID_RESOURCEID(IDR_SERVERDEMO, "{4C612C8F-B76B-423C-B59D-20B6575BA8BD}")
    };

CServerDemoModule _AtlModule;



//
extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, 
                                LPTSTR /*lpCmdLine*/, int nShowCmd)
{
    return _AtlModule.WinMain(nShowCmd);
}