#include "kernel32.as"
#const TRUE 1
#const FALSE 0
#const NULL 0
#const SIZE_SEC_ATTR 12
#const DUPLICATE_SAME_ACCESS 0x02
#const SIZE_SUP_INFO 68
#const STARTF_USESHOWWINDOW 0x00000001
#const STARTF_USESTDHANDLES 0x00000100
#const SW_HIDE 0
#const DEF_HSTDOUT 7
#const DEF_HSTDERR 11
#define NAME_CONAPP "cb.exe"
#const SIZE_BUF 1024
#const ERR_WRITEFILE 0
notesel data
noteload "main.hsp"
secattr = SIZE_SEC_ATTR, NULL, TRUE
CreatePipe varptr(hread), varptr(hwrite), varptr(secattr), 0
if (stat = FALSE) {
dialog "パイプの作成に失敗しました。スクリプトを終了します。", 1, "エラー"
end
}
GetCurrentProcess
hself = stat
DuplicateHandle hself, hwrite, hself, NULL, 0, FALSE, DUPLICATE_SAME_ACCESS
cmdline = NAME_CONAPP
supinfo = SIZE_SUP_INFO, NULL, NULL, NULL
supinfo(4) = 0, 0, 0, 0
supinfo(8) = 0, 0, NULL, STARTF_USESTDHANDLES
supinfo(12) = SW_HIDE, 0, hread, DEF_HSTDOUT, DEF_HSTDERR
dim procinfo, 4
CreateProcessA NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, varptr(supinfo), varptr(procinfo)
result = stat
CloseHandle hread
if (result = 0) {
dialog (NAME_CONAPP + "の起動に失敗しました。スクリプトを終了します。"), 1, "エラー"
CloseHandle hwrite
end
}
CloseHandle procinfo(0)
CloseHandle procinfo(1)
len = strlen(data)
loopcnt = (len / SIZE_BUF)
if ((len \ SIZE_BUF) ! 0) {
loopcnt ++
}
idx = 0
size = 0
repeat loopcnt
sdim buf, (SIZE_BUF + 1)
if (cnt = (loopcnt - 1)) {
memcpy buf, data, (len - idx), 0, idx
}
else {
memcpy buf, data, SIZE_BUF, 0, idx
idx += SIZE_BUF
}
WriteFile hwrite, buf, strlen(buf), varptr(size), NULL
if (stat = ERR_WRITEFILE) {
break
}
await 1
loop
nullchar = ""
WriteFile hwrite, nullchar, 1, varptr(size), NULL
CloseHandle hwrite
end
|