0

Trying to start up again with Visual C++, using 2010 Express edition.

Trying to figure out something.

If define a function in the Project.cpp file, why can't I use it in the Form1.h file, specifically the private: System::Void Form1_Load?

I get this error:

1>c:\users\boss\documents\visual studio 2010\projects\second\second\Form1.h(94): error C3861: 'Function': identifier not found

Is there any way to define a function so it can be used anywhere?

in Form1.h:

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    this->txtMain->Text += FunctionX("Data");
    this->txtMain->SelectionStart = this->txtMain->Text->Length;
}

in Project.cpp:

std::string FunctionX(std::string message) {
    // other code here
    return message;
}
Wyllow Wulf
  • 410
  • 4
  • 23

1 Answers1

0
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
extern std::string FunctionX(std::string message);
this->txtMain->Text += msclr::interop::marshal_as<System::String^>(FunctionX("Data"));
this->txtMain->SelectionStart = this->txtMain->Text->Length;
}

This works! Thanks for the tips.

Wyllow Wulf
  • 410
  • 4
  • 23