hinekure_inoviaさんが投稿したコード一覧

HSP 【HSP3】この文法でも動くことに驚いた

// これでも動く驚き
button : gosub "btn", *btn
// 普通はこれかと
;button gosub "btn", *btn
stop
*btn
	mes "click!"
return

HSP 【HSP3】ShellExecute

#include "shell32.as"
#define SW_SHOWDEFAULT 10

	url = "http://www.google.co.jp/search?q=ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	url += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	url += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	url += "ABCDEFGHIJKLMNOPQRSTUVWXWZ"
	url += "ABCDEFGHIJKLMNOPQRSTUVWXWZ"
	url += "ABCDEFGHIJKLMNOPQRSTUVWXWZ"
	url += "ABCDEFGHIJKLMNOPQRSTUVWXWZ"
	url += "ABCDEFGHIJKLMNOPQRSTUVWXWZ"
	url += "ABCDEFGHIJKLMNOPQRSTUVWXWZ"
	url += "ABCDEFGHIJKLMNOPQRSTUVWXWZ"
	url += "0123456789"
	mes "size:"+strlen(url)
	ShellExecuteA 0, 0, varptr(url), "", "", SW_SHOWDEFAULT

HSP 【HSP2.61】Unicode(UTF-16) を扱ってみるV2

#include "llmod.as"
#include "unicode.as"
#module
#deffunc replaceNullW val, int, int
	mref buf, 24
	mref size, 1
	mref r, 2
	sdim _buf, size
	memcpy _buf, buf, size, 0, 0
	sdim buf, size
	// 4byte NULLだった場合に抜ける
	j = 0
	repeat
		wpeek f1, _buf, cnt
		wpeek f2, _buf, cnt+2
		peek i, _buf, cnt
		if ((f1 == 0) && (f2 == 0)) : break
		if i == r {
			poke buf, j, 0
			poke buf, j+1, 0
			j+=2
		}else{
			poke buf, j, i
			j++
		}
	loop
return
#global
#module
dummyval = ""
dummyvalint = 0
#define WM_SETTEXT  0x000C
// W is the support Unicode(UTF-16)
#deffunc objprmW int, val
	// Get the first argument
	mref p1, 0
	// Gets the second argument
	mref p2, 25
	// Gets the handle of object
	_hspobjhandle p1
	handle = stat
	if handle == 0 : return -1
	// Gets a pointer to the variable
	getptr ptr, p2
	if ptr == 0 : return -2
	// Assignment SendMessageW function arguments
	prm = handle, WM_SETTEXT, 0, ptr
	// Call the SendMessageW function of the Win32API
	dllproc "SendMessageW", prm, 4, D_USER
return 0
#deffunc titleW val
	// Get the first argument
	mref p1, 24
	// Gets the window handle
	;_get_active_window handle
	mref bmscr, 67
	handle = bmscr.13
	if handle == 0 : return -1
	// Gets a pointer to the variable
	getptr ptr, p1
	if ptr == 0 : return -2
	// Assignment SendMessageW function arguments
	prm = handle, WM_SETTEXT, 0, ptr
	// Call the SendMessageW function of the Win32API
	dllproc "SendMessageW", prm, 4, D_USER
return 0
#define global strlenW(%1 = dummyvalint,%2) _strlenW %1, %2
#deffunc _strlenW val, val
	// Get argument
	mref p1, 16
	mref p2, 25
	// Gets a pointer to the variable
	getptr ptr, p2
	if ptr == 0 : return -1
	prm = ptr

	ll_libload msvcrt,"msvcrt"
	dllproc "wcslen", prm, 1, msvcrt
	p1 = dllret
return dllret
#deffunc strcatW val, val
	// Get argument
	mref p1, 24
	mref p2, 25
	// Gets a pointer to the variable
	getptr ptr1, p1
	getptr ptr2, p2
	if (ptr1 == 0) || (ptr2 == 0) : return -1

	prm = ptr1, ptr2
	ll_libload msvcrt,"msvcrt"
	dllproc "wcscat", prm, 2, msvcrt
