Click to See Complete Forum and Search --> : error C2352/C2227


mrknight
January 22nd, 2007, 12:11 AM
I am new to C++.NET and have created a form with a ListBox control on it to display ongoing status of the application.

How do I access this control outside the Form1.h header file? I have started writing the rest of the application in the Form1.cpp file, but am unable to add new items to the listbox as documented.

From what I've read, I am trying to access a non-static member but have been unable to find any examples of how to resolve this.

Here's the code snippet[s]. Any guidance would be appreciated.

Thanks in advance.

Form1.h

namespace DigiPlot
{
...
public: System::Void AddListBoxText(System::Object * text)
{
lBoxStatus->Items->Add(text);
}
};

Form1.cpp

int APIENTRY _tWinMain
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
{
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
Application::Run(new Form1());

Form1::AddListBoxText(S"This is a test"); //error C2352
return 0;
}

or alternatively:

int APIENTRY _tWinMain
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
{
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
Application::Run(new Form1());

Form1::lBoxStatus->Items->Add(S"This is a test"); // error C2227
return 0;
}

cilu
January 22nd, 2007, 02:38 AM
[ redirected ]

mrknight
January 22nd, 2007, 02:47 AM
cilu,

your response was redirected, any ideas where?