To make C# create and register the typelibrary go to
Project/Properties/Build tick Register for COM interop. (Reccomended Choice)
Otherwise you need to use REGASM (see here for the asembly registration tool). The Assembly Registration tool reads the metadata within an assembly and adds the necessary entries to the registry, which allows COM clients to create .NET Framework classes transparently. This utility is necessary when you need to expose to COM e .exe (winform application) .net assembly. You can create a type libray in this way. MyAssembly.dll can be also MyAssembly.exe
It is important that you do not check the
Project/Properties/Application/Assembly Information... Make assembly COM-Visible.
This option will set [assembly: ConVisible(true)] in the AssemblyInfo.cs file
Which will make all the Class in the Project COM visible. This in practice will make C# to generate new Guids for each class on which we did not specify a Guid attribute each time we recompile, causing a registry bloat.
It is much better to set
[assembly: ConVisible(false)], and use ComVisible(true) at class level to specify which class should be visible for COM interop .
Showing posts with label Dll. Show all posts
Showing posts with label Dll. Show all posts
Friday, September 10, 2010
How to Register / UnRegister a C# COM Exposed DLL manually an with VS 2008
To Register a C# COM Exposed Dll you I reccomend to create a Register.Bat file with the following instruction
------------------------------------------------------------------------------------------------------
REM Set the search directories
path=%path%;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322;
REM we first Unregister the .NET dll and then register it
regasm.exe /u "FullPath\MyLibrary.dll" /tlb
regasm.exe /codebase "FullPath\MyLibrary.dll" /tlb
pause
-----------------------------------------------------------------------------------------------------
This insturction set the search path for the regasm.exe file. I have included the most common directory that should have it
path=%path%; .......
This line unregister the Dll and its typelibrary
regasm.exe /u "FullPath\MyLibrary.dll" /tlb
This one creates the type library and register the dll with its full Path and along the type library.
If you do not use the /codebase option VB will complain that it cannot find the library.
regasm.exe /codebase "FullPath\MyLibrary.dll" /tlb
To unregister make an unregister.bat file
---------------------------------------------------------------------------------------------
REM Set the search directories
path=%path%;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322;
REM we Unregister the .NET dll
regasm.exe /u "FullPath\MyLibrary.dll" /tlb
pause
-----------------------------------------------------------------------------------------------------
When you use the code base option you need to have a strongly type Assembly (Dll) To do this
follow these steps
Go to Properties/Signing. Tick Sign the assembly check box.
Then go to Choose a stroing name key file
Choose a name ex "MyLibrary_COM_Key"
This will create a MyLibray_COM_Key.snk file in the project folder.
Lastly you also need to make sure that the Assembly Version is not someting like 1.0.* which means that each time you rebuild the project the assembly name changes. Just give the assembly a version, something like 1.0.0.0 and stick with it. The call to the COM exposed DLL is also connected to the assembly version registered in the registry.
------------------------------------------------------------------------------------------------------
REM Set the search directories
path=%path%;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322;
REM we first Unregister the .NET dll and then register it
regasm.exe /u "FullPath\MyLibrary.dll" /tlb
regasm.exe /codebase "FullPath\MyLibrary.dll" /tlb
pause
-----------------------------------------------------------------------------------------------------
This insturction set the search path for the regasm.exe file. I have included the most common directory that should have it
path=%path%; .......
This line unregister the Dll and its typelibrary
regasm.exe /u "FullPath\MyLibrary.dll" /tlb
This one creates the type library and register the dll with its full Path and along the type library.
If you do not use the /codebase option VB will complain that it cannot find the library.
regasm.exe /codebase "FullPath\MyLibrary.dll" /tlb
To unregister make an unregister.bat file
---------------------------------------------------------------------------------------------
REM Set the search directories
path=%path%;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322;
REM we Unregister the .NET dll
regasm.exe /u "FullPath\MyLibrary.dll" /tlb
pause
-----------------------------------------------------------------------------------------------------
When you use the code base option you need to have a strongly type Assembly (Dll) To do this
follow these steps
Go to Properties/Signing. Tick Sign the assembly check box.
Then go to Choose a stroing name key file
Choose a name ex "MyLibrary_COM_Key"
This will create a MyLibray_COM_Key.snk file in the project folder.
Lastly you also need to make sure that the Assembly Version is not someting like 1.0.* which means that each time you rebuild the project the assembly name changes. Just give the assembly a version, something like 1.0.0.0 and stick with it. The call to the COM exposed DLL is also connected to the assembly version registered in the registry.
Thursday, September 9, 2010
MS scripting run time and MS Regular Expression in VB 6.0 or VBA
Hi,
Two nice library that help you speed up your VB 6.0 / VBA development time are the
1) Microsoft Scripting Run Time library
The two most interestinjg objects here are the
Dictionary object which is an hashtable. Its only major draw back is that it does not expose the NewEnum function, which means that while you can wrap it up to create a strongly type dictionary object, you cannot create a NewEnum method to loop through the collection using the For Each statement
FileSystemObject which let you easily access to files and folders
2) Microsoft VBScript Regural Expression 5.5.
This is a really nice library to use to test a string using regular expression.
This is an example on how it works:
Two nice library that help you speed up your VB 6.0 / VBA development time are the
1) Microsoft Scripting Run Time library
The two most interestinjg objects here are the
Dictionary object which is an hashtable. Its only major draw back is that it does not expose the NewEnum function, which means that while you can wrap it up to create a strongly type dictionary object, you cannot create a NewEnum method to loop through the collection using the For Each statement
FileSystemObject which let you easily access to files and folders
2) Microsoft VBScript Regural Expression 5.5.
This is a really nice library to use to test a string using regular expression.
This is an example on how it works:
Labels:
dictionary,
Dll,
filesystemobject,
library,
regular expression,
vba
Subscribe to:
Posts (Atom)