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 dynamic MyStruct[] from unmanaged dll to C#

passing dynamic MyStruct[] from unmanaged dll to C#

Scheduled Pinned Locked Moved C#
csharpc++data-structuresquestion
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.
  • R Offline
    R Offline
    rncwnd
    wrote on last edited by
    #1

    I have to pass a dynamic array of structures from an unmanaged DLL to C#. I wrote the following wrapper-function. Unmanaged C++ DLL: typedef struct browserStruct { unsigned long id; unsigned char name[250]; } structTypBrowser; extern "C" __declspec(dllexport) unsigned long __stdcall sv_getDocClassList( unsigned long &cnc, unsigned short numOfElems, structTypBrowser *browserArray ) {...} In C#: public struct svStructTypBrowser { private UInt32 m_id; private string m_name; } [DllImport("SVConDll.dll")] private static extern UInt32 sv_getDocClassList( out UInt32 c, out ushort numOfElems, out IntPtr browserArray // svStructTypBrowser ); public getDocClassList() { IntPtr p1; svStructTypBrowser[] m_docClasses; ... try { result = sv_getDocClassList(out m_cnc, out noe, out p1); m_docClasses = (svStructTypBrowser[])Marshal.PtrToStructure(p1, typeof(svStructTypBrowser)); } } The IntPtr p1 is null after calling sv_getDocClassList(). Has anybody a solution?

    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