Author Topic: nsam win32 dialogBox  (Read 17311 times)

Offline ej3989

  • Jr. Member
  • *
  • Posts: 3
nsam win32 dialogBox
« on: August 25, 2011, 02:30:57 AM »
hi..
I want to make dialogbox
but i see error message about "don't find Dll start point"
I didn't attact two files win002_1.asm, win002_1.rc
so I ctrl+v sorce  below ===


win002_1.asm
================
Code: [Select]
%include "win32n.inc"
IDD_DLG1 equ 1000
IDC_BTN1 equ 1001

MSGhWnd   equ 0
MSGmsg    equ 4
MSGwParam equ 8
MSGlParam equ 12


EXTERN GetModuleHandleA
IMPORT GetModuleHandleA Kernel32.dll
EXTERN DialogBox
IMPORT DialogBox user32.dll
EXTERN MessageBoxA
IMPORT MessageBoxA user32.dll


section .data USE32

mywindowinstance dd 0

section .code USE32
..start

push dword 0
call [GetModuleHandleA]
mov [mywindowinstance], eax

push dword mydialog
push dword 0
push dword IDD_DLG1
push dword [mywindowinstance]
call [DialogBox]

mydialog:
cmp dword [esp+4+MSGwParam],1001
je testout

testout:
push dword MB_OK
push ecx
push dword textinside
push dword [mywindowinstance]
call [MessageBoxA]
ret 16



section .data USE32
textinside db "TEST BOX",0
================


win002_1.rc
==============
Code: [Select]
#define IDD_DLG1 1000
#define IDC_BTN1 1001

Nuke ICON DISCARDABLE "BIRNE.ICO"
AppIcon ICON DISCARDABLE "MEINICON.ICO"
Fisch CURSOR DISCARDABLE "CURSOR.CUR"

IDD_DLG1 DIALOGEX 10,10,150,100
CAPTION "IDD_DLG"
FONT 8,"MS Sans Serif",0,0,0
STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW
BEGIN
  CONTROL "IDC_BTN",IDC_BTN1,"Button",WS_CHILD|WS_VISIBLE|WS_TABSTOP,15,21,39,15
END
=============
« Last Edit: August 25, 2011, 05:19:55 AM by Frank Kotler »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: nsam win32 dialogBox
« Reply #1 on: August 25, 2011, 07:18:29 AM »
Hi ej3989,

I edited your post to put "code tags" around your code. Just put the word "code" in square brackets ("[]" - like a Nasm memory reference) at the beginning of your code, and "/code" (in "[]"s) at the end. Not a big deal, but we like "code tags" around this Forum, so please humor us and use 'em, if you would.

Having said that, I don't know much about Windows programming, and don't have an answer to your question. When do you see this error message? I'm pretty sure it isn't from Nasm. From the linker? (Alink?) Or when you try to run it?

I don't know Windows, but "code is code" (so I keep claiming), and there are a couple of things about your code that look "funny" to me. I don't think it's causing your problem, but I'll point it out anyway...

Code: [Select]
cmp dword [esp+4+MSGwParam],1001
je testout

testout:

You compare a parameter on your stack to 1001. If it compares equal, you jump to "testout:". If it doesn't compare equal, you "fall through" to "testout:". It doesn't make much sense to me do do a comparison and do the same thing either way. I suspect that maybe you want to pop up that messagebox if it is 1001, and... just "ret" without doing anything if it isn't? You equate "IDC_BTN1" to 1001. You might want to use IDC_BTN1 here instead if the raw number. Just a matter of "style" (exactly the same code), but what's the point of the equate if you're not going to use it?

Just before that...

Code: [Select]
call [DialogBox]

mydialog:

You've pushed "mydialog" as a parameter to "DialogBox". When DialogBox returns (if it does - not all APIs do), you're going to "fall through" and execute "mydialog" (again?). I doubt if you want to do that. I suspect you want an ExitProcess in there. You'll need to "extern" and "import" it like the others (I think it's in kernel32.dll). Takes one parameter, zero usually indicates success...

Code: [Select]
      call [DialogBox]

      push 0
      call [ExitProcess]

mydialog:

ExitProcess doesn't return. If DialogBox doesn't return either, my mistake. Shouldn't hurt.

One thing I remember from my very limited experience with Windows...

Code: [Select]
section .code USE32

That worked, but when I ran it in Ollydbg I got a message (Just a warning, I think, not an error) about "entrypoint outside of code segment" or so. Doing:

Code: [Select]
section .code USE32 class=CODE

used to shut Ollydbg up. Might do something useful, didn't seem to hurt...

Hopefully a real Windows programmer will be along and give you an actual answer to your problem. Good luck with it!

Best,
Frank


Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: nsam win32 dialogBox
« Reply #2 on: August 25, 2011, 03:13:44 PM »
In addition to Frank's analysis:
Code: [Select]
    push ecx
