Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.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
从C+创建C#COM接口+;头文件:指向结构的指针 我试图为下面的C++ COM接口创建C~*COM接口,但我遇到了麻烦。 C++ COM接口(工作) C#COM接口(不工作)_C#_C++_Com_Marshalling - Fatal编程技术网

从C+创建C#COM接口+;头文件:指向结构的指针 我试图为下面的C++ COM接口创建C~*COM接口,但我遇到了麻烦。 C++ COM接口(工作) C#COM接口(不工作)

从C+创建C#COM接口+;头文件:指向结构的指针 我试图为下面的C++ COM接口创建C~*COM接口,但我遇到了麻烦。 C++ COM接口(工作) C#COM接口(不工作),c#,c++,com,marshalling,C#,C++,Com,Marshalling,当我调用GetCommands时,COM服务应该用值填充结构。然而,在下面的代码中,结构似乎保持不变 var commands = new IRawCmd(); var pointer = Marshal.AllocHGlobal(Marshal.SizeOf(commands)); Marshal.StructureToPtr(commands, pointer, false); _deviceFilterRaw.GetCommands(pointer); var result = Mar

当我调用GetCommands时,COM服务应该用值填充结构。然而,在下面的代码中,结构似乎保持不变

var commands = new IRawCmd();
var pointer = Marshal.AllocHGlobal(Marshal.SizeOf(commands));
Marshal.StructureToPtr(commands, pointer, false);

_deviceFilterRaw.GetCommands(pointer);

var result = Marshal.PtrToStructure(pointer, typeof (IRawCmd));

我做错什么了吗?我应该在我的C#接口中使用ref参数吗?

将此属性应用于接口
接口类型(ComInterfaceType.Inter‌​人脸识别(未知)


您可以尝试使用:var pointer=Marshal.alloctaskmem(Marshal.SizeOf(commands))?我刚试过,结果也一样。你的dll是注册的还是guid是正确的?是的。该头文件在我所拥有的示例C++项目中工作正常。它是C#接口。如果应用此属性[ComImport,Guid(“574358C5-E59D-45b2-8976-0BA03D81EC07”,接口类型(ComInterfaceType.InterfaceSiunknown)]?
[ComImport, Guid("574358C5-E59D-45b2-8976-0BA03D81EC07")]
public interface IRaw
{
    [PreserveSig]
    int GetCommands(IntPtr pCmd);

    [PreserveSigAttribute]
    int SetCommands(IntPtr pCmd);
}

[StructLayout(LayoutKind.Sequential)]
public struct IRawCmd
{
    public int kmdf_drv_ver;
    public int kmdf_drv_buildtime;
    // more, but ommited
}
var commands = new IRawCmd();
var pointer = Marshal.AllocHGlobal(Marshal.SizeOf(commands));
Marshal.StructureToPtr(commands, pointer, false);

_deviceFilterRaw.GetCommands(pointer);

var result = Marshal.PtrToStructure(pointer, typeof (IRawCmd));
[ComImport, Guid("574358C5-E59D-45b2-8976-0BA03D81EC07",InterfaceType(ComInterfaceType.Inter‌​faceIsIUnknown)]