locked
C++: DialogResult and namespaces confusion...

    Question

  • Hi 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
    error C2039: 'Yes' : is not a member of '`global namespace''
    error C2065: 'Yes' : undeclared identifier

    So I also try without the leading :: and get:

    error C2039: 'Yes' : is not a member of 'System::Windows::Forms::Form::DialogResult'
    see declaration of 'System::Windows::Forms::Form::DialogResult'
    error C2065: 'Yes' : undeclared identifier

    Finally I try with the whole namespace (is that the right terminology ?) and it compiles:

    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 ?


    Friday, November 11, 2005 3:09 PM

Answers

  • 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
    Tuesday, December 13, 2005 8:34 PM

All replies

  • 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
    Tuesday, December 13, 2005 8:34 PM
  • Hi, 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.
    Saturday, July 01, 2006 12:06 PM
  • 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().

     

    Thursday, October 19, 2006 2:04 AM
  • 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

    Sunday, November 12, 2006 12:11 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

    Monday, November 13, 2006 8:16 PM
  • #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.
    Tuesday, January 16, 2007 2:45 AM
  • I 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:Big SmileialogResult:SurpriseK 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 :Big SmileialogResult:SurpriseK 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!

    Wednesday, March 28, 2007 10:18 PM
  • in visual c++ express try
    Code Snippet

    System::Windows::Forms::DialogResult::OK instead of DialogResult::OK


    it worked for me
    Thursday, July 26, 2007 4:09 AM
  • great System::Windows::Forms:Big SmileialogResult:SurpriseK worked instead of DialogResult:SurpriseK 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.
    Monday, May 12, 2008 8:07 PM
  • 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 == :Big SmileialogResult::Yes ){
    }

    }

    ************************************

    *** THIS FIXES THE PROBLEM ***


    using namespace
    System;
    using namespace System::Windows::Forms;


    namespace myApp {

    if ( result == :Big SmileialogResult::Yes ){
    }


    }

    *****************************

    • Proposed as answer by Clay L Friday, May 29, 2009 10:03 PM
    Tuesday, October 14, 2008 4:43 AM
  • Joe58,

    Thanks!!

    Solved the problem for me.

    Clay L
    Friday, May 29, 2009 10:05 PM
  • thanks ,your imformation is right.
    move the internal namespace out of your local namespace, it works.


    MSN:h2zy@hotmail.com
    Thursday, January 28, 2010 1:41 AM
  • Thanks 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
    Monday, September 03, 2012 10:49 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);
       
        }
    }

    Friday, November 23, 2012 12:53 PM