Re: Convert InProcServer to OutProc

From: Howard Swope (howardsnewsATspitzincDOTcom)
Date: 11/22/04

  • Next message: Howard Swope: "CoCreateInstanceEx returns null pointer, but IClassFactory::CreateInstance doesn't ???"
    Date: Mon, 22 Nov 2004 16:19:48 -0500
    
    

    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.

    "Frank Lakmann" <lakmann@gmx.de> wrote in message
    news:1d5cd7b3.0411221108.5d2a7bdb@posting.google.com...
    > 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}\InprocServer
    32]
    > @="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"=""


  • Next message: Howard Swope: "CoCreateInstanceEx returns null pointer, but IClassFactory::CreateInstance doesn't ???"

    Relevant Pages

    • Re: Reference Problem
      ... Are you having the same version of the VB dll on both of your servers? ... Server and Delete the Reference to VB Dll and agian add the reference ... i update the solution on Integration Server. ...
      (microsoft.public.dotnet.framework)
    • Re: Remoting Types in the client (newbie question)
      ... Then I added a reference to the web application. ... the function on the server except that I have to put #if around all the guts ... of the code so that it compiles out of the dll. ... public class Class1: MarshalByRefObject ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Reference DLL with CopyLocal = False problem ....
      ... CopyLocal is just a visual studio directive. ... on a server and I made a Reference to this DLL. ... I check my Reference paths in Project properties - there is a valid path ...
      (microsoft.public.dotnet.general)
    • Re: Connect to remote COM object and registering typelib
      ... do you need to have the DLL present on your local machine? ... object and the name of the server it resides on, ... of registration on the local machine - no registry entries are ...
      (microsoft.public.win32.programmer.ole)
    • Sharepoint caching referenced dlls
      ... We have recently come across an issue whereby SharePoint seems to cache dlls. ... Our web parts on the test server all referenced a dll called WebLibSP.dll. ... with a reference to the newly named version of WebLibSP ...
      (microsoft.public.sharepoint.portalserver.development)