日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

控件注册 - 利用资源文件将dll、ocx打包进exe文件(转)

發布時間:2023/12/2 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 控件注册 - 利用资源文件将dll、ocx打包进exe文件(转) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

很多時候自定義或者引用控件都需要注冊才能使用,但是如何使要注冊的dll或ocx打包到exe中,使用戶下載以后看到的只是一個exe,點擊直接運行呢?就像很多安全控件,如支付寶的aliedit.exe那樣。

?

????? 現在介紹一種使用資源文件,將dll、ocx打包進exe,點擊直接注冊的例子:

????? 首先,新建一個工程RegisterFile。? 新建文件夾Resource,里面添加需要注冊的ocx或dll。這里我添加的是dsoframer.ocx,并將其文件“屬性”中“生成操作”項的值改為“嵌入的資源”。

??????

????? 接下來,創建類Register.cs?? 里面只有一個函數RegisterDll()。?這里為省事,我把它放到了Program.cs里,同一命名空間下,效果是一樣的。????

?????

[c-sharp]?view plaincopy
  • using?System;??
  • using?System.Collections.Generic;??
  • using?System.Linq;??
  • using?System.Windows.Forms;??
  • ??
  • using?System.Diagnostics;??
  • ??
  • namespace?RegisterFile??
  • {??
  • ????static?class?Program??
  • ????{??
  • ????????///?<summary>??
  • ????????///?應用程序的主入口點。??
  • ????????///?</summary>??
  • ????????[STAThread]??
  • ????????static?void?Main()??
  • ????????{??
  • ????????????Application.EnableVisualStyles();??
  • ????????????Application.SetCompatibleTextRenderingDefault(false);??
  • ????????????Application.Run(new?frmMain());??
  • ????????}??
  • ????}??
  • ??
  • ??
  • ??
  • ????class?Register??
  • ????{??
  • ????????public?void?RegisterDll(string?strDll)??
  • ????????{??
  • ????????????Process?p?=?new?Process();??
  • ????????????p.StartInfo.FileName?=?"Regsvr32.exe";??
  • ??
  • ????????????p.StartInfo.Arguments?=?"?"?+?strDll;??
  • ????????????p.Start();??
  • ??
  • ????????????p.Close();??
  • ????????}??
  • ????}??
  • }??
  • ?

    ?????

    ????? 最后,在Form1_Load()中添加代碼:??

    ?????

    [c-sharp]?view plaincopy
  • //需要添加引用??
  • //using?System.IO;??
  • //using?System.Reflection;??
  • //using?System.Resources;??????????
  • ??
  • ??
  • ????????private?void?Form1_Load(object?sender,?EventArgs?e)??
  • ????????{??
  • ????????????this.Visible?=?false;??
  • ??
  • ????????????string?strPath?=?string.Empty;??
  • ????????????strPath?=?System.Environment.CurrentDirectory;??
  • ??
  • ??
  • ????????????Assembly?asm?=?Assembly.GetEntryAssembly();??
  • ????????????using?(Stream?stream?=?asm.GetManifestResourceStream("RegisterFile.Resource.dsoframer.ocx"))??
  • ????????????{??
  • ????????????????int?len?=?(int)stream.Length;??
  • ????????????????byte[]?byts?=?new?byte[len];??
  • ??
  • ????????????????stream.Read(byts,?0,?len);??
  • ????????????????stream.Close();??
  • ??
  • ????????????????using?(FileStream?fs?=?new?FileStream(Environment.GetFolderPath(Environment.SpecialFolder.System)?+?"//dsoframer.ocx",?FileMode.Create))??
  • ????????????????{??
  • ????????????????????fs.Write(byts,?0,?len);??
  • ????????????????}??
  • ????????????}??
  • ??
  • ??????????????
  • ??
  • ????????????Register?r?=?new?Register();??
  • ????????????r.RegisterDll("dsoframer.ocx");??
  • ??
  • ????????????this.Close();??
  • ????????}??
  • ?

    ?

    ?

    ?????注意:Stream stream = asm.GetManifestResourceStream("RegisterFile.Resource.dsoframer.ocx")中"RegisterFile.Resource.dsoframer.ocx"的取值為“命名空間”+ “文件夾” + “文件名稱”。

    轉載于:https://www.cnblogs.com/xyqCreator/archive/2012/07/17/2594670.html

    總結

    以上是生活随笔為你收集整理的控件注册 - 利用资源文件将dll、ocx打包进exe文件(转)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。