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. Managed C++/CLI
  4. First contact with C++/CLI

First contact with C++/CLI

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++helpquestionannouncement
2 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

    Background: I'm trying to build a managed wrapper around a C library, using C++/CLI to build a DLL that will be referenced by a C# program. This is my first look to C++/CLI, so even little things seem really hard. Now, my first problem. The C library has lots of parameters passed by pointers, e.g.: void H5get_libversion(int * major, int * minor, int * release); What I'd like to have is an equivalent method in C++/CLI, something that in C# would be: void GetLibVersion(ref int major, ref int minor, ref int release); The only way I found to achieve this is doing something like:

    void HGlobals::GetLibVersion(unsigned int % major, unsigned int % minor, unsigned int % release)
    {
    unsigned int _major, _minor, _release;

    H5get\_libversion(&\_major, &\_minor, &\_release);
    
    major = \_major;
    minor = \_minor;
    release = \_release;
    

    }

    Do I really have to do this manual "duplication"? Isn't there a better (shorter) way? 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

    M 1 Reply Last reply
    0
    • L Luca Leonardo Scorcia

      Background: I'm trying to build a managed wrapper around a C library, using C++/CLI to build a DLL that will be referenced by a C# program. This is my first look to C++/CLI, so even little things seem really hard. Now, my first problem. The C library has lots of parameters passed by pointers, e.g.: void H5get_libversion(int * major, int * minor, int * release); What I'd like to have is an equivalent method in C++/CLI, something that in C# would be: void GetLibVersion(ref int major, ref int minor, ref int release); The only way I found to achieve this is doing something like:

      void HGlobals::GetLibVersion(unsigned int % major, unsigned int % minor, unsigned int % release)
      {
      unsigned int _major, _minor, _release;

      H5get\_libversion(&\_major, &\_minor, &\_release);
      
      major = \_major;
      minor = \_minor;
      release = \_release;
      

      }

      Do I really have to do this manual "duplication"? Isn't there a better (shorter) way? 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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Maybe try pinning those moveable managed "pointers" (tracking references)

      void NativeFunc(int *a, int *b)
      {
          *a = 10;
          *b = 20;
      }

      public ref class TestRefClass
      {
      public:
          TestRefClass()  {}
          void TestMethod(Int32 %a, Int32 %b)
          {
              pin_ptr<Int32> pa = &a;
              pin_ptr<Int32> pb = &b;
              NativeFunc(pa, pb);
          }
      };

      int _tmain()
      {
          int a = 3;
          int b = 4;
          TestRefClass obj;
          obj.TestMethod(a, b);

      return 0;
      }

      Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      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