Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2004

Tip: Looking for answers? Try searching our database.

Convert InProcServer to OutProc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank Lakmann - 22 Nov 2004 19:08 GMT
Hello,
I created a COM Server .NET dll that works fine as an InProcServer. It
creates it's own OdbcConnection and saves the passed data to DB.
But the DB-connection of the application using this COM server gets
messed up when the new connection is opened (some wierd ODBC 2 vs ODBC
3 stuff).
The solution would be to run the COM Server in a separate process.
First I read this is not possible in .NET (shocking!) then I stumbled
over this sdk sample COMREG but couldn't get it to work.
What do I have to do to convert my DLL into an OutProcServer?
Can I use DllHost? Do I have to make an exe out of it? What would the
Main Method look like and do I have to show a Form?

I have little experience in COM programming and was happy the server
worked.
But now I am stuck. Please help.

The "entry point" of the DLL is the class Application.

using System;
using System.Runtime.InteropServices;
using ...

namespace IkarosGMV.COM {
    /// <summary>
    /// Zusammenfassung für Application.
    /// </summary>
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [Guid("D36F350B-7200-468f-8459-6BA8512BFD46")]
    public class Application {
        private Error _error;
       
        public Application() {
            _error = new Error();
        }
               
        public Error Error {
            get {return _error;}
        }
       
        public int AnzahlNeuerNachrichten {
             get {
                // get some data from db
                       ......
                }
                return anz;
            }
        }
               
        public void LogIn(string DSN,string DBN, string UID, string PWD) {
            try {
                // creates new connection
                       ......

                this._error.IsError = false;               
            } catch (Exception exc) {
                _error.IsError = true;
                _error.Message = exc.GetType().FullName + ": " + exc.Message;
            }
        }
           // other methods and properties
            ......
}       

The regfile otuput from COMREG looks like this:
REGEDIT4

[HKEY_CLASSES_ROOT\IkarosGMV.COM.Application]
@="IkarosGMV.COM.Application"

[HKEY_CLASSES_ROOT\IkarosGMV.COM.Application\CLSID]
@="{D36F350B-7200-468F-8459-6BA8512BFD46}"

[HKEY_CLASSES_ROOT\CLSID\{D36F350B-7200-468F-8459-6BA8512BFD46}]
@="IkarosGMV.COM.Application"
"AppID"="{D36F350B-7200-468F-8459-6BA8512BFD46}"

[HKEY_CLASSES_ROOT\CLSID\{D36F350B-7200-468F-8459-6BA8512BFD46}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="IkarosGMV.COM.Application"
"Assembly"="IkarosGMV.COM, Version=1.0.1781.16813, Culture=neutral,
PublicKeyToken=85dfcfbcc43007db"
"RuntimeVersion"="v1.1.4322"
"Codebase"="file:///I:/Testumgebung/IKAROS-GMV/IkarosGMV.COM.DLL"

[HKEY_CLASSES_ROOT\CLSID\{D36F350B-7200-468F-8459-6BA8512BFD46}\ProgId]
@="IkarosGMV.COM.Application"

[HKEY_CLASSES_ROOT\AppID\{D36F350B-7200-468F-8459-6BA8512BFD46}]
@="IkarosGMV.COM.Application"
"AppID"="{D36F350B-7200-468F-8459-6BA8512BFD46}"
"DllSurrogate"=""
"RunAs"="Interactive User"

[HKEY_CLASSES_ROOT\CLSID\{D36F350B-7200-468F-8459-6BA8512BFD46}\Implemented
Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}]
@=""

[HKEY_CLASSES_ROOT\Component
Category\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}]
"0"=""
Howard Swope - 22 Nov 2004 21:19 GMT
Yes, it is possible to this. There are a few good samples that I ran across
searching the web, however, I didn't save a reference to them. You would be
better served by finding one of those. However, the basic process was not
too difficult.

1. Create an exe that references your .dll
2. Have your exe register the class factories for your creatable objects
3. Use regasm to register your .dll and create a type library
4. Manually replace any InprocServer32 registry entries that were added with
LocalServer entries
5. Manually add appropriate AppId registry entries

You will probably also find it helpful to define your own interfaces instead
of letting interop do it for you. You will want to make sure that you have
applied the appropriate Com attributes too.

As I mentioned I came across a few good tutorial web sites. They walked you
through the process step by step.

> Hello,
> I created a COM Server .NET dll that works fine as an InProcServer. It
[quoted text clipped - 72 lines]
> @="IkarosGMV.COM.Application"
> "AppID"="{D36F350B-7200-468F-8459-6BA8512BFD46}"

[HKEY_CLASSES_ROOT\CLSID\{D36F350B-7200-468F-8459-6BA8512BFD46}\InprocServer
32]
> @="mscoree.dll"
> "ThreadingModel"="Both"
[quoted text clipped - 12 lines]
> "DllSurrogate"=""
> "RunAs"="Interactive User"

[HKEY_CLASSES_ROOT\CLSID\{D36F350B-7200-468F-8459-6BA8512BFD46}\Implemented
> Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}]
> @=""
>
> [HKEY_CLASSES_ROOT\Component
> Category\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}]
> "0"=""

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.