1. Create a class library project
2. Change class1.cs to the desired name and ask if you want to rename the class at the same time.
3. Modify the assemblyinfo. CS comvisible attribute under the properties directory to true.
4. Go to the "generate" tab of the "Project menu"> "mylib property" and click "register for com InterOP ".
5. Go on to the "signature" tab and click "sign for assembly". In the following drop-down box, select "<new...>"
6. In the pop-up dialog box, enter mylib .. You can also remove the password-protected file option by name.
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, select registry format for "create guid", and then copy
Note that you need to remove the curly brackets before and after the guid in [GUID ("...").
9. compile it at the command prompt. Go to the dll Directory and use gacutil/I mylib. DLL to add the DLL to the global cache. Then use regasm mylib. DLL to register the 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 >