CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: COM

  1. #1
    Join Date
    Mar 2001
    Location
    Austria
    Posts
    3

    COM

    I have seen several questions about this subject, yet no answer (if given at all) was satisfying to me. So here's the question again: How can I use existing COM interfaces from C#? Something to compile and run would be great.

    thanks very much

    phi


  2. #2
    Join Date
    Jan 2000
    Posts
    12

    Re: COM

    Hope this helps
    http://dev.aspfree.com/quickstart/ho...s_NET2COM.aspx

    also from the howto documentation of .net
    How Do I...Call COM Methods from .NET?
    This example demonstrates how to use COM object from a Visual Basic.NET or C# application.

    In order to use the types defined within a COM library from managed code, you must obtain an assembly containing definitions of the COM types. Refer to the How Do I...Build a .NET Client That Uses a COM Server? for specific details.

    With Visual Basic.NET or with C#, you can reference the assembly using compiler /r switch or you can add reference to the project directly from Visual Studio.NET development tool.



    namespace TestClient {
    public class Test {
    public static void Main(){
    ExplorerLib.InternetExplorer explorer;
    ExplorerLib.IWebBrowserApp webBrowser;

    explorer = new ExplorerLib.InternetExplorer();
    webBrowser = (ExplorerLib.IWebBrowserApp) explorer;

    webBrowser.Visible = true;
    webBrowser.GoHome();
    ...
    }
    }
    }



    Namespace TestClient
    Public Class Test
    Public Shared Sub Main()
    Dim explorer As ExplorerLib.InternetExplorer
    Dim webBrowser As ExplorerLib.IWebBrowserApp

    explorer = New ExplorerLib.InternetExplorer
    webBrowser = explorer

    webBrowser.Visible = True
    webBrowser.GoHome
    ...
    End Sub
    End Class
    End Namespace





  3. #3
    Join Date
    May 1999
    Location
    CT
    Posts
    75

    Re: COM

    Here is another great article on using COM components in .NET called "Consume COM Components From .NET".
    http://www.vbpj.com/upload/free/feat...7/ce0107-1.asp

    Please rate my post if you think it was helpful. Or you can send money!

  4. #4
    Join Date
    Mar 2001
    Location
    Austria
    Posts
    3

    Re: COM

    Thanks for the help. However I still have two serious problems (want to use
    an out-of-process server which has been tested with VB and VC++)

    1) When I take a look (ildasm.exe) at the dll which has been created by
    tlbimp.exe, I can see that many properties, instead of returning an
    interface just return a System.Object as shown below.

    get_ActiveDocument : class System.Object

    Thus I have to cast and, frankly, this is not what I expected from C#...

    2) Running the programm causes the following exception:

    An unhandled exception of type
    'System.Runtime.InteropServices.VTableCallsNotSupportedException' occurred

    Again, the server caused no problems with VB and VC++!


    Thanks for help

    hansjoerg




  5. #5
    Join Date
    Nov 2001
    Location
    Chennai, TN, India
    Posts
    37

    How to use WebBrowser2 control in my dialog

    I am in need to use WebBrowser2 control in my dialog (non mfc). sisce this is possible in vb, i trust, it can also be done in VC also. I am using a WinMain SDK application.


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