Use MessageBox in Win32 pgm with STL - winuser.h n/g in this context

R

Richard Lionheart

Hi,

I've got a progam which has a half-dozen STL headers and works fine.

I want to use a MessageBox type function. I'm not aware of any STL
thing like that. I tried to use it with the header MSDN says defines
it, winuser.h, but that wrecks things. (There's no winuser.)

I'm not surprised the .h content conflicted with STL, although I'm
using direct.h (for _getcwd) with no conflict.

Any advise would be most welcome.

TIA,
Richard
 
R

Richard Lionheart

Hi Cat,

You were right on! That got past the comile hurdle.

Now comes the DLL hurdle. I got the linker message:
unresolved external symbol __imp__MessageBoxA@16

So I've got two problems:
1. What DLL has that import symbol?
2. How do reference that DLL in the cl command?

I doing command-line builds because Visual Studio.Net threw in a slew
of .Net stuff which I don't know much about while I just wanted to run
a vanilla Win32/STL application.

Any ideas?

Regards,
Richard
 
P

Peter_Julian

| Hi,
|
| I've got a progam which has a half-dozen STL headers and works fine.
|
| I want to use a MessageBox type function. I'm not aware of any STL
| thing like that. I tried to use it with the header MSDN says defines
| it, winuser.h, but that wrecks things. (There's no winuser.)
|
| I'm not surprised the .h content conflicted with STL, although I'm
| using direct.h (for _getcwd) with no conflict.
|
| Any advise would be most welcome.
|
| TIA,
| Richard
|

You are off topic.

However, if you include windows.h then you can simply call ::MessageBox
see Exception::report() below.

#include "tchar.h"
#include <string>
#include <stdexcept>
#include "windows.h"

const int STATUS_FAILURE(-1);
const int STATUS_SUCCESS(0);

class Exception : public std::exception
{
std::string m_origin;
public:
Exception(std::string o, std::string s)
: std::exception(s.c_str()),
m_origin("Error in " + o) { }
virtual ~Exception() { }
/* member functions */
void report() const
{
std::string s(_T("info :\t"));
s += what();
s += "\t";
::MessageBox( 0,
s.data(),
m_origin.data(),
MB_OK | MB_ICONERROR );
} // report()
};

int main()
{
int result = STATUS_FAILURE;
bool condition = false; // false to see messagebox
try
{
if(!condition) // origin info
throw Exception(_T("main()"), _T("condition == false !"));
result = STATUS_SUCCESS;
}
catch (const Exception& e)
{
e.report();
}
return result;
}
 
B

benben

Richard said:
Hi Cat,

You were right on! That got past the comile hurdle.

Now comes the DLL hurdle. I got the linker message:
unresolved external symbol __imp__MessageBoxA@16

So I've got two problems:
1. What DLL has that import symbol?
2. How do reference that DLL in the cl command?

I doing command-line builds because Visual Studio.Net threw in a slew
of .Net stuff which I don't know much about while I just wanted to run
a vanilla Win32/STL application.

Any ideas?

Regards,
Richard

Try link with user32.lib

Regards,
Ben
 
R

Richard Lionheart

Hi benben,
You are off topic.

Why? I'm writing a Win32/STL app. Unfortunately, the most convenient
way I found to do this with Visual Studio .NET throwing a lot of c#
etc. in my way is to use VS as my editor and then running command line
compiles. But that makes debugging more difficult. The easiest I
could think of is MessageBox. But I like your exceptions approach, so
I think I'll adopt it after looking at it more closely.
if you include windows.h then you can simply call ::MessageBox

Thanks for that. Peter Julian posted the library I needed to go along
with windows.h and ::MessageBox.
see Exception::report() below.

Thanks for a correct, working example. It's much appreciated.

Regards,
Richard
 
R

Richard Lionheart

Thanks, that worked great!

BTW, what if anything did you reference to know that the user32
library would satisfy external reference in things declared in
windows.h (assuming that's the case)?

Regards,
Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top