return 0
#define global dialogW(%1 = dummyval,%2=0,%3 = dummyval) _dialogW %1, %3, %2
#define MB_OK 0x00000000
#define MB_YESNO 0x00000004
#define MB_ICONINFORMATION 0x00000040
#define MB_ICONEXCLAMATION 0x00000030
#define OFN_FILEMUSTEXIST 0x00001000
#deffunc _dialogW val, val, int
	// Gets argument
	mref p1, 24
	mref p2, 25
	mref p3, 2
	// Call the original instruction, in the case of color selection
	if (p3 == 32) || (p3 == 33) : dialog "", p3 : return
	// MessageBox
	if (p3 == 0) || (p3 == 1) || (p3 == 2) || (p3 == 3){
		// Gets the window handle
		;_get_active_window handle
		mref bmscr, 67
		handle = bmscr.13
		if handle == 0 : return -1
		// Gets a pointer to the variable
		getptr ptr1, p1
		getptr ptr2, p2
		if p3 == 0 : uType = MB_OK | MB_ICONINFORMATION
		if p3 == 1 : uType = MB_OK | MB_ICONEXCLAMATION
		if p3 == 2 : uType = MB_YESNO | MB_ICONINFORMATION
		if p3 == 3 : uType = MB_YESNO | MB_ICONEXCLAMATION
		// Assignment MessageBoxW function arguments
		prm = handle, ptr1, ptr2, uType
		// Call the MessageBoxW function of the Win32API
		dllproc "MessageBoxW", prm, 4, D_USER
		return dllret
	}
	// File selection dialog
	if (p3 == 16) || (p3 == 17){
		mref _stat, 64
		mref _stat, 65
		// OPENFILENAME structure
		dim ofn, 22
		sdim filename, 1024
		sdim aplFilter, 1024

		//
		sdim type, 1024
		sdim p1c, 1024	// Variable copy
		sdim p2c, 1024	// Variable copy
		memcpy p1c, p1, 1024, 0, 0
		memcpy p2c, p2, 1024, 0, 0
		strlenW ,p1c
		if stat == 0 {

			sdim tmp
			tmp = "*.*"
			to_uni type, tmp, -1
			sdim tmp2, 1024
			tmp2 = "All files (*.*)@*.*@"
			to_uni aplFilter, tmp2, -1

			; Not work
			;replaceNullW aplFilter, 1024, '@'

			size = 1024
			r = '@'
			sdim _buf, size
			memcpy _buf, aplFilter, size, 0, 0
			sdim aplFilter, size
			// If it was NULL(4 bytes) all goes out
			j = 0
			repeat size - 4
				wpeek f1, _buf, cnt
				wpeek f2, _buf, cnt+2
				peek i, _buf, cnt
				if ((f1 == 0) && (f2 == 0)) : break
				if i == r {
					poke aplFilter, j, 0
					poke aplFilter, j+1, 0
					j+=2
				}else{
					poke aplFilter, j, i
					j++
				}
			loop
			;

		}else{
			strlenW ,p1c
			mes "size:"+stat
			tmp = "*."
			to_uni type, tmp, -1
			strcatW type, p1c

			;
			sdim tmp2, 1024
			sdim tmp2_u, 1024
			tmp2 = " ("
			to_uni tmp2_u, tmp2, -1
			sdim tmp3, 1024
			sdim tmp3_u, 1024
			tmp3 = ")@"
			to_uni tmp3_u, tmp3, -1
			sdim tmp4, 1024
			sdim tmp4_u, 1024
			tmp4 = "@All files (*.*)@*.*@"
			to_uni tmp4_u, tmp4, -1

			strcatW aplFilter, p2c
			strcatW aplFilter, tmp2_u
			strcatW aplFilter, type
			strcatW aplFilter, tmp3_u
			strcatW aplFilter, type
			strcatW aplFilter, tmp4_u
			;

			; Not work
			;replaceNullW aplFilter, 1024, '@'

			size = 1024
			r = '@'
			sdim _buf, size
			memcpy _buf, aplFilter, size, 0, 0
			sdim aplFilter, size
			// If it was NULL(4 bytes) all goes out
			j = 0
			repeat size - 4
				wpeek f1, _buf, cnt
				wpeek f2, _buf, cnt+2
				peek i, _buf, cnt/2*2
				if ((f1 == 0) && (f2 == 0)) : break
				if i == r {
					poke aplFilter, j, 0
					//poke aplFilter, j+1, 0
					j++
				}else{
					peek i, _buf, cnt
					poke aplFilter, j, i
					j++
				}
			loop
			;
		}
		strlenW , type
		memcpy filename, type, stat * 2, 0, 0

		//
        	ofn.0 = 88 ; lStructSize
        	ofn.1 = bmscr.13 ; hwndOwner
        	ofn.2 = bmscr.14 ; hInstance
		getptr ofn.3, aplFilter ; lpstrFilter
		;getptr ofn.4, usrFilter ; lpstrCustomFilter
        	ofn.5 = 1024 ; nMaxCustFilter
        	ofn.6 = 0 ; nFilterIndex
		getptr ofn.7, filename ; lpstrFile
        	ofn.8 = 1024  ; nMaxFile
        	ofn.9 = 0 ; lpstrFileTitle
        	ofn.10 = 0 ; nMaxFileTitle
        	ofn.11 = 0 ; lpstrInitialDir
        	ofn.12 = 0 ; lpstrTitle
      		ofn.13 = OFN_FILEMUSTEXIST | 2; Flags
		// Assignment GetOpenFileNameW function argument
		getptr prm, ofn
		// Call the GetOpenFileNameW function of the Win32API
		if p3 == 16{
			dllproc "GetOpenFileNameW", prm, 1, D_COMDLG
		}else : if p3 == 17{
			dllproc "GetSaveFileNameW", prm, 1, D_COMDLG
		}
		if dllret != 0{
			sdim refstrW@, 1024
			memcpy refstrW@, filename, 1024, 0, 0
		}
	}
