How do I fix this....

Grasshopper-NET

Newcomer
Joined
Mar 12, 2006
Messages
18
----- 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.
 
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();
}
};
 
Could this be contributing? I think there is also a knowledge base article on the subject but I couldn't find a link.
 
Back
Top