I'm doing a Microsft PowerPoint add-in solution whit VSTO that reads info from a hardware, hardware developers gave me their SDK to control this hardware but I'm having problems trying to control it.
I have this library
ARS
There is a class
ARS.BaseConnection
I have this variable
ARS.BaseConnection BaseConn;
The problem is when a I create a new Object of type BaseConnection
BaseConn = new ARS.BaseConnection();
Debugger doesn't show any exception, POWERPNT.exe just crashes and stops.
I tried to debug POWERPNT and it says Access violation writing location 0x00d20f78. But I'm not programming PowerPoint.
I fount that the demo program in SDK(that actually works) has a [STAThread] before main, so I think it must be run as STA so I create a new thread:
ARS.BaseConnection BaseConn;`
public form1()
{
InitializeComponent();
System.Threading.Thread thread = new System.Threading.Thread(createBase);
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();
thread.Join();
BaseConn.Open(); // There is the problem, when I'm trying to use open() BaseConn debuger says: COM object that has been separated from its underlying RCW cannot be used.
}
private void createBase()
{
BaseConn = new ARS.BaseConnection(); //If it runs in a STA tread doesn't crash.
}
I got COM object that has been separated from its underlying RCW cannot be used.
How can I make this works?