1. Create a class library project
2. Change class1.cs to the name we want.
Ask if you want to rename the class at the same time, OK
3. Modify assemblyinfo. Cs in the properties directory.
Set the comvisible attribute to true.
4. Project menu-> mylib attributes
Find the generate Tab
Next, find "register for com InterOP" and check
5. Continue and find the "signature" tab.
CheckProgramSet signature"
In the drop-down box below, select "<new...>"
6. In the pop-up dialog box, enter mylib .. Or just give a name.
Remove the password-protected file option
7. Start encoding. Any public class must have an I-enabled interface definition.
-
-
C # code
-
Using System; Using System. Collections. Generic; Using System. text; Using System. runtime. interopservices; Namespace Mylib {[comvisible ( True )] [GUID ( " 2cbd3d76-35f1-4f9d-9c1b-9dbfee412f76 " )] Public Interface Imyclass { Void Initialize (); Void Dispose (); Int Add ( Int X, Int Y);} [comvisible ( True )] [GUID ( " EA2F140A-108F-47ae-BBD5-83EEE646CC0D " )] [Progid ( " Mylib. myclass " )] Public Class Myclass: imyclass { Public Void Initialize (){ // Nothing todo } Public Void Dispose (){ // Nothing todo } Public Int Add ( Int X, Int Y ){ Return X + Y ;}}}
8. For the string in the guid attribute, under the "tool" menu, "Create guid"
Select registry format, and then copy
Note that you need to remove the curly brackets before and after the guid in [GUID ("...").
9. compile it
Enter the directory where the DLL is located at the command prompt.
Use gacutil/I mylib. DLL to add this DLL to the global cache.
Then use regasm mylib. DLL to register this DLL.
10. Try it In VBScript...
-
-
HTML code
-
< Script Language = "VBScript" >
DimO:SetO=Createobject("Mylib. myclass")
O. initialize Msgbox " 1 + 2 = " & O. Add ( 1 , 2 ) O. Dispose Set O = Nothing </ Script >
1. Create a class library project
2. Change class1.cs to the name we want.
Ask if you want to rename the class at the same time, OK
3. Modify assemblyinfo. Cs in the properties directory.
Set the comvisible attribute to true.
4. Project menu-> mylib attributes
Find the generate Tab
Next, find "register for com InterOP" and check
5. Continue and find the "signature" tab.
Check "sign the assembly"
In the drop-down box below, select "<new...>"
6. In the pop-up dialog box, enter mylib .. Or just give a name.
Remove the password-protected file option
7. Start encoding. Any public class must have an I-enabled interface definition.
-
-
C # code
-
Using System; Using System. Collections. Generic; Using System. text; Using System. runtime. interopservices; Namespace Mylib {[comvisible ( True )] [GUID ( " 2cbd3d76-35f1-4f9d-9c1b-9dbfee412f76 " )] Public Interface Imyclass { Void Initialize (); Void Dispose (); Int Add ( Int X, Int Y);} [comvisible ( True )] [GUID ( " EA2F140A-108F-47ae-BBD5-83EEE646CC0D " )] [Progid ( " Mylib. myclass " )] Public Class Myclass: imyclass { Public Void Initialize (){ // Nothing todo } Public Void Dispose (){ // Nothing todo } Public Int Add ( Int X, Int Y ){ Return X + Y ;}}}
8. For the string in the guid attribute, under the "tool" menu, "Create guid"
Select registry format, and then copy
Note that you need to remove the curly brackets before and after the guid in [GUID ("...").
9. compile it
Enter the directory where the DLL is located at the command prompt.
Use gacutil/I mylib. DLL to add this DLL to the global cache.
Then use regasm mylib. DLL to register this DLL.
10. Try it In VBScript...
-
-
HTML code
-
< Script Language = "VBScript" >
DimO:SetO=Createobject("Mylib. myclass")
O. initialize Msgbox " 1 + 2 = " & O. Add ( 1 , 2 ) O. Dispose Set O = Nothing </ Script >