Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
COM:如何从c++;com客户端到c#_C#_C++_Com - Fatal编程技术网

COM:如何从c++;com客户端到c#

COM:如何从c++;com客户端到c#,c#,c++,com,C#,C++,Com,我已经读到com可以封送内存块。但是如何将C++内存块的内存块封给C?< /P>中编写的进程外服务器。 我有以下用C#编写的接口和实现: 在tlb中,此接口变为: interface ISomeInterface : IDispatch { HRESULT DoSomething([in] long memoryBlockPtr); }; < >在C++ COM客户端中,我想把COTASKMeMelc分配的内存传递给服务器 但此调用失败,因为com封送处理长而不是内存块指针,并且com

我已经读到com可以封送内存块。但是如何将C++内存块的内存块封给C?< /P>中编写的进程外服务器。 我有以下用C#编写的接口和实现:

在tlb中,此接口变为:

interface ISomeInterface : IDispatch {
  HRESULT DoSomething([in] long memoryBlockPtr);
};
< >在C++ COM客户端中,我想把COTASKMeMelc分配的内存传递给服务器

但此调用失败,因为com封送处理长而不是内存块指针,并且com服务器获取指向错误内存块的IntPtr

interface ISomeInterface : IDispatch {
  HRESULT DoSomething([in] long memoryBlockPtr);
};
char * memoryBlockPtr = (char*)CoTaskMemAlloc(size);
// write to memoryBlockPtr variable length structure 
// which could have char* fields that point to another memory block 
// allocated by CoTaskMemAlloc
HRESULT hr = ISomeInterface->DoSomething((long)memoryBlockPtr);