Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

----- error C2653: 'MessageBoxA' : is not a class or namespace name ------

 

I included all the correct .NET references in my project, but somehow it doesn't distinguish between the Windows version and the .NET version.

Posted

I'm trying to display an error message using

System::Windosw::Forms::MessageBox::Show();

 

These are my headers:

 

using namespace System;

using namespace System::IO;

using namespace System::Data;

using namespace System::Text;

using namespace System::Windows::Forms;

using namespace System::Collections;

 

/// -----------------------------------------------------------------------

///<summary> Creates a new file in the given path or current directory

/// -----------------------------------------------------------------------

static void CreateNewFile( String* filename, String* text, bool overwrite )

{

StreamWriter* streamWriter;

 

// Check to see if the user is writing over an existing file.

if (File::Exists(filename) && !overwrite)

{

if (MessageBox::Show(S"That file exists. Would you like to overwrite it?", S"File Overwrite?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == DialogResult::No)

{

// Leave the subroutine

return;

}

}

 

// The StreamWriter must be defined outside of the try-catch block

// in order to reference it in the __finally block.

// Ensure that the creation of the new StreamWriter is wrapped in a

// try-catch block, since an invalid filename could have been used.

try

{

Shared (static) File class.

streamWriter = File::CreateText(filename);

 

// Write the entire contents of the text

// to the StreamWriter in one shot.

streamWriter->Write(text);

streamWriter->Flush();

}

catch (Exception* exc)

{

// Show the error to the user.

MessageBox::Show(String::Concat(S"File could not be created or written to.\r\nPlease verify that the filename is correct, and that you have read permissions for the desired directory.\r\n\r\nException: ", exc->Message), S"File Error", MessageBoxButtons::OK, MessageBoxIcon::Error);

}

__finally

{

// Close the object if it has been created.

if (streamWriter)

streamWriter->Close();

}

};

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...