简体   繁体   English

如何释放后期绑定的COM对象?

[英]How to release late bound COM objects?

I guess I do have to release also late bound COM objects. 我想我也必须释放后期绑定的COM对象。
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): 在我的情况下,我使用C#中的以下代码从Google Earth(简化版)中获取焦点:

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? 那么在这种情况下如何释放相机和Google Earth对象呢?

You can use Marshal.ReleaseComObject 您可以使用Marshal.ReleaseComObject

eg 例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM