Inline Assembly MessageBox Problem

Just starting out? Need help? Post your questions and find answers here.
Logman
User
User
Posts: 33
Joined: Sun Oct 12, 2008 5:42 pm
Location: Virginia, USA

Inline Assembly MessageBox Problem

Post by Logman »

Greetings:

Before the PureBasic site switched over to this new format, I read a thread by either srod, Chris, El_Choni, or blueznl, I can't recall who, but I can't find it again.

My problem is that I copied the example inline assembly code from their thread into a sample program on my 64-bit Windows system, compiled it using PureBasic 4.4 Beta, and it worked perfectly.

However, I copied the same code onto my 32-bit XP system at work and it doesn't display the message box when I compile it using PureBasic 4.31. Here's the code. Can anyone recall from the past forum what's wrong with the code below? Why won't the message box appear on screen?

Code: Select all

EnableASM
DisableDebugger

! EXTRN "__imp__MessageBoxA@16" As MessageBox:dword

PUSH 1
PUSH _caption
PUSH _message
PUSH 0
CALL [MessageBox]

end

! _caption db "Win32 Assembly",0
! _message db "Hi! I am a sample program!",0
Like I said, it works perfectly on my 64-bit Vista system, but not on my 32-bit XP system.

Also, the following code works on my Vista system when I substitute PB variables instead of FASM variables:

Code: Select all

EnableASM
DisableDebugger

caption.s = "Win32 Assembly"
message.s = "Hi! I am a sample program!"

! EXTRN "__imp__MessageBoxA@16" As MessageBox:dword

PUSH 1
PUSH caption
PUSH message
PUSH 0
CALL [MessageBox]

End
Not sure what's going on here, but when I inserted a PB MessageRequester() procedure in the code to see if I could get a message box to appear, both boxes showed up on screen. This has me thoroughly baffled. Curious indeed.

Code: Select all

EnableASM
DisableDebugger

caption.s = "Win32 Assembly"
message.s = "Hi! I am an example program!"

! EXTRN "__imp__MessageBoxA@16" As MessageBox:dword

PUSH 1
PUSH caption
PUSH message
PUSH 0
CALL [MessageBox]

MessageRequester(caption, message, 1)

End
Apparently, on my 32-bit XP system, something is missing that would seem to trigger the message box to appear on screen, which by including MessageRequester() seems to add the trigger mechanism. I just can't figure out what's going on here. Not sure if it has anything to do with PB version 3.1 versus 4.4 beta or Vista versus XP or something else.

Additionally, on my 32-bit XP system I can jump over the MessageRequester() procedure in order to get only the inlineASM MessageBox to appear on screen:

Code: Select all

EnableASM
DisableDebugger

caption.s = "Win32 Assembly"
message.s = "Hi! I am an example program!"

! EXTRN "__imp__MessageBoxA@16" As MessageBox:dword

 PUSH 1
 PUSH caption
 PUSH message
 PUSH 0
 CALL [MessageBox]
 JMP l_stop

MessageRequester(caption, message, 2)

Stop:
End
This is driving me crazy.:? Any hints that would resolve this dilemma would be greatly appreciated--thanks in advance.

Logman
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Inline Assembly MessageBox Problem

Post by netmaestro »

Code: Select all

EnableASM
DisableDebugger

! EXTRN "__imp__InitCommonControlsEx@4" as InitCommonControls:dword
! EXTRN "__imp__MessageBoxA@16" As MessageBox:dword

PUSH 1
PUSH _caption
PUSH _message
PUSH 0
CALL [MessageBox]

End

! _caption db "Win32 Assembly",0
! _message db "Hi! I am a sample program!",0
Pls note:
The import is all that's necessary, you don't have to call it. Also, if your application uses a window at all, this wouldn't be needed as PureBasic does the import if there's an OpenWindow() anywhere in your code.
BERESHEIT
Logman
User
User
Posts: 33
Joined: Sun Oct 12, 2008 5:42 pm
Location: Virginia, USA

Re: Inline Assembly MessageBox Problem

Post by Logman »

Thanks netmaestro:

Your code works great!

