• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

simple messagebox with asm

Started by Frank Brübach, January 27, 2012, 10:36:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

here's a little example how to program a messagebox with pb inline assembler code :)

#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

Frank Brübach

I've found the solution for converting "CALL DWORD funcAddr" with

  ! mov eax,funcAddr
            ! call funcAddr
            'CALL DWORD funcAddr


so the code example above works correct with

#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