is an uninitialized pointer for the MessageBox caption.  You'll want to ensure it contains a valid address.

Also, "don't find Dll start point" implies that the linker is having difficulty locating the dll entry point.  It may be that you are not supplying the appropriate .lib file for the functions you use for your linker.  One of the main reasons NASMX uses Jeremy Gordon's GoLink program is because it locates all those Windows dll function entry points for you automagically.  You might want to check them out.

Offline Mathi

  • Jr. Member
  • *
  • Posts: 82
  • Country: in
    • Win32NASM
Re: nsam win32 dialogBox
« Reply #3 on: August 25, 2011, 10:53:21 PM »
To list out the issues

- DialogBoxParamA is the function which is there in user32.dll  (has one more parameter - 5th param passed as null)
- MessageBoxA has the first parameter as the parent window handle and not the appInstance (passed 0 )
- In the MyDialog callback procedure.. we need to return 0(set eax to 0) if we are not processing the message.
- Handle the WM_CLOSE message and exit out of the Application ( I thought this would happen automatically)

Made some Modifications to the code..


Code: [Select]
%include "win32n.inc"
IDD_DLG1 equ 1000
IDC_BTN1 equ 1001

MSGhWnd   equ 0
MSGmsg    equ 4
MSGwParam equ 8
MSGlParam equ 12


EXTERN GetModuleHandleA
IMPORT GetModuleHandleA Kernel32.dll
EXTERN DialogBoxParamA                  ; here
IMPORT DialogBoxParamA user32.dll       ; here
EXTERN MessageBoxA
IMPORT MessageBoxA user32.dll
EXTERN ExitProcess
IMPORT ExitProcess kernel32.dll

section .data USE32

mywindowinstance dd 0

section .code USE32
..start

push dword 0
call [GetModuleHandleA]
mov [mywindowinstance], eax

push dword 0                  ; here
push dword mydialog
push dword 0
push dword IDD_DLG1
push dword [mywindowinstance]
call [DialogBoxParamA]

mydialog:
cmp dword [esp+4+MSGwParam],1001
je testout

cmp dword [esp+4+MSGmsg], WM_CLOSE
je exitout

jmp returnback

exitout:
push dword 0
call [ExitProcess]
jmp returnback

testout:
push dword MB_OK
push dword textinside  ; here
push dword textinside
push dword 0           ; here
call [MessageBoxA]
returnback:
mov eax, 0
ret 16



section .data USE32
textinside db "TEST BOX",0

Resource file remains the same.

I used nasm , gorc and alink to generate the exe.

PFB the commands (I am assuming the icons and cursor files were there in the same directory . though not needed in this program)

Code: [Select]
nasm -fobj Dialog.asm
gorc /r Dialog.rc
alink -c -oPE -subsys gui Dialog Dialog.res


Offline ej3989

  • Jr. Member
  • *
  • Posts: 3
Re: nsam win32 dialogBox
« Reply #4 on: August 26, 2011, 01:00:49 AM »
Frank Kotler, Rob Neff, Mathi
Thank you for your helping
I understand many thing about nasm win32 program, this time.
so I have one question to Mathi
i use nasm, gorc and alink too.
 - why do i use dialogboxA in user32.dll??
Correctly Golink(Rob Neff recommended) compile dialogBoxA in user32.dll
but alink does not.
It's simply diffrent linker.
Doesn't alink  use dialogBoxA ?


how do i find function that Alink operate in kernel32.dll,user32.dll .... "


Offline Mathi

  • Jr. Member
  • *
  • Posts: 82
  • Country: in
    • Win32NASM
Re: nsam win32 dialogBox
« Reply #5 on: August 26, 2011, 02:45:29 AM »
Honestly, i don't know the answer for this.
i suggested that because i have use that before and it has worked for me.

May be someone can help us here.

I am guessing some alias for the win32api functions.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: nsam win32 dialogBox
« Reply #6 on: August 26, 2011, 03:58:40 AM »
I was going to make a little joke about "nsam", pointing out that in the source, things need to be spelled right. Sometimes case-sensitive! I suspect that "dialogbox" (in any form) won't work - you need "DialogBox" ("DialogBoxA" or "DialogBoxParamA")...

This documentation:

http://msdn.microsoft.com/en-us/library/ms645452(v=vs.85).aspx

makes reference to "DialogBox" being a macro. Doesn't say where this macro exists, but perhaps you don't have it. I suspect that the "true name" is "_DialogBoxParamA@16" or so. Some toolsets will "simplify" the name for you, others won't. I think that's what you're up against...

Best,
Frank


Offline ej3989

  • Jr. Member
  • *
  • Posts: 3
Re: nsam win32 dialogBox
« Reply #7 on: August 26, 2011, 09:33:39 AM »
thank you!:)
I understand DialogBoxA doesn't operate in source. I didn't think DialogBox is macro.
thank you!!!!