return dllret
#global
#module draw
#define global printW mesW
#define global mesW(%1) draw_init : getptr string_ptr@draw, %1 : _mesW string_ptr@draw
#deffunc draw_init
	string_ptr = 0
return
#deffunc _mesW
	mref bmscr, 67
	lpRect = csrx, csry, winx, winy
	getptr lpRect_ptr, lpRect
	prm = bmscr.4, string_ptr, -1, lpRect_ptr, 0
	dllproc "DrawTextW", prm, 5, D_USER
	pos csrx, csry + stat
return
#global
#module file
#define GENERIC_WRITE 0x40000000
#define GENERIC_READ 0x80000000
#define OPEN_EXISTING 3
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_BEGIN 1
#define FILE_CURRENT 1
#deffunc init_file
	file_u_ptr = 0
	buf_ptr = 0
	size = 0
	offset = 0
return
#define global bloadW(%1,%2,%3,%4=0) init_file : getptr file_u_ptr@file, %1 : getptr buf_ptr@file, %2 : size@file = %3 : offset@file = %4 : _bloadW 0
#define global bsaveW(%1,%2,%3,%4=0) init_file : getptr file_u_ptr@file, %1 : getptr buf_ptr@file, %2 : size@file = %3 : offset@file = %4 : _bloadW 1
#define global existW(%1) init_file : getptr file_u_ptr@file, %1 : _bloadW 2
#deffunc _bloadW int//, int, int, int
/*
	mref file_u_ptr, 0
	mref buf_ptr, 1
	mref size, 2
	mref offset, 3
*/
	mref mode, 0

	// Assignment CreateFileW function arguments
	if mode == 0{
		prm = file_u_ptr.0, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
	}
	if mode == 1{
		prm = file_u_ptr.0, GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
	}
	if mode == 2{
		prm = file_u_ptr.0, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
	}
	// Call the CreateFileW function of the Win32API

	dllproc "CreateFileW", prm, 7, D_KERNEL
	hFile = stat
	if hFile == 0 : return -1

	if mode == 2{
		prm = hFile, 0
		dllproc "GetFileSize", prm, 2, D_KERNEL
		fsize = stat
		prm = hFile
		dllproc "CloseHandle", prm, 1, D_KERNEL
		strsizeW@ = fsize
		return fsize
	}

	readsize = 0
	getptr readsize_ptr, readsize

	prm = hFile, offset, 0, FILE_BEGIN
	dllproc "SetFilePointer", prm, 4, D_KERNEL

	prm = hFile, buf_ptr, size, readsize_ptr, 0
	if mode == 0{
		dllproc "ReadFile", prm, 5, D_KERNEL
	}else{
		dllproc "WriteFile", prm, 5, D_KERNEL
	}

	prm = hFile
	dllproc "CloseHandle", prm, 1, D_KERNEL

	strsizeW@ = readsize

