〜 メディア 〜
MCIのエラー内容を確認 (要WINMM.DLL)

MCIはエラーが発生してもエラーコードを返すだけで、エラー内容を知らせてはくれません。
エラーなのかエラーでないのか、程度であればコード内容がわからずとも何とかなるのですが、
エラーが起きた時に何のエラーなのかわからず、修正箇所の検討も付かない場合等、
エラー内容を確認したい時はエラー内容を問い合わせなければなりません。
下記はエラーコードを指定するだけで最終エラー内容を返してくれるサンプルモジュールです。
尚、サンプルでは共通MCIモジュールを使用しています。
詳しくは、複数読込に対応しているコチラのサンプルを参照してください。
	

mciload ファイルパス, 番号
ファイルパス再生するファイルパスを指定する。
尚、"1"ならA、"2"ならB、"26"ならZドライブとしたCDオーディオ形式でロードする。
番号割り当てるバッファ番号を指定する。

mciplay 番号, 繰り返し, 再生位置
番号再生するバッファ番号を指定する。
繰り返し最後まで再生したら自動的に初めから再生する(=1)か否(=0)かを指定する。
再生位置ミリ秒単位の再生位置を指定する。

mcistop 番号
番号停止するバッファ番号を指定する。

mciexit
[パラメータなし]全デバイスを解放するだけの為、パラメータは必要ない。
尚、終了時に自動的に呼び出されるので命令を実行する必要はない。

mciresult コード
コード最後に送信したMCIコマンドの結果値を指定することでrefstrに結果内容を返す。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	ll_libload winmm, "winmm.dll"
	ll_getproc mciGetErrorStringA, "mciGetErrorStringA", winmm

#module
#deffunc mciload str, int
	mref file, 32 : mref no, 1
	cntno = no
	mci "close _" + cntno
	strmid i, file, , 2 : int i
	if i {
		file = "cdaudio!?"
		poke file, 8, i + 64
	}
	mci "open \"" + file + "\" alias _" + cntno
	return

#deffunc mciplay str, str, int
	mref start, 32 : mref finish, 33
	mref re, 2
	if start ! "" : s = " from " + start : else : s = ""
	if finish ! "" : s += " to " + finish
	if re : s += " repeat"
	mci "play _" + cntno + s
	return

#deffunc mcistop
	mci "stop _" + cntno
	return

#deffunc mciend onexit
	mci "stop all"
	mci "close all"
	return

#deffunc mciresult int
	mref code, 0
	mref rstr, 65
	ll_getptr rstr : ll_ret i
	prm = code, i, 128
	ll_callfunc prm, 3, mciGetErrorStringA@ // エラー内容を取得する
	return
#global

	dialog "", 16
	if stat = 0 : end
	mciload refstr
	mciresult stat
	mes refstr
	mciplay "", ""
	mciresult stat
	mes refstr
	wait 300
	mcistop
	mciresult stat
	mes refstr
	stop

mciload ファイルパス, 番号
ファイルパス再生するファイルパスを指定する。
尚、"1"ならA、"2"ならB、"26"ならZドライブとしたCDオーディオ形式でロードする。
番号割り当てるバッファ番号を指定する。

mciplay 番号, 繰り返し, 再生位置
番号再生するバッファ番号を指定する。
繰り返し最後まで再生したら自動的に初めから再生する(=1)か否(=0)かを指定する。
再生位置ミリ秒単位の再生位置を指定する。

mcistop 番号
番号停止するバッファ番号を指定する。

mciexit
[パラメータなし]全デバイスを解放するだけの為、パラメータは必要ない。
尚、終了時に自動的に呼び出されるので命令を実行する必要はない。

受取先 = mciresult(コード)
受取先結果内容の受取先を指定する。
コード最後に送信したMCIコマンドの結果値を指定する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#uselib "winmm.dll"
#func  global mciGetErrorString "mciGetErrorStringA" int, var, int

#module
#deffunc mciload str file, int no, local s
	cntno = no
	mci "close _" + cntno
	if int(file) {
		s = "cdaudio!?"
		poke s, 8, int(file) + 64
	} else {
		s = file
	}
	mci "open \"" + s + "\" alias _" + cntno
	return

#deffunc mciplay str start, str finish, int re, local s
	if start ! "" : s = " from " + start : else : s = ""
	if finish ! "" : s += " to " + finish
	if re : s += " repeat"
	mci "play _" + cntno + s
	return

#deffunc mcistop
	mci "stop _" + cntno
	return

#deffunc mciend onexit
	mci "stop all"
	mci "close all"
	return

#defcfunc mciresult int code, local rstr
	sdim rstr, 128
	mciGetErrorString code, rstr, 128 // エラー内容を取得する
	return rstr
#global

	dialog "", 16
	if stat = 0 : end
	mciload refstr
	mes mciresult(stat)
	wait 300
	mciplay "", ""
	mes mciresult(stat)
	wait 300
	mcistop
	mes mciresult(stat)