admin管理员组文章数量:1221299
I have a Outproc COM server exe created in C++ using ATL which implements interface methods.
I have 2 test clients to test this. One is native C++ and other is Managed.
Native test client implementation as below
::CoInitialize(NULL);
IMyInterfacePtr pMyInterfacePtr;
HRESULT hr = ::CoCreateInstance(__uuidof(CMyImpl), NULL, CLSCTX_LOCAL_SERVER, __uuidof(IMyInterface),
(void**) &pMyInterfacePtr);
if (SUCCEEDED(hr))
{
hr = pMyInterfacePtr->MyMethod();
if (SUCCEEDED(hr))
{
wprintf(L"My method called successfully");
}
else
{
wprintf(L"My method failed");
}
}
else
{
wprintf(L"Failed to create instance of CMyImpl\n");
}
I have created managed assembly using tlb and refferring the managed assembly in my Managed C# client.
Managed C# Client implementatio is as below,
static void Main(string[] _)
{
MyImpl myImpl = new MyImpl();
myImpl.MyMethod();
}
In both cases, When object is created new instance of my COM exe is getting lauched and MyMethod is getting executed in out of proc.
In case of Native client when execution is completed the outproc exe is automatically getting closed and I could see call to destructor of the MyImpl.
But incase of managed C# client when execution is completed the outproc exe is not getting closed. It's still running.
Is there any special handling required for Managed client?
I have a Outproc COM server exe created in C++ using ATL which implements interface methods.
I have 2 test clients to test this. One is native C++ and other is Managed.
Native test client implementation as below
::CoInitialize(NULL);
IMyInterfacePtr pMyInterfacePtr;
HRESULT hr = ::CoCreateInstance(__uuidof(CMyImpl), NULL, CLSCTX_LOCAL_SERVER, __uuidof(IMyInterface),
(void**) &pMyInterfacePtr);
if (SUCCEEDED(hr))
{
hr = pMyInterfacePtr->MyMethod();
if (SUCCEEDED(hr))
{
wprintf(L"My method called successfully");
}
else
{
wprintf(L"My method failed");
}
}
else
{
wprintf(L"Failed to create instance of CMyImpl\n");
}
I have created managed assembly using tlb and refferring the managed assembly in my Managed C# client.
Managed C# Client implementatio is as below,
static void Main(string[] _)
{
MyImpl myImpl = new MyImpl();
myImpl.MyMethod();
}
In both cases, When object is created new instance of my COM exe is getting lauched and MyMethod is getting executed in out of proc.
In case of Native client when execution is completed the outproc exe is automatically getting closed and I could see call to destructor of the MyImpl.
But incase of managed C# client when execution is completed the outproc exe is not getting closed. It's still running.
Is there any special handling required for Managed client?
Share Improve this question asked Feb 7 at 8:37 srajeshnklsrajeshnkl 8953 gold badges16 silver badges51 bronze badges1 Answer
Reset to default 1I found that Marshal.ReleaseComObject can release the Marshaled data, Modified the Managed C# code like below, now the out proc exe is closing after release.
object obj;
int hr = Ole32.CoCreateInstance(Constants.MyImplClassGuid,
IntPtr.Zero, Ole32.CLSCTX_LOCAL_SERVER, typeof(IMyInterface).GUID, out obj);
if (hr < 0)
{
Marshal.ThrowExceptionForHR(hr);
}
var server = (IMyInterface)obj;
string output = server.MyMethod();
Marshal.ReleaseComObject(obj);
本文标签: cOutProc COM from Managed client not closing the out proc server exeStack Overflow
版权声明:本文标题:c# - OutProc COM from Managed client not closing the out proc server exe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739341120a2158936.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论