应该将哪个模块实例传递给CreateCursor方法?

时间:2016-03-11 20:17:14

标签: c++ windows winapi win32gui

CreateCursor函数将HINSTANCE作为第一个参数,如下所述: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648385(v=vs.85).aspx

它可以是NULL,但为什么首先需要它?我的猜测是,它可用于查找应用程序主窗口并确定用于创建光标的显示驱动程序。但也许有人有更好的解释?

1 个答案:

答案 0 :(得分:0)

在我的Windows Server 2008 R2系统上,根本不使用句柄。这是反汇编,添加了一些评论:

0:000> u createcursor
USER32!CreateCursor:
00000000`77a40cb4 488bc4          mov     rax,rsp
00000000`77a40cb7 48895808        mov     qword ptr [rax+8],rbx
00000000`77a40cbb 48896810        mov     qword ptr [rax+10h],rbp
00000000`77a40cbf 48897018        mov     qword ptr [rax+18h],rsi
00000000`77a40cc3 48897820        mov     qword ptr [rax+20h],rdi
00000000`77a40cc7 4154            push    r12
00000000`77a40cc9 4881ecc0000000  sub     rsp,0C0h
00000000`77a40cd0 33db            xor     ebx,ebx
0:000> u
USER32!CreateCursor+0x1e:
00000000`77a40cd2 458be1          mov     r12d,r9d
00000000`77a40cd5 418bf8          mov     edi,r8d
00000000`77a40cd8 3bd3            cmp     edx,ebx
00000000`77a40cda 8bf2            mov     esi,edx

;  If xHotSpot is negative, return error
00000000`77a40cdc 0f8c60070100    jl      USER32!CreateCursor+0xb0 (00000000`77a51442)
00000000`77a40ce2 413bd1          cmp     edx,r9d

;  If xHotSpot is greater than nWidth return error
00000000`77a40ce5 0f8f57070100    jg      USER32!CreateCursor+0xb0 (00000000`77a51442)
00000000`77a40ceb 443bc3          cmp     r8d,ebx
0:000> u
USER32!CreateCursor+0x36:

;  If yHotSpot is negative, return error
00000000`77a40cee 0f8c4e070100    jl      USER32!CreateCursor+0xb0 (00000000`77a51442)
00000000`77a40cf4 8bac24f0000000  mov     ebp,dword ptr [rsp+0F0h]
00000000`77a40cfb 443bc5          cmp     r8d,ebp

;  If yHotSpot is greater than nHeight return error
00000000`77a40cfe 0f8f3e070100    jg      USER32!CreateCursor+0xb0 (00000000`77a51442)

;  This LEA overwrites whatever was passed in as the application handle!!!
;  RCX was not saved before this point, so handle is lost
00000000`77a40d04 488d4c2430      lea     rcx,[rsp+30h]
00000000`77a40d09 33d2            xor     edx,edx
00000000`77a40d0b 41b888000000    mov     r8d,88h
00000000`77a40d11 e8828affff      call    USER32!memset (00000000`77a39798)