我目前正在开发一个与客户端通信的应用程序。如下所示,我有一个委托方法,它将接收到的消息作为 TextBox 类型的 ComObject 返回。
void mailbox_MessageReceived(ref object ComObj1) {
string typeName = Microsoft.VisualBasic.Information.TypeName(ComObj1);
Console.WriteLine(typeName); //Prints "TextBox"
//insert rest of code here
}
到目前为止,我没有成功地尝试强制转换 ( ComObj1
as TextBox),并试图让IntPtr
forComObj1
作为参数传递 Marshal.GetObjectForNativeVariant()
,但都无济于事。
我的问题是我应该如何ComObj1
转换为 C# 对象?