COM相關操作(C#)

來源:互聯網
上載者:User

標籤:

  • 檢查dll是否已經註冊

檢查是否已經註冊的代碼為:

 

   #region Is dll register    public bool IsDllRegistered()    {      bool reg=true;      RegistryKey rk=Registry.ClassesRoot.OpenSubKey("CLSID\\{AC53EFE4-94A7-47E6-BBFC-E9B9CF322299}");      if(rk==null)      {        MessageBox.Show("未註冊");        reg=false;      }      else      {        MessageBox.Show("登入");      }      return reg;    }    #endregion

 

其中GUID串{AC53EFE4-94A7-47E6-BBFC-E9B9CF322299}為註冊dll的Class ID。註冊表搜尋了半天沒有找到,可通過一個名叫RegDllView的小工具進行尋找。

 

  • 註冊dll控制項
    #region Open dwg file    [DllImport(@"../ja-JP/com/DwgViewX.dll")]    private static extern int DllRegisterServer();    private void OpenDwgFile(string savePath)    {      if(!IsDllRegistered())      {        int i = DllRegisterServer();        if (i >= 0)        {          /*           * Inoke special function to open dwg file           * */                  }        else        {          /*           * Register failed and open dwg with CAD           * */          System.Diagnostics.Process.Start(savePath);        }      }    }    #endregion

 

 

其中@"../ja-JP/com/DwgViewX.dll"是你的dll儲存的相對路徑。注意需要引用名空間:

 

using System.Runtime.InteropServices;using Microsoft.Win32;

 

COM相關操作(C#)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.