Converting C++ COM to C#
-
Hello, I am working on using a COM from C++ in new C# code. I have connected and I can get access to the member functions. The problem that I am having is that one of the member functions takes a STRUCT as an input and it outputs an array of STRUCT. And in the STRUCT there are some char arrays. So when I run the C# code I get an error message "Specified array was not of the expected type." I'll put in a bit of the code that I am converting: C++ ----------------- interface IHangerAssignment2 : public IUnknown { virtual HRESULT STDMETHODCALLTYPE Analyze(const HangerIn2& rIn, HangerOut2* pOut, int nOut, int& nResults) = 0; }; where HangerIn2 and HangerOut2 are structs that inherit from other structs. HangerOut2 inherits from a struct that contains 2 char arrays. HangerOut2 also contains an array or char arrays. in C# --------------- I rewrote HangerIn2 public struct HangerIn2 { public HangerIn hangerIn; //I just added the HangerIn struct as a member // New USP2 properties public double kingWidth; public double kingHeight; public double []bearingLength; public bool concealedFlange; }; I did the same for HangerOut2 which contains several arrays. The converted code in C# public interface IHangerAssignment { void Analyze(HangerIn2 hgrIn, ref HangerOut2[] hgrOut, int maxOutput, ref int nResults); } When this function is called, that is when I get the error "Specified array was not of the expected type." I did notice that when stepping through the debugger that the members are always listed in alphabetical order.
-
Hello, I am working on using a COM from C++ in new C# code. I have connected and I can get access to the member functions. The problem that I am having is that one of the member functions takes a STRUCT as an input and it outputs an array of STRUCT. And in the STRUCT there are some char arrays. So when I run the C# code I get an error message "Specified array was not of the expected type." I'll put in a bit of the code that I am converting: C++ ----------------- interface IHangerAssignment2 : public IUnknown { virtual HRESULT STDMETHODCALLTYPE Analyze(const HangerIn2& rIn, HangerOut2* pOut, int nOut, int& nResults) = 0; }; where HangerIn2 and HangerOut2 are structs that inherit from other structs. HangerOut2 inherits from a struct that contains 2 char arrays. HangerOut2 also contains an array or char arrays. in C# --------------- I rewrote HangerIn2 public struct HangerIn2 { public HangerIn hangerIn; //I just added the HangerIn struct as a member // New USP2 properties public double kingWidth; public double kingHeight; public double []bearingLength; public bool concealedFlange; }; I did the same for HangerOut2 which contains several arrays. The converted code in C# public interface IHangerAssignment { void Analyze(HangerIn2 hgrIn, ref HangerOut2[] hgrOut, int maxOutput, ref int nResults); } When this function is called, that is when I get the error "Specified array was not of the expected type." I did notice that when stepping through the debugger that the members are always listed in alphabetical order.
LeonardLay wrote:
in C# --------------- I rewrote HangerIn2 public struct HangerIn2 { public HangerIn hangerIn; //I just added the HangerIn struct as a member // New USP2 properties public double kingWidth; public double kingHeight; public double []bearingLength; public bool concealedFlange; };
Look, without knowing what both structs looked like in C++, I haven't a hope in heck of helping you that much, though I think that void Analyze(HangerIn2 hgrIn, ref HangerOut2[] hgrOut, int maxOutput, ref int nResults); should be void Analyze(ref HangerIn2 hgrIn, HangerOut2[] hgrOut, int maxOutput, ref int nResults);