return readsize
#global

HSP 【HSP2.61】Unicode(UTF-16) を扱ってみる

// HSP 2.61用コード
#include "llmod.as"
#include "unicode.as"
#module
#define WM_SETTEXT  0x000C
#deffunc objprmW int, val
	mref p1, 0
	mref p2, 25
	_hspobjhandle p1
	handle = stat
	if handle == 0 : return -1
	getptr ptr, p2
	if ptr == 0 : return -2
	prm = handle, WM_SETTEXT, 0, ptr
	dllproc "SendMessageW", prm, 4, D_USER
return
#global

in = "abcあいうえお"
strlen size, in
sdim out, size*2+2
to_uni out, in, size + 1
sdim dummy, 1024
objsize 320, 24
input dummy
objprmW stat, out
stop

HSP 【HSP3】hsp3ld V3

#runtime "hsp3ld"
#include "user32.as"
#include "kernel32.as"
#module load_dll
#deffunc load_dll_init
	sdim name, 261
	GetModuleFileNameA 0, varptr(name), 260
	LoadLibraryA getpath(name, 8)
	hEXE = stat
	GetProcAddress hEXE, "InitializeDLLLoad"
	pInitializeDLLLoad = stat
	if pInitializeDLLLoad == 0{
		dialog "hsp3ldランタイムが使用されていません。終了します。" : end
	}
	prm = 0
	ret = callfunc(prm, pInitializeDLLLoad, 0)
return ret
#deffunc LoadDLL str fname
	name = getpath(fname, 8) + "_DLLIMAGE"
	exist fname
	if strsize == -1 : return 0
	size = strsize
	sdim buf, size
	bload fname, buf
	// DLLイメージを書き込む
	// PAGE_READWRITE
	CreateFileMapping -1, 0, 0x04, 0, size, 0; varptr(name)
	hMapObj = stat
	// FILE_MAP_WRITE
	MapViewOfFile hMapObj, 0x02, 0, 0, size
	sharedMemPtr = stat
	if sharedMemPtr == 0 {
		CloseHandle hMapObj
		return 0
	}
	dupptr sharedMemVal, sharedMemPtr, size, 2
	// DLLイメージをコピーする
	memcpy sharedMemVal, buf, size, 0, 0
	UnmapViewOfFile sharedMemPtr	// 一度閉じておく
	// FILE_MAP_READ
	MapViewOfFile hMapObj, 0x04, 0, 0, 0
	pBaseAddr = stat
	if pBaseAddr == 0{
		CloseHandle hMapObj
		return 0
	}
	// 実行
	name = getpath(fname, 8)
	GetProcAddress hEXE, "LoadDLLFromImage"
	pLoadDLLFromImage = stat
	prm.0 = pBaseAddr, varptr(name), 0
	ret = callfunc(prm, pLoadDLLFromImage, 3)

	UnmapViewOfFile pBaseAddr
	CloseHandle hMapObj
return ret
#defcfunc GetDLLProcAddress int handle, str fn
	_fn = fn
	GetProcAddress hEXE, "GetDLLProcAddress"
	pGetDLLProcAddress = stat
	prm = handle, varptr(_fn)
	ret = callfunc(prm, pGetDLLProcAddress, 2)
