〜 タイム 〜
パソコンが起動してからの時間を取得 (要KERNEL32.DLL)

ミリ秒単位のパソコン稼働時間を取得するサンプルです。
取得するAPI関数はGetTickCountという4バイトの数値型変数に稼働時間を格納するものなので、
起動してから約49.7日以上再起動すらしていないマシンの場合はカウンタが0に戻り、
「実際は50日間動かしてるのに1日しか動いてない」となってしまうことを覚えておきましょう。
HSP3は関数が使えて、引数のないAPI関数は1文だけで済ませられるため、モジュールにはしてません。
	

getoptime 受取先
受取先起動してからの経過時間(ミリ秒単位)を格納する数値型変数を指定する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
	ll_libload kernel, "kernel32.dll"
	ll_getproc GetTickCount, "GetTickCount", kernel

#module
#deffunc getoptime val
	mref time, 16
	ll_callfnv GetTickCount@
	ll_ret time
	return
#global

	getoptime tm
	tm.1 = tm / 1000 / 60 / 60 / 24
	tm.2 = tm / 1000 / 60 / 60 \ 24
	tm.3 = tm / 1000 / 60 \ 60
	tm.4 = tm / 1000 \ 60
	tm.5 = tm \ 1000
	mes "稼働してから" + tm.1 + "日" + tm.2 + "時間" + tm.3 + "分" + tm.4 + "秒" + tm.5 + "ミリ秒経っています"
	stop

経過時間 = getoptime( )
経過時間起動してからの経過時間(ミリ秒単位)の格納先を指定する。
[パラメータなし]経過時間を取得するだけのため、パラメータは必要ない。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#uselib "kernel32.dll"
#cfunc global getoptime "GetTickCount"

	operating = getoptime()
	tm  = strf("%d日",     operating / 1000 / 60 / 60 / 24)
	tm += strf("%d時間",   operating / 1000 / 60 / 60 \ 24)
	tm += strf("%d分",     operating / 1000 / 60 \ 60)
	tm += strf("%d秒",     operating / 1000 \ 60)
	tm += strf("%dミリ秒", operating \ 1000)
	mes "稼働してから" + tm + "経っています"