在经过TlbImp.exe等处理过程之后。
我在主线程里 private void button1_Click(object sender, RoutedEventArgs e)
{
DotNetArcom.Icomm icomm;
DotNetArcom.commClass m_comm;
m_comm = new DotNetArcom.commClass();
icomm = (Icomm)m_comm; if (!icomm.Init())
{
Debug.WriteLine("初始化成功!");
return;
}
Debug.WriteLine("xxx");
}调用正常。
但是我如果新开一个线程,在线程里创建com对象,如下
public void Run()
{
DotNetArcom.Icomm icomm;
DotNetArcom.commClass m_comm; m_comm = new DotNetArcom.commClass();
icomm = (Icomm)m_comm; Debug.WriteLine("xxx"); //初始化组件
if (!icomm.Init())
{
Debug.WriteLine("初始化成功!");
return;
}
}private void button2_Click(object sender, RoutedEventArgs e)
{
Thread xx2 = new Thread(Run);
xx2.SetApartmentState(ApartmentState.STA);
xx2.Start(); }
则在调用接口方法icomm.Init()的时候失败!
提示Unable to cast COM object of type 'DotNetArcom.commClass' to interface type 'DotNetArcom.Icomm'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{035785C0-5513-4874-ABD9-3AF5015D5261}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).请问我该怎么办。
我在主线程里 private void button1_Click(object sender, RoutedEventArgs e)
{
DotNetArcom.Icomm icomm;
DotNetArcom.commClass m_comm;
m_comm = new DotNetArcom.commClass();
icomm = (Icomm)m_comm; if (!icomm.Init())
{
Debug.WriteLine("初始化成功!");
return;
}
Debug.WriteLine("xxx");
}调用正常。
但是我如果新开一个线程,在线程里创建com对象,如下
public void Run()
{
DotNetArcom.Icomm icomm;
DotNetArcom.commClass m_comm; m_comm = new DotNetArcom.commClass();
icomm = (Icomm)m_comm; Debug.WriteLine("xxx"); //初始化组件
if (!icomm.Init())
{
Debug.WriteLine("初始化成功!");
return;
}
}private void button2_Click(object sender, RoutedEventArgs e)
{
Thread xx2 = new Thread(Run);
xx2.SetApartmentState(ApartmentState.STA);
xx2.Start(); }
则在调用接口方法icomm.Init()的时候失败!
提示Unable to cast COM object of type 'DotNetArcom.commClass' to interface type 'DotNetArcom.Icomm'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{035785C0-5513-4874-ABD9-3AF5015D5261}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).请问我该怎么办。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货