return ret
#deffunc LoadPackDLL str _fname
	// 小文字に変換
	fname = getpath(_fname, 16)
	// すでに読み込み済みな場合はDLLをデタッチする
	GetModuleHandle fname
	if stat != 0{
		FreeLibrary stat
	}
	// パックファイルからDLLを読み取りアタッチする
	LoadDLL fname
	hDLL = stat
	if hDLL == 0 : return -1	// 失敗 

	// Func info から 関数を検索して差し替え登録する
	mref hspctx, 68
	dupptr hsphed, hspctx.0, 96 // hspctx.hsphed / sizeof HSPHED
	ds_ptr = lpeek( hspctx, 12 ) // hspctx.mem_mds
	finfo_ptr = lpeek( hspctx, 840 ) // hspctx.mem_finfo
	max_finfo = lpeek( hsphed, 60 ) // hsphed.max_finfo
	linfo_ptr = lpeek( hspctx, 840 - 8 )
	max_linfo = lpeek( hsphed, 60 - 8 )

	dupptr linfo, linfo_ptr, max_linfo
	sdim dlllist, 260 : dllnum = 0	// 使用中のDLL名のリストですの
	for i, 0, max_linfo, 16	// LIBDAT size
		nameidx = lpeek( linfo, i + 4 )
		dupptr dllname, ds_ptr + nameidx, 260, 2
		dlllist.dllnum = getpath(dllname, 16)	// 小文字に
		dllnum++
		sdim dllname
	next
	sdim linfo
	// 関数名の一覧ですの
	dupptr finfo, finfo_ptr, max_finfo
	for i, 0, max_finfo, 28 // sizeof STRUCTDAT == 28
		libindex = wpeek( finfo, i)
		nameidx = lpeek( finfo, i + 12 )
		proc = lpeek( finfo, i + 24 )
		dupptr name, ds_ptr + nameidx, 260, 2
		if dllnum > libindex {
			// DLL名の一致
			if dlllist(libindex) == fname{
				// 関数名からアドレスを取得
				pFunc = GetDLLProcAddress(hDLL, name)
				if pFunc == 0 : _continue
				// 書き換え
				lpoke finfo, i + 24, pFunc
			}
			;logmes name + ":"+proc+":"+dlllist(libindex)
		}
		sdim name
	next
	sdim finfo
	sdim hsphed
return 0
#deffunc LoadPackHPI str _fname
	// 小文字に変換
	fname = getpath(_fname, 16)

	// すでに読み込み済みな場合はDLLをデタッチする
	GetModuleHandle fname
	if stat != 0{
		FreeLibrary stat
	}
	// パックファイルからDLLを読み取りアタッチする
	LoadDLL fname
	hDLL = stat
	if hDLL == 0 : return -1	// 失敗 

	mref hspctx, 68
	dupptr hsphed, hspctx.0, 96 // hspctx.hsphed / sizeof HSPHED
	ds_ptr = lpeek( hspctx, 12 ) // hspctx.mem_mds
	;dupptr ds, ds_ptr, 1024
	;bsave "ds.txt", ds, 1024

	pt_hpidat = lpeek( hsphed, 80 )
	max_hpi = wpeek( hsphed, 84 )
	max_varhpi = wpeek( hsphed, 86 )
	ptr = hspctx.0 + pt_hpidat

	dupptr hpidat, ptr, max_hpi
	for i, 0, max_hpi, 16	// HPIDAT size
		nameidx = lpeek( hpidat, i + 4 )
		funcidx = lpeek( hpidat, i + 8 )
		;_libptr = lpeek( hpidat, i + 12 )
		dupptr funcname, ds_ptr + funcidx, 260, 2
		dupptr name, ds_ptr + nameidx, 260, 2
		dllname = getpath(name, 16)
		// DLL名の一致
		if dllname == fname{
			pFunc = GetDLLProcAddress(hDLL, funcname)
			if pFunc == 0 : _continue
			lpoke hpidat, i + 12, pFunc
		}
		sdim name
		sdim funcname
	next
	sdim hpidat
	;sdim ds
	sdim hsphed
return 0
#deffunc KillDLLLoad onexit
	GetProcAddress hEXE, "KillDLLLoad"
	pKillDLLLoad = stat
	prm = 0
	ret = callfunc(prm, pKillDLLLoad, 0)
return
#global
load_dll_init

#pack "hspogg.dll"
#pack "hspsock.dll"
#pack "hspinet.dll"
#pack "theme.wav"

	// パックファイルからDLLを読み込む(実行ファイルにしたとき)
	LoadPackDLL "hspsock.dll"	// #func #cfunc のみ
	if stat : dialog "hspsock.dll の読み込みに失敗しました" : end
	LoadPackDLL "hspogg.dll"	// #func #cfunc のみ
	if stat : dialog "hspogg.dll の読み込みに失敗しました" : end
	LoadPackDLL "hspinet.dll"	// #func #cfunc のみ
	if stat : dialog "hspinet.dll の読み込みに失敗しました" : end

	// #regcmd形式のプラグインには非対応です
	;LoadPackHPI "e3dhsp3.dll"	// #regcmd
	;mes stat

