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. Name Mangling

Name Mangling

Scheduled Pinned Locked Moved Managed C++/CLI
c++
7 Posts 4 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.
  • U Offline
    U Offline
    User 625201
    wrote on last edited by
    #1

    Is there a way to declare a function (SHOWME in this case) in C++ to prevent the name mangling so it can be referenced by C code. I currently have this (form1.h): public: void showme(int thenum) { MessageBox::Show(S"abc", S"Result..."); }

    N U R 3 Replies Last reply
    0
    • U User 625201

      Is there a way to declare a function (SHOWME in this case) in C++ to prevent the name mangling so it can be referenced by C code. I currently have this (form1.h): public: void showme(int thenum) { MessageBox::Show(S"abc", S"Result..."); }

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #2

      Use extern "C": extern "C" void showme(int thenum) {...}

      U 1 Reply Last reply
      0
      • N Nemanja Trifunovic

        Use extern "C": extern "C" void showme(int thenum) {...}

        U Offline
        U Offline
        User 625201
        wrote on last edited by
        #3

        Still get the same error.

        R 1 Reply Last reply
        0
        • U User 625201

          Still get the same error.

          R Offline
          R Offline
          Rick York
          wrote on last edited by
          #4

          The function called by the "C" module can not be a member of the class. One common way to export methods of a class for use by C code is to write functions (called wrappers) that take an object of the class as an argument. Here is a small sample : extern "C" { int ShowMe( void *pobject, int argument ) { CYourClass *pc = (CYourClass *)pobject; return pc->ShowMe( argument ); } } I have done this on a fairly large scale and it worked rather well. a two cent stamp short of going postal.

          U 1 Reply Last reply
          0
          • R Rick York

            The function called by the "C" module can not be a member of the class. One common way to export methods of a class for use by C code is to write functions (called wrappers) that take an object of the class as an argument. Here is a small sample : extern "C" { int ShowMe( void *pobject, int argument ) { CYourClass *pc = (CYourClass *)pobject; return pc->ShowMe( argument ); } } I have done this on a fairly large scale and it worked rather well. a two cent stamp short of going postal.

            U Offline
            U Offline
            User 625201
            wrote on last edited by
            #5

            Well, progress is made. Any advice on appending text to a textbox in TOoutbox function. Here is the code: #pragma once extern "C" int magiccalc(void); namespace myapp1 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public __gc class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); magiccalc(); } protected: void Dispose(Boolean disposing) { if (disposing && components) { components->Dispose(); } __super::Dispose(disposing); } private: System::Windows::Forms::TextBox * outBox; private: System::ComponentModel::Container * components; void InitializeComponent(void) { ...yada yada } public: static void TOoutbox(int outnum) { outBox->AppendText("x"); //add text to textbox } }; } extern "C" { void showme(int wrapnum) // My wrapper for C { myapp1::Form1::TOoutbox(3); } } Thanks to all

            1 Reply Last reply
            0
            • U User 625201

              Is there a way to declare a function (SHOWME in this case) in C++ to prevent the name mangling so it can be referenced by C code. I currently have this (form1.h): public: void showme(int thenum) { MessageBox::Show(S"abc", S"Result..."); }

              U Offline
              U Offline
              User 625201
              wrote on last edited by
              #6

              myapp1::Form1::ioBOX.Appendtext("x"); Gives this error: error C2228: left of '.Appendtext' must have class/struct/union type type is '' ---------------------------------------------------------------------- Any ideas? ---------------------------------------------------------------------- #pragma once extern "C" int magiccalc(void); namespace myapp1 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public __gc class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); magiccalc(); } protected: void Dispose(Boolean disposing) { if (disposing && components) { components->Dispose(); } __super::Dispose(disposing); } private: System::Windows::Forms::TextBox * ioBOX; private: void InitializeComponent(void) { this->ioBOX = new System::Windows::Forms::TextBox(); ... ...yadda yadda } public: static void TOioBox(int outnum) { ERROR----> myapp1::Form1::ioBOX.Appendtext("x"); } }; } extern "C" { void showme(int wrapnum) // My wrapper for C { myapp1::Form1::TOioBox(3); } }

              1 Reply Last reply
              0
              • U User 625201

                Is there a way to declare a function (SHOWME in this case) in C++ to prevent the name mangling so it can be referenced by C code. I currently have this (form1.h): public: void showme(int thenum) { MessageBox::Show(S"abc", S"Result..."); }

                R Offline
                R Offline
                Rahul200676
                wrote on last edited by
                #7

                Name mangling is a technique used by the compiler. Each compiler can have different algorithm for name mangling. I don't think its possible to prevent name mangling. Rahul

                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