Ok I found it. Infact I disassembled the interop using a dissembler and got
the code from there.
I've added following classes to my dotnet code (given below), from where I
want to call the COM methods. But when I try to use it as
string szParam1, szParam2, szParam3;
string szRetVal;
MyInterfaceClass objCom = new MyInterfaceClass();
szRetVal = objCom.MyMethod(szParam1, szParam2, szParam3);
I get a runtime exception as
An unhandled exception of type 'System.ExecutionEngineException' occurred in
ConsoleApplication1.exe
Do you have any idea, where I'm doing it wrong. I've checked the GUID of the
interface and the COM, both are correct. Please help me with any suggestion.
Regards
Usman
////////////////////////////////////////////////START OF
CODE/////////////////////////////////////////////////////////////////////////////////////
[assembly: Guid("2feb9bb4-35a5-4044-82f2-4063f31c156d")]
[assembly: ImportedFromTypeLib("MyComLib")]
namespace MyComLib
{
[ComImport, Guid("0287D794-187B-4CAC-A87D-BF2AD3BCFBA5"),
CoClass(typeof(MyInterfaceClass))]
public interface MyInterface : IMyInterface
{
}
[ComImport, TypeLibType((short) 2), ClassInterface((short) 0),
Guid("BEB239AB-6220-4FBF-BBEB-9B6234FA23BA")]
public class MyInterfaceClass : IMyInterface, MyInterface
{
// Methods
[MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(1)]
public virtual extern short MyMethod([In, MarshalAs(UnmanagedType.BStr)]
string szParam1, [In, MarshalAs(UnmanagedType.BStr)] string szParam2, [In,
MarshalAs(UnmanagedType.BStr)] string szParam3);
[return: MarshalAs(UnmanagedType.BStr)]
}
[ComImport, TypeLibType((short) 0x10c0),
Guid("0287D794-187B-4CAC-A87D-BF2AD3BCFBA5")]
public interface IMyInterface
{
[MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(1)]
short MyMethod([In, MarshalAs(UnmanagedType.BStr)] string szParam1, [In,
MarshalAs(UnmanagedType.BStr)] string szParam2, [In,
MarshalAs(UnmanagedType.BStr)] string szParam3);
}
}
////////////////////////////////////////////////END OF
CODE/////////////////////////////////////////////////////////////////////////////////////
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:e9****************@TK2MSFTNGP06.phx.gbl...
Is there any other way to call the COM
method such that my output assembly of dotnet application does'nt rely on
the interop.
You can manually declare the COM types you need to use in your code.
See the ComImport, Guid, ComClass and ComInterfaceType attributes.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.