Click to See Complete Forum and Search --> : COM
H. Petschko
June 25th, 2001, 01:55 PM
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
angelsb
June 26th, 2001, 07:26 PM
Hope this helps
http://dev.aspfree.com/quickstart/howto/doc/Interop/Building_Samples_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
smakadia
July 13th, 2001, 10:22 AM
Here is another great article on using COM components in .NET called "Consume COM Components From .NET".
http://www.vbpj.com/upload/free/features/vbpj/2001/07jul01/ce0107/ce0107-1.asp
Please rate my post if you think it was helpful. Or you can send money! :)
H. Petschko
July 15th, 2001, 04:45 AM
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
Padma kumar
November 5th, 2001, 06:12 AM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.