Much better now. In the Project Properties, I set Configuration
Properties/General/Character Set to "Not Set", which apparently means
normal character strings. The only choices are Not Set, Unicode, and
MultiByte. Not Set sounds bad, but I guess that's what I want. Works
much better, I get to code like I expect.
Now, I am struggling to understand their use of the System::
constructs. This is the Option 1 method of calling the MessageBox.
I added a Windows Form to my project, for use in making a properties
dialog. I now have two files, Settings.cpp (for the dialog) and
Brew.cpp (the main set of methods), with their associated .h files.
Settings.h (summarized)
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
namespace Brew {
public ref class Settings : public System::Windows::Forms::Form
{
public:
Settings(void)
{
InitializeComponent();
}
...
private: System::Void OK_Click(System::Object^ sender,
System::EventArgs^ e) {
// What the? This works here
MessageBox::Show("I think it Worked.",
"Settings Applied", MessageBoxButtons::OK,
MessageBoxIcon::Asterisk);
}
};
}
Note that in this code, the Option 1 method of MessageBox works. The
Option 3 code does NOT work.
Now, in Brew.cpp I have
#include "stdafx.h"
#include "DlgSettings.h"
#include "Brew.h"
...
int CCamAPIDll::CCSettings(const enumZZCAM2& Camera, const
enumWhichCCD2& CCD)
{
// This one works fine
MessageBox (NULL,"These are my Settings", "Title",
MB_ICONEXCLAMATION);
// This one does not compile
//MessageBox::Show("The calculations are complete",
// "My Application", MessageBoxButtons::OKCancel,
// MessageBoxIcon::Asterisk);
DlgSettings dlg;
dlg.Show;
return S_OK;
}
Note that in this case, the Option 1 method will not compile, but the
Option 3 method works fine.
I need to understand this, because the Brew.cpp code does not compile
correctly - the include of Settings.h generates the same types of
error as the MessageBox::Show call. It doesn't seem to know about the
System namespace or something.
Brew.cpp compile errors, generated when it hits the namespace
statements in Settings.h;
: error C2871: 'System' : a namespace with this name does not exist
: error C2653: 'System' : is not a class or namespace name
: error C2871: 'ComponentModel' : a namespace with this name does not
exist
: error C2653: 'System' : is not a class or namespace name
: error C2871: 'Collections' : a namespace with this name does not exist
: error C2653: 'System' : is not a class or namespace name
: error C2871: 'Forms' : a namespace with this name does not exist
: error C2653: 'System' : is not a class or namespace name
and so on...
I am thinking I am missing an important include file, or there is some
type of setting on the file? I don't know why Settings.cpp compiles
fine, but Brew.cpp does not.
Thanks for your major help!
brew
--- In [email protected], Thomas Hruska <[EMAIL PROTECTED]> wrote:
>
> robert_brewington wrote:
> > Wow. This is very disheartening, to say the least.
> >
> > Fortunately, I have 35 years programming experience, including 10
> > years with prior versions of Visual C++. This, of course, does not
> > allow me to do the first thing with Visual C++ 2008.
> >
> > I am trying to do something apparently extremely complicated - pop up
> > a messagebox. After 3 hours, I was able to locate sample programs
> > (2008 specific) at the Microsoft site, since the code snippets I find
> > in the help files do not work. The Visual C++ installation did not
> > load any example code.
> >
> > The code in the sample program also does not work, of course. In fact,
> > the sample does not even build (I am looking at something called
polygon).
> >
> > -------------------------------------------------------
> > Option 1 - The help file shows the construct
> >
> > MessageBox::Show("The calculations are complete",
> > "My Application", MessageBoxButtons::OKCancel,
> > MessageBoxIcon::Asterisk);
> >
> > which leads to the errors
> >
> > 1>.\BrewOrion.cpp(222) : error C2653: 'MessageBoxW' : is not a class
> > or namespace name
> > 1>.\BrewOrion.cpp(223) : error C2653: 'MessageBoxButtons' : is not a
> > class or namespace name
> > 1>.\BrewOrion.cpp(223) : error C2065: 'OKCancel' : undeclared
identifier
> > 1>.\BrewOrion.cpp(224) : error C2653: 'MessageBoxIcon' : is not a
> > class or namespace name
> > 1>.\BrewOrion.cpp(224) : error C2065: 'Asterisk' : undeclared
identifier
> > 1>.\BrewOrion.cpp(222) : error C3861: 'Show': identifier not found
> >
> > -------------------------------------------------
> > Option 2: The Polygon sample program uses
> >
> > MessageBox(COLE2T(strError), _T("Error"), MB_ICONEXCLAMATION);
> >
> > which also fails - neither the _T or COLE2T words are recognized.
> >
> > ------------------------------------------
> > Option 3: I did manage to get this construct to pop up a message box:
> >
> > MessageBox (NULL,(LPCWSTR)"Settings", (LPCWSTR)"My
> > Application",MB_ICONEXCLAMATION);
> >
> > Unfortunately, all the strings are in Chinese characters:(
> >
> > I assume that Option 1 needs some sort of include file or namespace
> > specification, although I can't find any reference to anything.
> >
> > Option 2 didn't make any sense to me, since I could not find any spec
> > on MessageBox that looked like this interface.
> >
> > In Option 3, I am assuming LPCWSTR means use Wide Chinese characters?
> > I couldn't come up with another casting type that would compile...
> >
> > Any help on this would be appreciated:)
> >
> > brew
>
> Option 1 is wrong. I've never seen that before. Option 2 is usually
> MFC (fewer parameters than the MSDN Library specification). Option 3
> looks more correct for a straight Win32 API call.
>
> L = Long/Large (IIRC, this is leftover from Win 3.x)
> P = Pointer
> C = Const (constant)
> W = Wide (Unicode)
> STR = String
>
> Or something like that. The first thing I would check is to see if you
> are building a Unicode application. The error message MessageBoxW()
> indicates the compiler is trying to use the Unicode version of
MessageBox().
>
> http://msdn2.microsoft.com/en-us/library/ms645505(VS.85).aspx
>
> _T(...) is a macro that allows you to build the same app. as ANSI or
> Unicode. In a Unicode build, the string "Settings" becomes "Settings"L
> or something like that (I can never remember where the 'L' goes -
before
> or after the quotes) which tells the compiler to guarantee that it
> becomes a valid Unicode string. I don't know why the macro isn't
defined.
>
> The 'T' you'll see in various API calls stands for TCHAR. Depending on
> Unicode vs. non-Unicode builds, LPCTSTR will become LPCWSTR or LPCSTR.
>
> So...to fix the code, I'd try:
>
> MessageBox(NULL, "Settings"L, "My Application"L, MB_ICONEXCLAMATION);
>
> Since _T() isn't available. Although, you may simply wish to drop the
> Unicode build and stick with ANSI for the time being. In which case,
> you can drop the 'L's.
>
> --
> Thomas Hruska
> CubicleSoft President
> Ph: 517-803-4197
>
> *NEW* MyTaskFocus 1.1
> Get on task. Stay on task.
>
> http://www.CubicleSoft.com/MyTaskFocus/
>