Author Topic: simple messagebox with asm  (Read 3914 times)

0 Members and 1 Guest are viewing this topic.

Offline Frank Brübach

  • Full Member
  • ***
  • Posts: 109
simple messagebox with asm
« on: January 27, 2012, 10:36:45 AM »
here's a little example how to program a messagebox with pb inline assembler code :)

Code: [Select]
#COMPILE EXE
#DIM ALL

#INCLUDE "windows.inc" '"Win32API.inc"

FUNCTION PBMAIN () AS LONG
    DIM hWnd AS LONG, tAdr AS LONG, mAdr AS LONG, temp AS LONG
    DIM msg AS ASCIIZ * 32, titl AS ASCIIZ * 32
    DIM funcAddr AS DWORD

    hWnd = LoadLibrary ("user32")
    msg = "Hello, dear powerbasic world!"
    titl = "Example with messagebox_asm"
    IF ISTRUE (hWnd) THEN
       funcAddr = GetProcAddress (hWnd, "MessageBox")
        IF ISTRUE (funcAddr) THEN
            ! push 0
            ! lea eax, msg ;' mAdr = VARPTR(msg)
            ! push eax
            ! lea eax, titl ;' tAdr = VARPTR(titl)
            ! push eax
            ! push tAdr
            ! push 0
            ! push mAdr
            ! push 0
            CALL DWORD funcAddr
        ELSE
            GOTO epicFail
        END IF
    ELSE
        GOTO epicFail
    END IF

    GOTO getMeOuttaHere

epicFail:
    MSGBOX msg, , titl

getMeOuttaHere:
    IF ISTRUE(hWnd) THEN
        temp = FreeLibrary (hWnd)
        IF ISFALSE(temp) THEN MSGBOX "Error freeing library... [shrug]"
    END IF
END FUNCTION

hello steve, do you know if it's also possible to convert "CALL DWORD funcAddr" with asm ? best regards, frank
« Last Edit: January 27, 2012, 10:39:07 AM by Frank Brübach »

Offline Frank Brübach

  • Full Member
  • ***
  • Posts: 109
Re: simple messagebox with asm
« Reply #1 on: January 27, 2012, 01:38:14 PM »
I've found the solution for converting "CALL DWORD funcAddr" with

Code: [Select]
  ! mov eax,funcAddr
            ! call funcAddr
            'CALL DWORD funcAddr

so the code example above works correct with

Code: [Select]
#COMPILE EXE
#DIM ALL

#INCLUDE "windows.inc" '"Win32API.inc"

FUNCTION PBMAIN () AS LONG
    DIM hWnd AS LONG, tAdr AS LONG, mAdr AS LONG, temp AS LONG
    DIM msg AS ASCIIZ * 32, titl AS ASCIIZ * 32
    DIM funcAddr AS DWORD

    hWnd = LoadLibrary ("user32")
    msg = "Hello, dear powerbasic world!"
    titl = "Example with messagebox_asm"
    IF ISTRUE (hWnd) THEN
       funcAddr = GetProcAddress (hWnd, "MessageBox")
        IF ISTRUE (funcAddr) THEN
            ! push 0
            ! lea eax, msg ;' mAdr = VARPTR(msg)
            ! push eax
            ! lea eax, titl ;' tAdr = VARPTR(titl)
            ! push eax
            ! push tAdr
            ! push 0
            ! push mAdr
            ! push 0
            ! mov eax,funcAddr
            ! call funcAddr
            'CALL DWORD funcAddr
        ELSE
            GOTO epicFail
        END IF
    ELSE
        GOTO epicFail
    END IF

    GOTO getMeOuttaHere

epicFail:
    MSGBOX msg, , titl

getMeOuttaHere:
    IF ISTRUE(hWnd) THEN
        temp = FreeLibrary (hWnd)
        IF ISFALSE(temp) THEN MSGBOX "Error freeing library... [shrug]"
    END IF
END FUNCTION

btw: this code is antique, I have converted this from a old assembler website (including some explanations between basic programming languages) just for fun. Normally I don't like "goto's" :)

regards, frank