English 中文(简体)
不能处置C# COM物体
原标题:Unable to dispose of C# COM object
  • 时间:2010-07-22 18:36:47
  •  标签:
  • c#
  • c++
  • com
  • dll

我有一个“C#”类,我已经把它归入一个未管理的C++ DLL。 C#类的定义类似:

public interface IFSFunction
{
    double GetProcessTime();
}

public class Functions : IFSFunction
{
    // Initialization here

    // Interface function
    public double GetProcessTime()
    {
        // Do stuff - return a value
    }
}

然后,在我的C++中 DLL 我提到了C#类:

IFSFunctionPtr pIFuncs;
pIFuncs.CreateInstance(__uuidof(Functions));
double proctime = pIFuncs->GetProcessTime()
pIFuncs.Detach()->Release();

这称C#非常出色地运作,但似乎在言词之后没有正确清除。 似乎还有人提到我的C#类hang。 我如何确保我的C# COM目标完全消失?

最佳回答

我会猜测你正在使用一种欺骗工具,让你看看看管的肥皂。 和Winbug.exe一样,也有 so。 是的,在最后释放后,请看功能类别物体的事例。 这是一个符合正常垃圾收集规则的管理物体。 在垃圾收集器运行之前,它获得的垃圾收集。 只要你继续管理分配记忆的法典,那将是这样。

问题回答

你们是否做了这项工作? (sorry, it s C#而不是C++)

try
{
    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pIFuncs);
}
catch (System.Exception ex)
{
    // Do nothing
}
finally
{
    pIFuncs = null;
}

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.finalreleasecomobject.aspx” rel=“nofollow noreferer”>。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签