C++: DialogResult and namespaces confusion...
-
Friday, November 11, 2005 3:09 PMHi I'm working with C++ Express, I'm new to Windows Forms and the namespaces used but not to C++. I'm having difficulties with DialogResults:
The MSDN documentation gives examples like this:
System::Windows::Forms::DialogResult result;
result = MessageBox::Show( this, message, caption, buttons );
if ( result == ::DialogResult::Yes )
Yet when I compile I get the following errors (for the if line) :
error C3083: 'DialogResult': the symbol to the left of a '::' must be a type
So I also try without the leading :: and get:
error C2039: 'Yes' : is not a member of '`global namespace''
error C2065: 'Yes' : undeclared identifier
error C2039: 'Yes' : is not a member of 'System::Windows::Forms::Form::DialogResult'
Finally I try with the whole namespace (is that the right terminology ?) and it compiles:
see declaration of 'System::Windows::Forms::Form::DialogResult'
error C2065: 'Yes' : undeclared identifier
if (result == System::Windows::Forms::DialogResult::Yes )
Now I suspect I may be missing something, but I copied this code from the MSDN examples yet in is not working, can someone tell me what I ought to be doing ? and is there some documentation I should be reading on this ?
All Replies
-
Tuesday, December 13, 2005 8:34 PM
Hi there -
Make sure you have both the #using and the using namespace directives to ensure the compiler understands your references.
For example -
#using <System.DLL>
#using <System.Drawing.DLL>
#using <System.Windows.Forms.DLL>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
Thanks,
April Reagan
Visual C++ Program Management -
Saturday, July 01, 2006 12:06 PMHi, i was having the exact same problem, i implemented the #using directives as you described but makes no difference at all, still need to type in system::windows::forms::dialogresult::ok for it to compile, any other suggestions would be great.
-
Thursday, October 19, 2006 2:04 AM
i meet a similar problem
if ( openFileDialog1->ShowDialog() ==DialogResult::OK )
{
if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
{
// Insert code to read the stream here.
myStream->Close();
}
}there are only tow items can be selected after DilogResrlt:: . they are get() and set().
-
Sunday, November 12, 2006 12:11 PM
Just wasted a morning on this one -- anyone got a fix yet? Seems there's already confusion in the docs, I've seen two MS code snippets, one reading:
if ( openFileDialog1->ShowDialog() == DialogResult::OK )
the other:
if ( openFileDialog1->ShowDialog() == ::DialogResult::OK )Seriously thinking of moving to another platform... max sympathy to fellow-sufferers
FM
-
Monday, November 13, 2006 8:16 PM
April Reagan MSFT wrote: Hi there -
Make sure you have both the #using and the using namespace directives to ensure the compiler understands your references.
For example -
#using <System.DLL>
#using <System.Drawing.DLL>
#using <System.Windows.Forms.DLL>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;Thanks April Reagan ,your suggestion solves my little problem.
and my problem was (Compiler Error C3083): the compiler couldn't recognize this:
System::Windows::Forms::MessageBox::Show("disposed");
But after writing #using <System.Windows.Forms.DLL> in my code, Wow, this solves the problem and my happy life back again.
Thanks April Reagan
-
Tuesday, January 16, 2007 2:45 AM#using <System.DLL>
#using <System.Drawing.DLL>
#using <System.Windows.Forms.DLL>
Those did not help me. Same compile errors. But when I included the same sample code into a MDI form application. The compile error went away. Very strange.
---
Free stuff is not really free, if it wastes your time. -
Wednesday, March 28, 2007 10:18 PMI have the same exact issue and placing the #using directives doesn't work.
Still get these three errors:
Error 1 error C3083: 'DialogResult': the symbol to the left of a '::' must be a type
Error 2 error C2039: 'OK' : is not a member of '`global namespace''
Error 3 error C2065: 'OK' : undeclared identifier
Writing the entire System::Windows::Form:
ialogResult:
K compiles.
I'm have another issue, when I run the program the OpenFileDialog opens again after selecting a file.
This is strange, ShowDialog() returns a bool yet, what does OpenFileDialog1->ShowDialog() return?
The dialog result should just be a member of the OpenFileDialog class, then checking a field in the data structure/class would be very easy. But I'm not even sure what the is :
ialogResult:
K is doing, how does it get the pointer to the correct dialog box?
Is C++ dead? has everyone just gone to C#?
This thread has gone 15 months unsolved! -
Thursday, July 26, 2007 4:09 AMin visual c++ express try
it worked for meCode SnippetSystem::Windows::Forms::DialogResult::OK instead of DialogResult::OK
-
Monday, May 12, 2008 8:07 PMgreat System::Windows::Forms:
ialogResult:
K worked instead of DialogResult:
K i just don't get why as i have
using namespace System::Windows::Forms;
in my sourcecode, shouldn't that handle it?
but thanks a lot. -
Tuesday, October 14, 2008 4:43 AM
The :: in front of DialogResult means DialogResult is a global identifier. The problem occurs when your using namespace declarations are inside of your local namespace.
The solution is to move those statements outside of and before your form application namespace.
*** THIS IS A PROBLEM ***
namespace myApp {
using namespace System;using namespace System::Windows::Forms;
if ( result == :
ialogResult::Yes ){
}
}
************************************
*** THIS FIXES THE PROBLEM ***
using namespace System;
using namespace System::Windows::Forms;
namespace myApp {
if ( result == :
ialogResult::Yes ){
}
}
*****************************- Proposed As Answer by Clay L Friday, May 29, 2009 10:03 PM
-
Friday, May 29, 2009 10:05 PMJoe58,
Thanks!!
Solved the problem for me.
Clay L -
Thursday, January 28, 2010 1:41 AM
thanks ,your imformation is right.
move the internal namespace out of your local namespace, it works.
MSN:h2zy@hotmail.com -
Monday, September 03, 2012 10:49 PMThanks that's the simplest solution
- Edited by Shakeel Osmani Monday, September 03, 2012 10:49 PM
- Proposed As Answer by Shakeel Osmani Monday, September 03, 2012 10:50 PM
- Unproposed As Answer by Shakeel Osmani Monday, September 03, 2012 10:50 PM
-
Friday, November 23, 2012 12:53 PM
short
private: System::Void Vaciar_Click(System::Object^ sender, System::EventArgs^ e) {
short Confirmacion;
Confirmacion = Convert::ToInt16(MessageBox::Show("DeleteList","Eliminar",MessageBoxButtons::YesNo,MessageBoxIcon::Question));
if((Confirmacion.CompareTo(Convert::ToInt1(System::Windows::Forms::DialogResult::Yes))) ==0){
Lista->Items->Clear();
NArticulos->Text=Convert::ToString(Lista->Items->Count);
}
}

