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. Passing an array of structs from c# to unmanaged c++ dll

Passing an array of structs from c# to unmanaged c++ dll

Scheduled Pinned Locked Moved C#
csharpc++data-structuresdebuggingtutorial
1 Posts 1 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.
  • M Offline
    M Offline
    Marek Konieczny
    wrote on last edited by
    #1

    Hi, I need to pass a relativly complicated struct into a dll calling a CORBA Service which has to be written in vc6.0 and it has to contain many elements which are necessary to create an input for a service. Unfortunately I can see only the first array element, other are ignored. Here an example of c# code: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct MyStrStruct3 { public string FirstName; public string FamilyName; public int size; } [DllImport(@"C:\Projects\CorbaLib60\Debug\CorbaLib.dll")] private static extern int TestMe(ref MyStrStruct3[] pstr); MyStrStruct3[] Names = new MyStrStruct3[2]; Names[0].FamilyName = "Konieczny"; Names[0].FirstName = "Marek"; Names[0].size = 3; Names[1].FamilyName = "OtherName"; Names[1].FirstName = "OtherFirst"; Names[1].size = 2; int miki1 = TestMe(ref Names); C++ code look like this: typedef struct _MyStruct2 { char* FirstName; char* FamilyName; UINT size; } MyStruct2; int TestMe(MyStruct2* pStruct[]) { int Size = 2; for (int i=0; isize; char* miki = pStruct[i]->FamilyName; char* miki1 = pStruct[i]->FirstName; } return 42; } I define export : __declspec(dllexport) int TestMe(MyStruct2* pStruct[2]); It works, but only for first element. I also have tried to pass it as [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct MyStrStruct4 { public MyStrStruct3[] Names; public int size; } but it doesn't work and raise an exception. Marek

    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