views:

145

answers:

1

I guess I do have to release also late bound COM objects.
But how is this done directly?

In my situation I use the following code from C# to get the focused point from Google Earth (simplified):

Type oClassType = Type.GetTypeFromProgID("GoogleEarth.ApplicationGE");
object oGE = Activator.CreateInstance(oClassType);
object oCamera = oGE.GetType().InvokeMember("GetCamera", System.Reflection.BindingFlags.InvokeMethod, null, oGE, new object[] { 0 });
double dFocusLatitude = (double)oCamera.GetType().InvokeMember("FocusPointLatitude", System.Reflection.BindingFlags.GetProperty, null, oCamera, null);
double dFocusLongitude = (double)oCamera.GetType().InvokeMember("FocusPointLongitude", System.Reflection.BindingFlags.GetProperty, null, oCamera, null);

So how to I release the camera and Google Earth objects in this situation?

+5  A: 

You can use Marshal.ReleaseComObject

e.g.

if(Marshal.IsComObject(oGE)==true)
{
  Marshal.ReleaseComObject(oGE);
}
cmsjr