您好,登錄后才能下訂單哦!
環境:VS2010...WIN7系統
設置工程屬性:“生成”->?“為COM?Interop注冊”。
當然也可以為每個接口設置COM可見性,ComVisibleAttribute類提供了這樣的控制。
更改AssemblyInfo.cs……設置COM可見
//?將??ComVisible?設Θ?置?為a?false?使?此?程ì序ò集ˉ中D的?類え?型í
//?對??COM?組哩?件t不?可é見?。£如?果?需è要癮從洙?COM?訪?問ê此?程ì序ò集ˉ中D的?類え?型í,?
//?則ò將?該?類え?型í上?的??ComVisible?特?性?設Θ?置?為a?true。£
[assembly:?ComVisible(true)]
建立源碼
using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Runtime.InteropServices;
namespace?MyLib
{
????[ComVisible(true)]
????[Guid("2CBD3D76-35F1-4f9d-9C1B-9DBFEE412F77")]
????public?interface?IMyClass
????{
????????void?Initialize();
????????void?Dispose();
????????String?VC(String?path);
????}
????[ComVisible(true)]
????[Guid("EA2F140A-108F-47ae-BBD5-83EEE646CC0e")]
????[ProgId("MyLib.MyClassa")]
????public?class?MyClass?:?IMyClass
????{
????????public?void?Initialize()
????????{
????????????//nothing?todo
????????}
????????public?void?Dispose()
????????{
????????????//nothing?todo
????????}
????????public?String?VC(String?path)
????????{
???????????//??x?+?y;
????????????if?(path.Trim().Equals(""))
????????????{
????????????????return?"no?pathx";
????????????}
????????????fastvcAtiLib.fastvcyjmC2k?c?=?new?fastvcAtiLib.fastvcyjmC2k();
????????????//???c.novc?=?true;???//4?test?.only?show?pic?.not?show?vercode?text
????????????//?c.oriImg?=?true;???//img?not?process?and?get?vercode...?cant?echo?show?img?pic?..
????????????c.vg?=?1;
????????????c.sid?=?"c2n";
??????????
????????????string?VerifyCode;
????????????try
????????????{
????????????????VerifyCode?=?c.RecByte(path);
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????VerifyCode?=?ex.Message;
????????????}
????????????return?VerifyCode;
????????}
????}
}
注冊COM組件DLL
regasm???ClassLibrary1.dll?/codebase
如果你的DLL不?是強簽名的,則必須要使用/codebase參數
反注冊使用
regasm??/u?ClassLibrary1.dll
使用HTML中VBS腳本測試?
<script?language="VBScript">
Dim?o?:?Set?o=CreateObject("MyLib.MyClass")??
??o.Initialize
????MsgBox?"1?+?2?=?"?&?o.vc("c:\dx.jpg")
????o.Dispose
????Set?o=Nothing
</script>
提示不能創建?ACTIVEX?控件……
原因:是因為注冊沒有注冊上……
提示找不到路徑
說明已經注冊上了。可能DLL不是強簽名的,而又沒有指定/CODEBASE屬性,導致注冊里沒有這個鍵值。而查找不到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。