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. Send a struct to external DLL

Send a struct to external DLL

Scheduled Pinned Locked Moved C#
questioncsharpc++
4 Posts 3 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
    Ronenb
    wrote on last edited by
    #1

    Hi All I have a project in C# that I need to import C++ dll In order to import it I’m using [DllImport("CommunicationManagerDLL.dll")] private static extern bool WiMAXGetState(ref eNDIS_802_16E_STATE NDIS_802_16E_STATE); how can I send a pointer to struct to the dll ? should I use ref? Thanks Ronen

    D 1 Reply Last reply
    0
    • R Ronenb

      Hi All I have a project in C# that I need to import C++ dll In order to import it I’m using [DllImport("CommunicationManagerDLL.dll")] private static extern bool WiMAXGetState(ref eNDIS_802_16E_STATE NDIS_802_16E_STATE); how can I send a pointer to struct to the dll ? should I use ref? Thanks Ronen

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      This should work if you're struct is correct.

      eNDIS_802_16E_STATE NDIS_802_16E_STATE interopStruct = new eNDIS_802_16E_STATE NDIS_802_16E_STATE();
      bool result = WiMAXGetState(ref interopStruct);

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
      Why are you using VB6? Do you hate yourself? (Christian Graus)

      L 1 Reply Last reply
      0
      • D DaveyM69

        This should work if you're struct is correct.

        eNDIS_802_16E_STATE NDIS_802_16E_STATE interopStruct = new eNDIS_802_16E_STATE NDIS_802_16E_STATE();
        bool result = WiMAXGetState(ref interopStruct);

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        That looks fine for simple structs, holding value types only, except maybe for padding and different semantics (long and char). And it could go terribly wrong when the struct holds reference types or pointers. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        D 1 Reply Last reply
        0
        • L Luc Pattyn

          That looks fine for simple structs, holding value types only, except maybe for padding and different semantics (long and char). And it could go terribly wrong when the struct holds reference types or pointers. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          Of course, with no info on the struct it's impossible to be absolutly sure!

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          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