#include "hspsock.as"
#include "hspogg.as"
#include "hspinet.as"

	dialog "hspsock.dll を使用してIPアドレスを取得します(ipget)"
	ipget
	mes "IP: "+refstr

	dialog "hspinet.dll を使用してBASE64エンコードを行います(b64encode)"
	src = "test"
	b64encode dst, src, strlen(src)
	mes "SRC: "+src+" -> DST:" +dst

	dialog "hspogg.dll を使用して音楽を再生します。音量に注意してください。"
	dmmini

	exist "theme.wav"
	size = strsize
	sdim oggdata, size
	bload "theme.wav", oggdata
	memfile oggdata, 0, size
	dmmload "MEM:theme.wav", 0		; wavファイル読み込み
	dmmplay 0

	dialog "終了します"

	end

HSP 【HSP3】hsp3ld V2

#runtime "hsp3ld"
#include "user32.as"
#include "kernel32.as"
#module load_dll
#deffunc load_dll_init
	sdim name, 261
	GetModuleFileNameA 0, varptr(name), 260
	LoadLibraryA getpath(name, 8)
	hEXE = stat
	GetProcAddress hEXE, "InitializeDLLLoad"
	pInitializeDLLLoad = stat
	if pInitializeDLLLoad == 0{
		dialog "hsp3ldランタイムが使用されていません。終了します。" : end
	}
	prm = 0
	ret = callfunc(prm, pInitializeDLLLoad, 0)
return ret
#deffunc LoadDLL str fname
	name = getpath(fname, 8) + "_DLLIMAGE"
	exist fname
	if strsize == -1 : return -1
	size = strsize
	sdim buf, size
	bload fname, buf
	// DLLイメージを書き込む
	// PAGE_READWRITE
	CreateFileMapping -1, 0, 0x04, 0, size, varptr(name)
	hMapObj = stat
	// FILE_MAP_WRITE
	MapViewOfFile hMapObj, 0x02, 0, 0, size
	sharedMemPtr = stat
	if sharedMemPtr == 0 {
		CloseHandle hMapObj
		return -2
	}
	dupptr sharedMemVal, sharedMemPtr, size, 2
	// DLLイメージをコピーする
	memcpy sharedMemVal, buf, size, 0, 0
	UnmapViewOfFile sharedMemPtr	// 一度閉じておく
	// FILE_MAP_READ
	MapViewOfFile hMapObj, 0x04, 0, 0, 0
	pBaseAddr = stat
	if pBaseAddr == 0{
		CloseHandle hMapObj
		return -3
	}
	// 実行
	name = getpath(fname, 8)
	GetProcAddress hEXE, "LoadDLLFromImage"
	pLoadDLLFromImage = stat
	prm.0 = pBaseAddr, varptr(name), 0
	ret = callfunc(prm, pLoadDLLFromImage, 3)

	UnmapViewOfFile pBaseAddr
	CloseHandle hMapObj
return ret
#defcfunc GetDLLProcAddress int handle, str fn
	_fn = fn
	GetProcAddress hEXE, "GetDLLProcAddress"
	pGetDLLProcAddress = stat
	prm = handle, varptr(_fn)
	ret = callfunc(prm, pGetDLLProcAddress, 2)
return ret
#deffunc LoadPackDLL str _fname
	// 小文字に変換
	fname = getpath(_fname, 16)
	// すでに読み込み済みな場合はDLLをデタッチする
	GetModuleHandle fname
	if stat != 0{
		FreeLibrary stat
	}
	// パックファイルからDLLを読み取りアタッチする
	LoadDLL fname
	hDLL = stat
	if hDLL <= 0 : return -1	// 失敗 

	// Func info から 関数を検索して差し替え登録する
	mref hspctx, 68
	dupptr hsphed, hspctx.0, 96 // hspctx.hsphed / sizeof HSPHED
	ds_ptr = lpeek( hspctx, 12 ) // hspctx.mem_mds
	finfo_ptr = lpeek( hspctx, 840 ) // hspctx.mem_finfo
	max_finfo = lpeek( hsphed, 60 ) // hsphed.max_finfo
	linfo_ptr = lpeek( hspctx, 840 - 8 )
	max_linfo = lpeek( hsphed, 60 - 8 )

	dupptr linfo, linfo_ptr, max_linfo
	sdim dlllist, 260 : dllnum = 0	// 使用中のDLL名のリストですの
	for i, 0, max_linfo, 16	// LIBDAT size
		nameidx = lpeek( linfo, i + 4 )
		dupptr dllname, ds_ptr + nameidx, 260, 2
		dlllist.dllnum = getpath(dllname, 16)	// 小文字に
		dllnum++
	next
	// 関数名の一覧ですの
	dupptr finfo, finfo_ptr, max_finfo
	for i, 0, max_finfo, 28 // sizeof STRUCTDAT == 28
		libindex = wpeek( finfo, i)
		nameidx = lpeek( finfo, i + 12 )
		proc = lpeek( finfo, i + 24 )
		dupptr name, ds_ptr + nameidx, 260, 2
		if dllnum > libindex {
			// DLL名の一致
			if dlllist(libindex) == fname{
				// 関数名からアドレスを取得
				pFunc = GetDLLProcAddress(hDLL, name)
				// 書き換え
				lpoke finfo, i + 24, pFunc
			}
			;logmes name + ":"+proc+":"+dlllist(libindex)
		}
	next

