我写了一个进程内COM组件,用REGSVR32.EXE可注册,但我现在想在另一个程序中注册
请问用什么函数,CoRegisterClassObject()好象只能注册进程外组件,请问注册进程内组件用什么函数,最好有SAMPLE!谢谢!!!

解决方案 »

  1.   

    用LoadLibrary和GetProcAddress获得DllRegisterServer函数,调用就OK
      

  2.   

    抄了另一个贴子的代码,看上去好像是:
    borz(COM COM 给我感觉) (  ) 信誉:100  2002-07-23 17:48:00  得分:0  
     
     
      BOOL CBridgeApp::RegisterCOM(CString file,BOOL reg)
    {
    CString error,title;
    title.Format(_T("Load '%s'"),file);
    HINSTANCE hDll = LoadLibrary(file);
    if(!hDll)
    {
    if(reg)
    bp4_SysError(GetLastError(),title);
    return FALSE;
    }
    REG_FUNC lpRegFunc;
    BOOL ok=FALSE;
    //·Ç³£ÖØÒª
    HRESULT hr = CoInitialize(NULL);
    if(!SUCCEEDED(hr))
    {
    if(reg)
    bp4_SysError(GetLastError(),title);
    return FALSE;
    }
    if(reg)
    lpRegFunc = (REG_FUNC)GetProcAddress((HMODULE)hDll,"DllRegisterServer");
    else
    lpRegFunc = (REG_FUNC)GetProcAddress((HMODULE)hDll,"DllUnregisterServer");
    if(lpRegFunc)
    hr = (*lpRegFunc)();//-2147352567
    ok = lpRegFunc!=NULL && SUCCEEDED(hr);
    if(!ok)
    {
    if(reg)
    bp4_SysError(GetLastError(),title);
    }
    FreeLibrary(hDll);
    return ok;
    }
      
     
    另外:直接在程序中运行regsvr32 -s "需要注册的组件全路径"即可。