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