CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    53

    How to Call COM unmanaged code at Runtime from C#.NET using ITypeLib and ITypeInfo ?

    Hello,

    I need to call unmanaged COM code from C#.NET. By Loading unmanaged COM Type libraries from (LoadTypeLibEx), I am able to iterate over all exposed types by COM TLB. Now I need to call those exposed methods at run time by knowing their addresses or by accessing some how COM vtable's starting address and by applying indexing for getting addresses of those exposed methods under interfaces.

    How this can be acheived..?

    Regards Usman

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How to Call COM unmanaged code at Runtime from C#.NET using ITypeLib and ITypeInf

    Um, I'm not sure this is the right forum.

    Can't you just add the typelib as a reference? Then just create the class as you would any other class?

  3. #3
    Join Date
    Jan 2010
    Posts
    53

    Re: How to Call COM unmanaged code at Runtime from C#.NET using ITypeLib and ITypeInf

    No.!!
    This is unmanaged COM code problem.
    I've unmanaged C++ COM component's binaries(DLL/EXE) and I need to call those unmanaged COM component's exposed functions at runtime. This requires addresses of those functions and knowing the exact type.

    I've loaded type library and iterated over all types enclosed in that and able to extract every function signature with its type(interface). Now next step to call those methods provided its name and interface. This requires traversal of vtable of that COM Interface and taking address.

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How to Call COM unmanaged code at Runtime from C#.NET using ITypeLib and ITypeInf

    Yes!!

    It looks like you're trying to accomplish this by taking the path of MOST resistance.

    Just go to your C# project properties, choose "Add Reference" Pick the Browse tab, select your .tlb and your done.

    Now you can create the class with a simple "new" and follow the intellisense. That's how I do it, but I'm admittedly pretty ignorant on C#.

    Code:
            private void button1_Click(object sender, EventArgs e)
            {
                ComClassLib.MyTestClassClass MyTestClassObject = new ComClassLib.MyTestClassClass();
                MyTestClassObject.DoIdentify(2,2);
            }

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to Call COM unmanaged code at Runtime from C#.NET using ITypeLib and ITypeInf

    I've moved this into the C# forum. If you need to call a COM component from a C# app, just follow hoxsiew's advice.

    The COM subsystem will expose the interfaces and methods and adding the COM reference to the C# project will create the necessary wrappers so the COM object can be used in the C# project.

  6. #6
    Join Date
    Jan 2010
    Posts
    53

    Re: How to Call COM unmanaged code at Runtime from C#.NET using ITypeLib and ITypeInf

    I think story just drifting on other side.
    My target isn't to generate code.

    I know .NET use tlbimp.exe to create wrappers on unmanaged code and allows you to call unmanaged code using that wrapper. It creates managed TLB's for you (By adding Reference).

    My target is NOT this.

    I need to call unmanaged code at RUNTIME(Suppose I have Gui which shows all COM exposed methods(full signatures) and Interfaces , Now I want o call one of those exposed methods at now-means at runtime).

    What I need for this to be done ? I need to pass arguments and finally the address of that exposed method that's it. I've enumerated all types and signatures on GUI using ITypeLib as LoadTypeLibEx and ITypeInfo methods i.e GetNames and members of TYPEDESC etc.

    Now I want to execute those methods at runtime. I just need ADDRESS OF EXPOSED METHOD.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured