我想把相当复杂的types从托pipe到本地,反之亦然。
目前,这是通过创build多维安全列表来完成的,这个安全列表的优点是编组已经完成了,但意味着我们最终会得到相当复杂的参差不齐的arrays。
我试图把一些结构放入SAFEARRAYs,但遇到的问题非常类似于这个没有答案的问题。 MSDN似乎暗示,这是可能的,但我没有成功。 如果这是可能的,在以下情况下有效的VT_types是什么?
编辑:谢谢! 所以这必须是一个VT_RECORD。
struct Change { PSTR key; PSTR val; }; struct NodeChages { int nodeId; SAFEARRY* changes; //CComSafeArray<Change> }; STDAPI func(/*CComSafeArray<NodeChanges>*/ SAFEARRAY * f);
在pipe理方面,我有。
public struct Change { [MarshalAsAttribute(UnmanagedType.LPStr)] public string key; [MarshalAsAttribute(UnmanagedType.LPStr)] public string value; } [StructLayoutAttribute(LayoutKind.Sequential)] public struct NodeChanges { public int nodeId; [MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(CurveChange))] public Change[] changes; } [DllImportAttribute("My.dll", EntryPoint = "Func", PreserveSig = true, CallingConvention=CallingConvention.StdCall)] public static extern void Func( [MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(NodeChange))] NodeChange[] changes );
但是这个(如另一个post )给了我:
System.ArgumentException : The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))