This is a very common occasion where we need to expose a .NET assembly to COM applications, so that the COM application can communicate with .NET assemblies. Here I am going to create a .NET Assembly and expose it from COM.
Your COM Exposed .NET class :
Let us create the Class which I need to expose to COM.
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace ComVisibleObject { [Guid("EB7F73B0-AF1F-4595-8CE8-849D3745E862")] public interface IComVisibleObject { string GetString(); void SetString(string value); } [Guid("DF8B1227-68EC-4F76-8C79-D20574C21B56")] [ComVisible(true)] public class ComVisibleObjectEx : IComVisibleObject { private string element = string.Empty; public string GetString() { return element; } public void SetString(string value) { element = value; } } }
Here I have created an Interface called IComVisibleObject
which might be used to create the class. Please note, it is not mandatory to create the interface.
To Uniquely Identify each class we placed GuidAttribute
to each of them. The class ComVisibleObjectEx
is exposed to COM using ComVisibleAttribute
set to true.
After your class is created in Class Library, Right click on Project - > Go to Properties and select Register for COM interop.
Again Under the signing Tab Select Sign the Assembly. In the Choose key file combobox select New. Choose Filename, Username and password.. The Strong name key will be created automatically.
Now Build the project. Say the dll produced is ComVisibleObject.dll. Use GacUtil to put it in Global Assembly Cache. Use this :
gacutil -i ComVisibleObject.dll
If its successful it will confirm "Assembly successfully added to the cache”
.
To add it from COM applications, you need to register assembly using regasm tool.Use
regasm ComVisibleObject.dll
After registration is successful, it will say "‘Types registered successfully"
.
Now let us create your COM application. For simplicity I use vbs. You can easily create an original VB application to test this as well
Dim object set object = CreateObject(”ComVisibleObject.ComVisibleObjectEx”) MsgBox(”Created the object.”) defaultText = object.GetString() MsgBox(”Default text length : ” & Len(defaultText)) object.SetString(”My new string”) newText = object.GetString() MsgBox(”New text is ” & newText)
Finally save the file as Example.vbs.
Open Command prompt and type
cscript Example.vbs
You will see the messageboxes show the text.
This comment has been removed by a blog administrator.
ReplyDeleteグリーもそこそこ出逢えますが、であいを求めるならやっぱりスタービーチが一番!登録無料で楽しい時間を過ごしたい方にはもってこいのサイト。これで恋人、セクフレを作るチャンスが大幅アップ
ReplyDeleteこれから家出したい人や現在家出している人達と、家出少女を救いたい人を繋げるSOS掲示板です
ReplyDelete今やモバゲーは押しも押されもせぬ人気SNS!当然であいを求めてる人も多い!そこで男女が出逢えるコミュニティーが誕生!ここなら友達、恋人が簡単にできちゃいますよ
ReplyDeletegreeやモバゲー、mixiよりアツイ!!スタービーチが新しくなって登場!!復活したスタービーチで新しいでぁいを見つけよう
ReplyDeleteセクフレ掲示板、¥倶楽部で大人の恋愛をしてみませんか?割り切ったセクフレと快楽のみを求めた恋愛をしてくださいませ
ReplyDeleteモバゲーやミクシィ、グリーでであえなかった人もNEWスタービーチなら確実にであいをゲット!無料年齢認証登録であの感動が今、再び蘇る
ReplyDelete最も復活してほしかったサイトでダントツのNO.1であるスタービーチがとうとう復活!!以前にもましてご利用者様に満足していただける最高のシステムになっております。思う存分新しくなったスタービーチをお楽しみください
ReplyDelete最低10万円から交際がスタートする援助スポット。不満を持つ熟女達が若い男性を求めて集まっております。熟女サークル逆¥交際であなたもリッチな生活を送ってみませんか
ReplyDelete