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. How to access public varialbes in C# class

How to access public varialbes in C# class

Scheduled Pinned Locked Moved C#
questioncsharpc++tutorial
8 Posts 5 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.
  • J Offline
    J Offline
    Joe Rozario
    wrote on last edited by
    #1

    Dear friends I have small clarification I have c++ Dll which contains a class like these

    public class Vector3d {

    public:

    float x, y, z;

    Vector3d()
    {
    }
    }

    when i try to access the class by adding reference in C# project I could only create object for Vector3d class i am unable to access variables (x,y,z) my Vector3d Metadata looks like these

    [NativeCppClass]
    [CLSCompliant(false)]
    public struct Vector3d
    {
    }

    i could not find the variables in metadata also... what is the mistake i have done??? And what i have to do get the values to access? Thanks Joe.I

    realJSOPR P 2 Replies Last reply
    0
    • J Joe Rozario

      Dear friends I have small clarification I have c++ Dll which contains a class like these

      public class Vector3d {

      public:

      float x, y, z;

      Vector3d()
      {
      }
      }

      when i try to access the class by adding reference in C# project I could only create object for Vector3d class i am unable to access variables (x,y,z) my Vector3d Metadata looks like these

      [NativeCppClass]
      [CLSCompliant(false)]
      public struct Vector3d
      {
      }

      i could not find the variables in metadata also... what is the mistake i have done??? And what i have to do get the values to access? Thanks Joe.I

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      That's because you didn't make them public. Unless otherwise specified, all methods and data members are priviate.

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      J A R 3 Replies Last reply
      0
      • realJSOPR realJSOP

        That's because you didn't make them public. Unless otherwise specified, all methods and data members are priviate.

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        J Offline
        J Offline
        Joe Rozario
        wrote on last edited by
        #3

        Dear john, thanks for reply Please check the second line in C++ class

        1 Reply Last reply
        0
        • J Joe Rozario

          Dear friends I have small clarification I have c++ Dll which contains a class like these

          public class Vector3d {

          public:

          float x, y, z;

          Vector3d()
          {
          }
          }

          when i try to access the class by adding reference in C# project I could only create object for Vector3d class i am unable to access variables (x,y,z) my Vector3d Metadata looks like these

          [NativeCppClass]
          [CLSCompliant(false)]
          public struct Vector3d
          {
          }

          i could not find the variables in metadata also... what is the mistake i have done??? And what i have to do get the values to access? Thanks Joe.I

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          I believe you will have to provide set_ and get_ methods in your C++ code to access the data as these are fields.

          I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Onyx

          J 1 Reply Last reply
          0
          • realJSOPR realJSOP

            That's because you didn't make them public. Unless otherwise specified, all methods and data members are priviate.

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #5

            C++ is different than C#. In C++, you only need to specify "public:" once above the members you want to be public, whereas in C# you need to specify "public" in front of each member you want to be public.

            [Forum Guidelines]

            1 Reply Last reply
            0
            • P Pete OHanlon

              I believe you will have to provide set_ and get_ methods in your C++ code to access the data as these are fields.

              I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

              Forgive your enemies - it messes with their heads

              My blog | My articles | MoXAML PowerToys | Onyx

              J Offline
              J Offline
              Joe Rozario
              wrote on last edited by
              #6

              Dear peter Thanks for the reply, i have not only public variables and also public methods. i could not access anything. i do not know where is my mistake. is there anything i need to do to access the public method of c++ class? i just added the dll in my reference, then i specified in the Using namespace. Thanks

              P 1 Reply Last reply
              0
              • J Joe Rozario

                Dear peter Thanks for the reply, i have not only public variables and also public methods. i could not access anything. i do not know where is my mistake. is there anything i need to do to access the public method of c++ class? i just added the dll in my reference, then i specified in the Using namespace. Thanks

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                Is this a managed C++ class? You can't add an unmanaged DLL to .NET like this - you need to either wrap it in a Managed C++ implementation, or you need to p/invoke into it.

                I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Onyx

                1 Reply Last reply
                0
                • realJSOPR realJSOP

                  That's because you didn't make them public. Unless otherwise specified, all methods and data members are priviate.

                  .45 ACP - because shooting twice is just silly
                  -----
                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                  R Offline
                  R Offline
                  Ravi Bhavnani
                  wrote on last edited by
                  #8

                  No, they're internal. /ravi

                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                  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