i got one COM component and want to access from C#.I created a interface in my C# program and want to access that component with its CoClass.When i created a object it gives me __ComObject which is a RuntimeCallabelWrapper.
I want to know when it returns me a object and it create a MethodTable for me, then when i cast this interface to another interface to call method of other interface i adds method of second interface or create a new MethodTable for that? Below is the code:
[Guid("169D0491-E149-4BB3-932E-A42C4F8D3478")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IInventory
{
void Buy(int quantity, float rate);
void Sell(int quantity, float rate);
int GetStock();
}
[Guid("8B08A7ED-8D46-41B2-B8D9-35F4CF37F75B")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IAccount
{
void Credit(double amount);
void Debit(double amount);
double GetBalance();
}
[Guid("F8E3E05A-CAFA-4CBD-BC42-DF9328729B01")]
[ComImport]
class Trader{}
public static void Main(string[] args)
{
IInventory inv = (IInventory) new Trader(); // this gives me RCW
inv.Buy(qty, 150);
IAccount acc = (IAccount) inv; // ?
Console.WriteLine("Current balance: {0}", acc.GetBalance());
}