return
#global
load_dll_init

#pack "hspdsc.dll"
#uselib "hspdsc.dll"
#func dsc_Version "dsc_Version"

	LoadPackDLL "hspdsc.dll"
	dsc_Version
	/*
	LoadDLL "hspdsc.dll"
	hDLL = stat
	func = GetDLLProcAddress(hDLL, "dsc_Version")
	prm = 0
	mes callfunc(prm, func, 0)
	*/

HSP 【HSP3】hsp3ld

#runtime "hsp3ld"
#include "user32.as"
#include "kernel32.as"
#module load_dll
#deffunc load_dll_init
	sdim name, 261
	GetModuleFileNameA 0, varptr(name), 260
	LoadLibraryA getpath(name, 8)
	hEXE = stat
	GetProcAddress hEXE, "InitializeDLLLoad"
	pInitializeDLLLoad = stat
	if pInitializeDLLLoad == 0{
		dialog "hsp3ldランタイムが使用されていません。終了します。" : end
	}
	prm = 0
	ret = callfunc(prm, pInitializeDLLLoad, 0)
return ret
#deffunc LoadDLL str fname

	name = getpath(fname, 8) + "_DLLIMAGE"
	exist fname
	if strsize == -1 : return -1
	size = strsize
	sdim buf, size
	bload fname, buf
	// DLLイメージを書き込む
	// PAGE_READWRITE
	CreateFileMapping -1, 0, 0x04, 0, size, varptr(name)
	hMapObj = stat
	// FILE_MAP_WRITE
	MapViewOfFile hMapObj, 0x02, 0, 0, size
	sharedMemPtr = stat
	if sharedMemPtr == 0 {
		CloseHandle hMapObj
		return -2
	}
	dupptr sharedMemVal, sharedMemPtr, size, 2
	// DLLイメージをコピーする
	memcpy sharedMemVal, buf, size, 0, 0
	UnmapViewOfFile sharedMemPtr	// 一度閉じておく
	// FILE_MAP_READ
	MapViewOfFile hMapObj, 0x04, 0, 0, 0
	pBaseAddr = stat
	if pBaseAddr == 0{
		CloseHandle hMapObj
		return -3
	}
	// 実行
	name = getpath(fname, 8)
	GetProcAddress hEXE, "LoadDLLFromImage"
	pLoadDLLFromImage = stat
	prm.0 = pBaseAddr, varptr(name), 0
	ret = callfunc(prm, pLoadDLLFromImage, 3)

	UnmapViewOfFile pBaseAddr
	CloseHandle hMapObj
return ret
#defcfunc GetDLLProcAddress int handle, str fn
	_fn = fn
	GetProcAddress hEXE, "GetDLLProcAddress"
	pGetDLLProcAddress = stat
	prm = handle, varptr(_fn)
	ret = callfunc(prm, pGetDLLProcAddress, 2)
return ret
#global

#pack "hspdsc.dll"

	load_dll_init
	LoadDLL "hspdsc.dll"
	hDLL = stat
	func = GetDLLProcAddress(hDLL, "dsc_Version")
	prm = 0
	mes callfunc(prm, func, 0)

HSP 【HSP3】Aeroを一時的に無効化する

