+ Reply to Thread
Results 1 to 8 of 8

Thread: C# in-process DLL activex com object

  1. #1
    Newbie kegtappa is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    8

    C# in-process DLL activex com object

    I'm trying to write an in-process dll plugin for an application. Every dll file I create using C# cannot be read by the hosting application. The program says the dll files are an "invalid format". However, the files I create in VB6 work fine. This is VERY frustrating since I do not want to code in VB6. Since I'm using Visual Studio 2008 and C# I can obviously do anything that VB6 used to be able to do, and it should be MUCH easier. Since creating a com plugin from a type library is pretty simple and easy in VB6 why can't I figure this out in C#?!

    What am I do doing wrong? Here is an article about what I'm trying to achieve. The article explains how to create the plugin in VB6, and that works great. Now I just want to do this in .NET can someone tell me what I'm doing wrong here? Why can't the host application read the .net dll file? I've tried to create this dll file in every imaginable way, no matter what the host application cannot read the dll file.

  2. #2
    Learning Programmer lobo521 is on a distinguished road
    Join Date
    Jan 2010
    Posts
    57

    Re: C# in-process DLL activex com object

    If i understand you are trying to create com dll in c#. This can help you.
    Building COM Objects in C# C# Help – C# Resources and Community

  3. #3
    Newbie kegtappa is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    8

    Re: C# in-process DLL activex com object

    Yes, exactly. I was worried that I couldn't use C# / .NET to create a dll file in the correct format. Every dll file I've created thus far can't be read by the host application. It just says "invalid dll".

    Thanks for the link I'll check out this article.

  4. #4
    Newbie kegtappa is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    8

    Re: C# in-process DLL activex com object

    Ok I'm at a loss here. I'm not sure what I'm doing wrong. Here is a last ditch effort.

    Here is the interface which my DLL file should implement.

    Code:
    using System;
    using System.Runtime.InteropServices;
    
    namespace Zmud
    {
        [Guid("0999FEED-10E6-4424-A706-A28731686853")]
        [TypeLibType(4160)]
        public interface IzMUDPlugin
        {
            [DispId(24)]
            bool CanCapture { get; }
            [DispId(17)]
            string SaveSettings { get; }
            [DispId(2)]
            int Version { get; }
    
            [DispId(5)]
            void AddCommands(ref string FileName, ref int ComVersion);
            [DispId(9)]
            void AddMenu(int MenuIndex, ref string Caption, ref string HelpStr, ref int ComID, int M);
            [DispId(18)]
            void CaptureOutput(int H, string AsciiText, string RawText);
            [DispId(4)]
            void Close();
            [DispId(21)]
            void CloseThread(int H);
            [DispId(7)]
            bool CustomEdit(string Ref, string S);
            [DispId(3)]
            void Init();
            [DispId(15)]
            void LoadSettings(string P, int L);
            [DispId(10)]
            void Menu(int H, int ComID);
            [DispId(13)]
            void MUDInput(int H, ref string P);
            [DispId(22)]
            void OnConnect(int H);
            [DispId(23)]
            void OnDisconnect(int H);
            [DispId(20)]
            void OpenThread(int H, string Name, string Host, int Port);
            [DispId(12)]
            void Parse(int H, ref string P, bool IsPrompt, ref int DoGag, ref bool DoUpdate);
            [DispId(6)]
            void plugCommand(int H, int ComID, string ComStr, object P);
            [DispId(8)]
            string plugFunction(int H, int ComID, string ComStr, object P);
            [DispId(1)]
            void Register(ref string Name, ref string Company, ref string Regcode, ref string Description, ref string Version, ref string HelpFile, ref bool LoadDef);
            [DispId(19)]
            void Status(int Stat);
            [DispId(14)]
            void Update(int H);
            [DispId(11)]
            void UserInput(int H, ref string P, ref bool SendToMUD);
        }
    }
    Here is my (unsuccessful) attempt to implement this interface.

    Code:
    using System;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Zmud;
    
    namespace TestPlugin
    {
        [Guid("DF8290EA-0388-45f1-B692-ED94F0F5517F"),
        ClassInterface(ClassInterfaceType.None),
        ComSourceInterfaces(typeof(IzMUDPlugin))]
        public class TestPlugin : IzMUDPlugin
        {
            public TestPlugin()
            {
            }
    
            #region IzMUDPlugin Members
    
            void IzMUDPlugin.AddCommands(ref string FileName, ref int ComVersion)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.AddMenu(int MenuIndex, ref string Caption, ref string HelpStr, ref int ComID, int M)
            {
                //throw new NotImplementedException();
            }
    
            bool IzMUDPlugin.CanCapture
            {
                //get { throw new NotImplementedException(); }
                get { return true; }
            }
    
            void IzMUDPlugin.CaptureOutput(int H, string AsciiText, string RawText)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.Close()
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.CloseThread(int H)
            {
                //throw new NotImplementedException();
            }
    
            bool IzMUDPlugin.CustomEdit(string Ref, string S)
            {
                //throw new NotImplementedException();
                return true;
            }
    
            void IzMUDPlugin.Init()
            {
                //throw new NotImplementedException();
    
            }
    
            void IzMUDPlugin.LoadSettings(string P, int L)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.MUDInput(int H, ref string P)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.Menu(int H, int ComID)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.OnConnect(int H)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.OnDisconnect(int H)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.OpenThread(int H, string Name, string Host, int Port)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.Parse(int H, ref string P, bool IsPrompt, ref int DoGag, ref bool DoUpdate)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.Register(ref string Name, ref string Company, ref string Regcode, ref string Description, ref string Version, ref string HelpFile, ref bool LoadDef)
            {
                Name = "TestzMudPlugin";
                Company = ""; //My registration Company
                Regcode = ""; //My Regcode
                Description = "TestPlugin";
                HelpFile = "";
                LoadDef = true;
            }
    
            string IzMUDPlugin.SaveSettings
            {
                //get { throw new NotImplementedException(); }
                get { return ""; }
            }
    
            void IzMUDPlugin.Status(int Stat)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.Update(int H)
            {
                //throw new NotImplementedException();
            }
    
            void IzMUDPlugin.UserInput(int H, ref string P, ref bool SendToMUD)
            {
                //throw new NotImplementedException();
            }
    
            int IzMUDPlugin.Version
            {
                get { return 1; }
            }
    
            void IzMUDPlugin.plugCommand(int H, int ComID, string ComStr, object P)
            {
                //throw new NotImplementedException();
            }
    
            string IzMUDPlugin.plugFunction(int H, int ComID, string ComStr, object P)
            {
                //throw new NotImplementedException();
                return "";
            }
    
            #endregion
        }
    }
    The source code compiles fine. But when I attempt to load the plugin dll file in the host application the error is

    "TestPlugin.dll is not a valid plugin"

    I know the interface is good, I can use it to create dll files in VB6. I'm hoping I wont' have to do this in VB6

  5. #5
    Learning Programmer lobo521 is on a distinguished road
    Join Date
    Jan 2010
    Posts
    57

    Re: C# in-process DLL activex com object

    Have you done everything that is in tutorial that i posted (Register for COM Interop, strong name).
    I think ComSourceInterfaces should be type of your event interface.

  6. #6
    Newbie kegtappa is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    8

    Re: C# in-process DLL activex com object

    Yes, I followed the article exactly.

    The project is setup to register with COM interop, and is being built with a strong name key file. I know the assembly is registered with COM, I can see it in the COM viewer utility.

    But that might be the problem. The application in question isn't looking in the COM registry entry, it is looking at the dll file for a type library. I think the problem here is that the hosting application isn't a .NET application so this dll file needs to be compiled to a win32 dll file, not a .NET dll file. I just can't find the **** option to make a regular win32 dll file anywhere. When I try to view the dll file that is created by Visual Studio 2008 with a type library viewer the file is unreadable, which means it does not contain a type library. The dll I created in VB6 IS readable, and has a type library I can see with the viewer.

    It wants to open the dll and read the com interface from there, not from the type library registered somewhere in windows or COM, but directly from the dll file.

    This has to be possible in .net somehow, it worked in VB6... I'm not sure why this was so easy in VB6 and now its just a nightmare, they made everything else easier...

  7. #7
    Newbie kegtappa is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    8

    Thumbs down Re: C# in-process DLL activex com object

    Its looking more and more like this isn't going to be possible.

    See this

    stackoverflow.com/questions/404521/can-i-create-a-regular-windows-dll-for-a-plugin-in-net

    It sounds like I'm going to have to write my dll file in a non .net language.

    That kinda sucks... but it confirms what I was seeing in the type library viewer. C# dll files do not have type libraries in them... No wonder the app can't read the dll file.

  8. #8
    Programming Professional PGP_Protector is on a distinguished road PGP_Protector's Avatar
    Join Date
    Jun 2009
    Posts
    220

    Re: C# in-process DLL activex com object

    I did a DLL in C# that my client uses in C++ or VB.NET
    It opens a Pipe to my main application so they can talk to it and control it.
    But it doesn't run as a plugin, they just include it in their application.

    One thing to check is verify that your Output Type (Options -> Application) is set to Class Library.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 0
    Last Post: 01-06-2010, 10:40 AM
  2. windows process and thread wrapping
    By julmuri in forum C and C++
    Replies: 1
    Last Post: 11-07-2009, 12:05 PM
  3. Unable to cast COM object
    By stonezz in forum C# Programming
    Replies: 2
    Last Post: 11-05-2009, 05:58 AM
  4. PHP Objects
    By chili5 in forum PHP Tutorials
    Replies: 5
    Last Post: 03-24-2009, 02:12 PM
  5. Replies: 0
    Last Post: 11-26-2008, 11:30 PM