I was just using the code as a standalone program without any other window being opened. I really appreciate the help as it was driving me nuts. I guess that by opening a PB MessageRequester() window I was inadvertently providing the mechanism in PB to show the inlineASM messagebox on screen. Not yet being as familiar as I need to be with Win32, I just couldn't figure out what I was missing.

By the way, that was a pretty insightful solution. You must really know your stuff--your input makes this forum extremely valuable! Thanks. :D

Logman
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Inline Assembly MessageBox Problem

Post by netmaestro »

Thanks, but I really don't know anything. It's just one of the vast multitude of mistakes I've made before :wink:
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Inline Assembly MessageBox Problem

Post by srod »

netmaestro wrote:Thanks, but I really don't know anything. It's just one of the vast multitude of mistakes I've made before :wink:
Aye, I gave up trying to keep count of them all some years ago! :wink:
I may look like a mule, but I'm not a complete ass.
Logman
User
User
Posts: 33
Joined: Sun Oct 12, 2008 5:42 pm
Location: Virginia, USA

Re: Inline Assembly MessageBox Problem

Post by Logman »

Quick follow-up:

I know you coding geniuses don't hear it often, but we "new to PB" folks certainly appreciate your quick and appropriate responses to our questions. Most of the time we spend countless hours searching for a solution because we do not yet have the experience level to know where the answer lies and don't want to embarrass ourselves on this forum by asking. Sure enough, we eventually must seek out the answer here. Then, like magic, with what seems only a blink of an eye, one of you pops in with a great solution.

Your solutions of course lead us to delve deeper into PB code, manuals, and other resources, which more likely than not leads to more questions.

Without experts like srod, netmaestro, kale, blueznl, trond, rings, el_choni, and51, freak, et. al, most of us wouldn't be enjoying PB as much as we do. So, thanks once again and stay with it. You are training and mentoring the next generation of PB coders.

Logman
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Inline Assembly MessageBox Problem

Post by srod »

Logman wrote:Without experts like srod, netmaestro, kale, blueznl, trond, rings, el_choni, and51, freak, ...
Logman
What, that bunch of wasters? They sit around all day scratching their butts and shoving donuts down their necks!

:twisted:

Ahh, we were all newbies once upon a time and I know less now than when I started!
I may look like a mule, but I'm not a complete ass.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Inline Assembly MessageBox Problem

Post by c4s »

Logman wrote:Quick follow-up:

I know you coding geniuses don't hear it often, but we "new to PB" folks certainly appreciate your quick and appropriate responses to our questions. Most of the time we spend countless hours searching for a solution because we do not yet have the experience level to know where the answer lies and don't want to embarrass ourselves on this forum by asking. Sure enough, we eventually must seek out the answer here. Then, like magic, with what seems only a blink of an eye, one of you pops in with a great solution.

Your solutions of course lead us to delve deeper into PB code, manuals, and other resources, which more likely than not leads to more questions.

Without experts like srod, netmaestro, kale, blueznl, trond, rings, el_choni, and51, freak, fluid byte, sparkie, et. al, most of us wouldn't be enjoying PB as much as we do. So, thanks once again and stay with it. You are training and mentoring the next generation of PB coders.

Logman
I know these situations very well so I also want to thank you guys!
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5345
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Inline Assembly MessageBox Problem

Post by Kwai chang caine »

Hello it's again me..the furuncle of the forum :D

Without all my MASTERS and especially SROD, SPARKIE, FLYPE, GNOZAL, IDLE, TsSoft, KIFFY and all the peoples of forums US or Fr, they are a long time that i stop programming :(
I know i know, it's perhaps the more big unhappiness that i don't stop ...for them :lol:
I believe they don't have a little idea of the pleasure and the proud that i have to know all of them 8)

I'm not a woman...with big boobs
But i can say that i love all this HEROES :mrgreen:

I'm not very intelligent too
But all the days, they are here, like superman for help the floor clothe of programming like me.
Never i can thank so much :oops:

No words is enough for make understand, what i feel, when i talk to all this GOD of programming
Have a day a friend like them.....it's a dream, and this day if is exist...i never want awake

Thanks to be born 8)
ImageThe happiness is a road...
Not a destination
Post Reply