Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Converting C++ COM to C#

Converting C++ COM to C#

Scheduled Pinned Locked Moved C#
helpcsharpc++comdata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LeonardLay
    wrote on last edited by
    #1

    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.

    C 1 Reply Last reply
    0
    • L LeonardLay

      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.

      C Offline
      C Offline
      cpkilekofp
      wrote on last edited by
      #2

      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);

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups