News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Putting icz3 into a dll. I'm having fun now.

Started by ThoughtCriminal, October 04, 2009, 03:53:44 AM

Previous topic - Next topic

ThoughtCriminal

I wondered for a while now if putting the basic code for a window in a dll would work. I've wondered why do I always have to scroll past this stuff. Now  make a window with just one call.  It would take a little more work to make the window accept new parameters, but it could be done. I would post the dll but the board does not seem to allow it unless I have an off site place to put it. I don't.

Based of the MASM32 dll example:

    .386
    .model flat, stdcall
    option casemap :none   ; case sensitive

; #########################################################################

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

; #########################################################################
externdef begin :NEAR
WinMain proto :DWORD, :DWORD, :DWORD, :DWORD
;WndProc proto :DWORD, :DWORD, :DWORD, :DWORD this does not need to be protoed

.data
ClassName db "SimpleWinClass",0
AppName  db "Our First Window",0

.data?
hInstance dd ?
CommandLine dd ?

.code

; ##########################################################################

LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD

mov eax,1
        ret

LibMain Endp

; ##########################################################################

begin:

invoke GetModuleHandle, NULL
mov    hInstance,eax
invoke GetCommandLine
mov    CommandLine,eax
invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
invoke ExitProcess, eax

WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov   wc.cbSize, SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra, NULL
mov   wc.cbWndExtra, NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground, COLOR_WINDOW+1
mov   wc.lpszMenuName, NULL
mov   wc.lpszClassName, OFFSET ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov   wc.hIcon, eax
mov   wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov   wc.hCursor, eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
mov   hwnd, eax

invoke ShowWindow, hwnd, SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg, NULL, 0, 0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov     eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg==WM_DESTROY
invoke PostQuitMessage, NULL
.else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.endif
xor eax,eax
ret
WndProc endp

; ##########################################################################

End LibMain

my quick test program:

       .386
    .model flat, stdcall
    option casemap :none   ; case sensitive

; #########################################################################

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

; #########################################################################

.data

dlltoload db "winmaindll.dll",0
ProcName1 db "begin",0
ProcName2 db "WndProc",0
seax dd 0

.code
start:

nop
nop
invoke LoadLibrary, ADDR dlltoload
mov seax, eax
Invoke GetProcAddress, eax, ADDR ProcName1
call eax
nop
nop

end start