网上搜了下可以用DllRegisterServer这个函数,可是这个函数怎么用呢?
  谢高人指点

解决方案 »

  1.   

    孙鑫的C++视频中有怎么注册dll的,好像是调用一下这个函数吧
      

  2.   


    同意.
    regsvr32 c:\mycom.dll
    regsvr32 /u c:\mycom.dll
      

  3.   

    做成com组件形式的dll就会有DllRegisterServer这个接口来注册
      

  4.   

    HINSTANCE hLib = LoadLibrary("D:\\codes\\msg_com_p\\FullTunnelControl.dll");
    if(hLib == NULL)
    {
       AfxMessageBox("加载DLL失败!");
      return;
    }FARPROC lpDllEntryPoint;
    lpDllEntryPoint = GetProcAddress(hLib, "DllRegisterServer");
    if(lpDllEntryPoint != NULL)
    {
      if(FAILED((*lpDllEntryPoint)()))
      {
        AfxMessageBox("调用DllRegisterServer失败");
        FreeLibrary(hLib);
        return;
      };
      AfxMessageBox("注册成功");
    }
    else
      AfxMessageBox("调用DllRegisterServer失败");
    FreeLibrary(hLib);
      

  5.   

    PROCESS_INFORMATION ProcessInfo;
        STARTUPINFO StartupInfo;
        ZeroMemory(&StartupInfo,sizeof(StartupInfo));
        StartupInfo.cb = sizeof StartupInfo;    _tcscat(path, _T("\\Test.dll\" /s"));//path:Test.dll的目录,目录有空格要加引号“C:\Program Files\Test.dll”
        TCHAR szPath[MAX_PATH]={0};
        _tcscpy(szPath,_T("regsvr32.exe \""));
        _tcscat(szPath,path);
        if(CreateProcess(NULL,szPath,NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo,&ProcessInfo) )
        {        //注册成功的话,等待注册完成
            WaitForSingleObject(ProcessInfo.hProcess,INFINITE); 
            CloseHandle(ProcessInfo.hThread);
            CloseHandle(ProcessInfo.hProcess);
        }
      

  6.   

    它只是一个dll的导出函数,用来写一些注册信息STDAPI DllRegisterServer()
    {
    HKEY  hCLSIDKey = NULL, hInProcSvrKey = NULL;
    LONG  lRet;
    TCHAR szModulePath [MAX_PATH];
    TCHAR szClassDescription[] = _T("SimpleMsgBox class");
    TCHAR szThreadingModel[]   = _T("Apartment");__try
        {
        // Create a key under CLSID for our COM server.    lRet = RegCreateKeyEx ( HKEY_CLASSES_ROOT, _T("CLSID\\{7D51904E-1645-4a8c-BDE0-0F4A44FC38C4}"),
                                0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE | KEY_CREATE_SUB_KEY,
                                NULL, &hCLSIDKey, NULL );
        
        if ( ERROR_SUCCESS != lRet ) 
            return HRESULT_FROM_WIN32(lRet);    // The default value of the key is a human-readable description of the coclass.    lRet = RegSetValueEx ( hCLSIDKey, NULL, 0, REG_SZ, (const BYTE*) szClassDescription,
                               sizeof(szClassDescription) );    if ( ERROR_SUCCESS != lRet )
            return HRESULT_FROM_WIN32(lRet);
        
        // Create the InProcServer32 key, which holds info about our coclass.    lRet = RegCreateKeyEx ( hCLSIDKey, _T("InProcServer32"), 0, NULL, REG_OPTION_NON_VOLATILE,
                                KEY_SET_VALUE, NULL, &hInProcSvrKey, NULL );    if ( ERROR_SUCCESS != lRet )
            return HRESULT_FROM_WIN32(lRet);    // The default value of the InProcServer32 key holds the full path to our DLL.    GetModuleFileName ( g_hinstThisDll, szModulePath, MAX_PATH );    lRet = RegSetValueEx ( hInProcSvrKey, NULL, 0, REG_SZ, (const BYTE*) szModulePath, 
                               sizeof(TCHAR) * (lstrlen(szModulePath)+1) );    if ( ERROR_SUCCESS != lRet )
            return HRESULT_FROM_WIN32(lRet);    // The ThreadingModel value tells COM how it should handle threads in our DLL.
        // The concept of apartments is beyond the scope of this article, but for
        // simple, single-threaded DLLs, use Apartment.    lRet = RegSetValueEx ( hInProcSvrKey, _T("ThreadingModel"), 0, REG_SZ,
                               (const BYTE*) szThreadingModel, 
                               sizeof(szThreadingModel) );    if ( ERROR_SUCCESS != lRet )
            return HRESULT_FROM_WIN32(lRet);
        }   
    __finally
        {
        if ( NULL != hCLSIDKey )
            RegCloseKey ( hCLSIDKey );    if ( NULL != hInProcSvrKey )
            RegCloseKey ( hInProcSvrKey );
        }    return S_OK;
    }