2010-10-25 28 views
2

我試圖手動調用RegisterClassEx Windows API而不使用.data節上的WNDCLASS結構,我需要使用push指令創建此結構。在Assembly的RegisterClassEx

請問有人可以幫我嗎?

非常感謝

+0

爲什麼你需要組裝做到這一點? – joni 2010-10-25 11:57:41

+0

@joni:他不需要組裝來完成它。他只是想*在彙編中做到這一點:) – jyz 2010-10-25 12:16:01

+0

作爲其中一種「我很酷 - 因爲我寫的win32/64應用程序在asm只是爲了好玩而且 - 學習一些東西「 - 他們應該能夠自己弄清楚,然後獲得獎章:P – joni 2010-10-25 12:33:41

回答

3

事實上,你可以很容易地做你想做的。你只需要小心地正確計算結構的每個元素的地址。不過這也是一件容易的事...;)

請看看我做的代碼:

WinMain: 
    push ebp 
    mov ebp, esp 
    add esp, -50h 

    push 7F00h 
    push 0h 
    call LoadIconA 

    mov ebx, eax 

    push 7F00h 
    push 0h 
    call LoadCursorA 
    ;eax = return of LoadCursorA 
    ;ebx = return of LoadIconA 

    mov dword ptr ss:[ebp-30h], 30h     ;WNDCLASSEX.cbSize,   dd WNDCLASSEX_size 
    mov dword ptr ss:[ebp-2Ch], 3h     ;WNDCLASSEX.style,   dd CS_VREDRAW + CS_HREDRAW 
    mov dword ptr ss:[ebp-28h], WndProc    ;WNDCLASSEX.lpfnWndProc,  dd WndProc 
    mov dword ptr ss:[ebp-24h], 0h     ;WNDCLASSEX.cbClsExtra,  dd NULL 
    mov dword ptr ss:[ebp-20h], 0h     ;WNDCLASSEX.cbWndExtra,  dd NULL 
    mov dword ptr ss:[ebp-1Ch], 0h     ;WNDCLASSEX.hInstance,  dd NULL 
    mov dword ptr ss:[ebp-18h], ebx     ;WNDCLASSEX.hIcon,   dd return of LoadIconA 
    mov dword ptr ss:[ebp-14h], eax     ;WNDCLASSEX.hIconSm,   dd return of LoadCursorA 
    mov dword ptr ss:[ebp-10h], 06h     ;WNDCLASSEX.hbrBackground, dd COLOR_BTNFACE + 1 
    mov dword ptr ss:[ebp-0Ch], 0h     ;WNDCLASSEX.lpszMenuName,  dd NULL 
    mov dword ptr ss:[ebp-08h], offset WndProc  ;WNDCLASSEX.lpszClassName, dd offset of ClassName 
    mov dword ptr ss:[ebp-04h], ebx     ;WNDCLASSEX.hCursor,   dd return of LoadIconA 

    lea eax,[ebp-30h] 
    push eax 
    call RegisterClassEx 

你只需要調用CreateWindow的前把這個。

任何懷疑只是喊。

PS .:記住的WndProc是你的彙編程序的循環過程

+0

'ss:'不需要 - 它是ebp的默認段寄存器。 – Abyx 2010-11-04 21:46:58

+0

@Abyx:是的我知道,只是澄清:) – jyz 2010-11-05 00:21:55

0

反向結構,轉棧,有效地址的第一個項目,通話 RegisterClassEx,流行結構堆棧。

1
.data 
    wndclass WNDCLASS 
.code 
    push offset wndclass 
    call RegisterClassEx 

你應該推動其抵消,沒有結構本身

對於局部變量,推動其地址

LOCAL wndclass:WNDCLASS 
lea edx, wndclass 
push edx 
call RegisterClassEx