本帖最后由 ceoguang 于 2013-1-6 11:40 编辑
另外,lz如果觉得刚才的回答有些憋屈,给段代码过过目,觉得过瘾否?
netegg 发表于 2013-1-4 00:23
蛋,人家是来踩场子的。要示例的话无需调用第三方辅助,内置函数就足够了
下面的例子就是全内置函数实现的多线程messagebox
#region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_UseX64=n
#PRE_Res_requestedExecutionLevel=None
#endregion ;**** 参数创建于 ACNWrapper_GUI ****
Main()
Func Main()
Const $dwThreads = 300;将创建300个线程,配置不好就别玩了
Local $pMessageBoxW = GetProcAddress(GetModuleHandle('User32'), 'MessageBoxW')
Local $pMessageBoxCode = Hex(Binary($pMessageBoxW))
Local $pData[24] = [0x55, 0x8B, 0xEC, 0x6A, 0x00, 0x6A, 0x00, 0x6A, 0x00, 0x6A, 0x00, 0xB8,Number('0x' & StringMid($pMessageBoxCode, 1, 2)), Number('0x' & StringMid($pMessageBoxCode, 3, 2)), Number('0x' & StringMid($pMessageBoxCode, 5, 2)), Number('0x' & StringMid($pMessageBoxCode, 7, 2)),0xff, 0xd0, 0x33, 0xC0, 0x5D, 0xC2, 0x04, 0x00]
Local $tBuffer = DllStructCreate('char[24]')
For $i = 1 To 24
DllStructSetData($tBuffer,1,$pdata[$i-1],$i)
Next
Local $dwThreadId,$hThread
For $x = 1 To $dwThreads
$hThread = CreateThread(DllStructGetPtr($tBuffer),0,$dwThreadId)
ConsoleWrite(StringFormat('第:%d 个线程创建,线程ID:%d\n',$x,$dwThreadId))
CloseHandle($hThread)
Next
MsgBox(64,'线程创建完成','请在任务管理器中查看本进程的线程数' &@LF & '注意:此提示框仅用于避免主线程退出')
EndFunc ;==>Main
Func CreateThread($lpStartAddress, $lpParameter, ByRef $lpThreadId, $dwCreationFlags = 0)
Local $aRet = DllCall('Kernel32.dll', 'HANDLE', 'CreateThread', 'ptr', 0, 'ULONG_PTR', 0, 'ptr', $lpStartAddress, 'ptr', $lpParameter, 'dword', $dwCreationFlags, 'dword*', 0)
If @error Then Return SetError(@error, @extended, 0)
If $aRet[0] = 0 Then Return SetError(-1, 0, 0)
$lpThreadId = $aRet[6]
Return $aRet[0]
EndFunc ;==>CreateThread
Func CloseHandle($hHandle)
Local $aResult = DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hHandle)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0]
EndFunc ;==>_WinAPI_CloseHandle
Func GetModuleHandle($lpModuleName)
Local $aRet = DllCall('Kernel32.dll', 'HANDLE', 'GetModuleHandleW', 'wstr', $lpModuleName)
If @error Then Return SetError(@error, @extended, 0)
If $aRet[0] = 0 Then Return SetError(-1, 0, 0)
Return $aRet[0]
EndFunc ;==>GetModuleHandle
Func GetProcAddress($hModule, $lpProcName)
Local $aRet = DllCall('Kernel32.dll', 'ptr', 'GetProcAddress', 'HANDLE', $hModule, 'str', $lpProcName)
If @error Then Return SetError(@error, @extended, 0)
If $aRet[0] = 0 Then Return SetError(-1, 0, 0)
Return $aRet[0]
EndFunc ;==>GetProcAddress
补上附件,messagebox加入了标题和内容 |