#uselib "Dwmapi"
#define DWM_EC_DISABLECOMPOSITION 0
#define DWM_EC_ENABLECOMPOSITION 1
#func DwmEnableComposition "DwmEnableComposition" int

	// 一時的なので終了しても元に戻る

	// Aero無効化
	DwmEnableComposition DWM_EC_DISABLECOMPOSITION

	dialog "押すと戻るよ"

	// Aero有効化
	DwmEnableComposition DWM_EC_ENABLECOMPOSITION

HSP 【HSP3】XOR暗号化

#module
#deffunc XorCrypt var b, int s, int p
if s <= 0 : return -1
randomize p
dim k, 256
repeat 256
	v = rnd(cnt + 1)
	k.cnt = k.v
	k.v = cnt
loop
repeat s
	poke b, cnt, peek(b, cnt)^k(cnt\256)
loop
dim k, 256
return 0
#global

in = "こんにちは"
size = strlen(in)
mes in

// 暗号化・復号化したい変数, サイズ, 鍵を作成するためのシード値 (0~)
XorCrypt in, size, 0
mes in

// 同じシード値で実行すると元に戻ります
XorCrypt in, size, 0
mes in

HSP 【HSP3】ツイッターのトレンドを取得してみるよー

// hspinet (HSP 3.2 以降が必要)
#include "hspinets.as"

// 以下モジュール
// このモジュールはhspinetを使用していますので、
// 先に hspinet.as がインクルードされている必要があります。
#module _twittertrend_
#deffunc TTSetConfig str _url, str _woeid, str _ex
	if _url == ""{
		url = "http://api.twitter.com/1/trends/"
	}else{
		url = _url
	}
	if _woeid == ""{
		woeid = "23424856"	// 日本
	}else{
		woeid = _woeid
	}
	if _ex == ""{
		ex = ".json"
	}else{
		ex = _ex
	}
return
#deffunc TTGetTrends var _trend, var _url
	neturl@ url
	netrequest_get@ woeid+""+ex
	error = 0
	repeat
		netexec@ res
		if res > 0 : break
		if res < 0 : error = 1 : break
	loop
	if error == 1{	// エラー
		neterror@ estr
		return -1
	}
	sdim buf,$10000
	netgetv@ buf
	if buf == "" : return -2
	jsonnkf@ "Ws"	; utf8->sjisへの変換指定
	jsonopen@ jroot, buf
	jsongets@ erstr, "error"
	if stat == 0 {
		jsonclose@
		return -3
	}

	sdim trendnames, 1400
	sdim trendurls, 5000
	trendname = "" : trendurl =""
	jsonnext@ root, ,2
	jsongetobj@ trends, "trends", root
	jsonnext@ cur, trends, 2
	repeat
		if cur == 0 : break
		jsongets@ trendname, "name", cur	; 内容の取得
		if stat == 0 {
			trendnames+=trendname+"\n"
		}
		jsongets@ trendurl, "url", cur	; URLの取得
		if stat == 0 {
			trendurls+=trendurl+"\n"
		}
		jsonnext@ cur,cur,0
	loop
	jsonclose@
	_trend = ""+trendnames
	_url = ""+trendurls
return 0
#global

// モジュール終了
// 以下サンプル

	title "ツイッタートレンドランキング"

	netinit
	if stat : dialog "ネット接続できません。" : end

	// woeid の一覧は以下のアドレスを参照
	// http://phpjavascriptroom.com/exp3.php?f=include/topic/twitter_rest_api_local_trends/available.inc&ttl=%E8%A8%AD%E7%BD%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%3Atrends.json

	; 第1パラが アドレス(空欄でデフォルト使用)
	; 第2パラが woeid (空欄で日本の 23424856 使用。東京 は 1118370 )
	; 第3パラが 取得形式(空欄でデフォルトのJSON使用)
	TTSetConfig "","",""		; 日本
	;TTSetConfig "","1118370",""	; 東京

	; 第1パラが トレンドを入れる変数
	; 第2パラが トレンドのURLを入れる変数
	TTGetTrends trends, url
	if stat < 0 : dialog "エラーが発生しました。" : end

	// 分離して表示する
	notesel trends
	repeat notemax
		noteget tmp, cnt
		mes "("+(cnt+1)+"位) \t"+tmp
	loop

// サンプル終了
Total Pages: 1 / 812345...最後 »

よく投稿されているコード

タグ

最近投稿されたコード