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. Importing a global variable from a C DLL

Importing a global variable from a C DLL

Scheduled Pinned Locked Moved C#
csharpc++question
3 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
    Luca Leonardo Scorcia
    wrote on last edited by
    #1

    Yep, I'm not in the wrong forum (I hope). I have a C DLL that exports a few global variables (integers, if that matters) - I'd like to access these values using a C# library. I tried to google, but I couldn't find satisfactory answers. I've been able to access these variables creating a C++/CLI wrapper around the library, but I'm looking for a C# solution to avoid mantaining an extra project just for these integers. Any pointers? Thanks in advance

    Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása

    L 1 Reply Last reply
    0
    • L Luca Leonardo Scorcia

      Yep, I'm not in the wrong forum (I hope). I have a C DLL that exports a few global variables (integers, if that matters) - I'd like to access these values using a C# library. I tried to google, but I couldn't find satisfactory answers. I've been able to access these variables creating a C++/CLI wrapper around the library, but I'm looking for a C# solution to avoid mantaining an extra project just for these integers. Any pointers? Thanks in advance

      Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása

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

      Hi, AFAIK you can't just access unmanaged data, so the easiest thing to do would be to add getter and setter functions to the C DLL, then use P/Invoke to call them from C#. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


      L 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, AFAIK you can't just access unmanaged data, so the easiest thing to do would be to add getter and setter functions to the C DLL, then use P/Invoke to call them from C#. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


        L Offline
        L Offline
        Luca Leonardo Scorcia
        wrote on last edited by
        #3

        Well, I can't recompile the library since its licensing terms prohibit modifications, so I'll keep the C++ wrapper. Thanks anyway! I'm new to this P/Invoke stuff and I know I have quite an ability to overengineer simple things :-D

        Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása

        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