设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1984|回复: 7
打印 上一主题 下一主题

[已经解决] 请问API函数createthread怎么使用啊

[复制链接]

Lv4.逐梦者

梦石
0
星屑
13559
在线时间
2753 小时
注册时间
2014-10-4
帖子
756

R考场第七期纪念奖

1
发表于 2019-9-28 23:50:17 | 显示全部楼层
本帖最后由 SixRC 于 2019-9-29 11:47 编辑

C 代码复制
  1. #include <windows.h>
  2. #include <stdio.h>
  3. int __stdcall hi(int i) {
  4.         Sleep(i * 80);
  5.         printf("hi %d\n", i);
  6.         return 0;
  7. }
  8.  
  9. int main() {
  10.         for (int i = 0; i < 10; i++) {
  11.                 CloseHandle(CreateThread(0, 0, (LPTHREAD_START_ROUTINE)hi, i, 0, 0));
  12.         }
  13.         Sleep(1000);
  14.         getchar();
  15.         return 0;
  16. }

感觉已经忘记怎么写代码了..
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
13559
在线时间
2753 小时
注册时间
2014-10-4
帖子
756

R考场第七期纪念奖

2
发表于 2019-9-29 12:08:08 | 显示全部楼层

RUBY 代码复制
  1. u = Win32API.new("kernel32", "GetModuleHandleA", "p", "l").call("user32")
  2. m = Win32API.new("kernel32", "GetProcAddress", "lp", "l").call(u, "MessageBoxA")
  3. func = [0x8B, 0x4C, 0x24, 0x04,
  4.         0x31, 0xC0, 0x50, 0x50, 0x51, 0x50, 0xB8].pack("C*") +
  5.        [m].pack("l") +
  6.        [0xFF, 0xD0, 0xC2, 0x04, 0x00].pack("C*")
  7. =begin
  8.   mov ecx, [esp+4] 参数 i.to_s
  9.   xor eax,eax
  10.   push eax
  11.   push eax
  12.   push ecx
  13.   push eax
  14.   mov eax,MessageBoxA
  15.   call eax  0,text,0,0
  16.   ret 4
  17. =end
  18. c = Win32API.new("kernel32", "CreateThread", "llppll", "v")
  19. for i in 0...5
  20.   c.call(0, 0, func, i.to_s, 0, 0)
  21. end
  22. loop{Graphics.update}

道理还是一样的
但是新线程的函数不能是ruby函数 因为机制不一样
得先编译好
汇编毕竟麻烦

评分

参与人数 2星屑 +100 +1 收起 理由
VIPArcher + 100 认可答案
灰太狼与喜羊羊 + 1 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-5 12:39

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表