Name Mangling
-
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..."); }
-
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..."); }
Use
extern "C"
: extern "C" void showme(int thenum) {...} -
Use
extern "C"
: extern "C" void showme(int thenum) {...}Still get the same error.
-
Still get the same error.
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. -
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.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
-
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..."); }
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); } }
-
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..."); }
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