views:

130

answers:

1

I am trying to get access to an running instance of an application, Rational Rhapsody, through COM. I am trying to use the C++/CLI COM calls.
From C++ calling:

rhapsody::RPApplication^ App = safe_cast<rhapsody::RPApplication^>( Marshal::GetActiveObject("Rhapsody.Application"));

Causes a COM Exception : 800401E3 (Operation Unavailable)

But, using Marshal::GetActiveObject("Word.Application") works just fine. Using gcnew rhapsody::RPApplication() works fine to make a new instance and the same code in C#:

rhapsody.RPApplication App = (rhapsody.RPApplication) Marshal.GetActiveObject("Rhapsody.Application")

works just fine. Any ideas why it doesn't work from C++/CLI?

+1  A: 

Is your main() routine in C++/CLI flagged with [STAThread]? It's commonly required, especially when dealing with COM objects.

[STAThread]
int main(array<System::String^>^args)
{
     // code here...
}
Reed Copsey
I tried adding that, as another post here sugested it for the same error, but it didn't change anything.
Zanson
Ok, I tried it again just for fun and for some reason it works now. Wierd.
Zanson