デバッグに役立つと予想される、様々な値を出力するプロシージャ群です。
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: 57: 58: 59: |
Sub OutputValue(Int As Long)
Dim Message[256] As Byte wsprintf(Message,Ex"%i\r\n",Int) OutputDebugString(Message) End Sub Sub OutputUnsignedValue(Int As DWord) Dim Message[256] As Byte wsprintf(Message,Ex"%u\r\n",Int) OutputDebugString(Message) End Sub Sub OutputHexValue(Int As Long) Dim Message[256] As Byte wsprintf(Message,Ex"%X\r\n",Int) OutputDebugString(Message) End Sub Sub OutputErrorMessage() Dim Message[256] As Byte FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),LANG_USER_DEFAULT,Message,256,NULL) OutputDebugString(Message) End Sub Sub OutputCOMErrorMessage(Int As HRESULT) Dim Message[256] As Byte FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,Int,LANG_USER_DEFAULT,Message,256,NULL) OutputDebugString(Message) End Sub Sub ValueBox(Int As Long) Dim Message[256] As Byte wsprintf(Message,Ex"%i\r\n",Int) MessageBox(NULL,Message,NULL,MB_OK) End Sub Sub UnsignedValueBox(Int As DWord) Dim Message[256] As Byte wsprintf(Message,Ex"%u\r\n",Int) MessageBox(NULL,Message,NULL,MB_OK) End Sub Sub HexValueBox(Int As Long) Dim Message[256] As Byte wsprintf(Message,Ex"%X\r\n",Int) MessageBox(NULL,Message,NULL,MB_OK) End Sub Sub ErrorMessageBox() Dim Message[256] As Byte FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),LANG_USER_DEFAULT,Message,256,NULL) MessageBox(NULL,Message,NULL,MB_OK) End Sub Sub COMErrorMessageBox(Int As HRESULT) Dim Message[256] As Byte FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,Int,LANG_USER_DEFAULT,Message,256,NULL) MessageBox(NULL,Message,NULL,MB_OK) End Sub |
大方の使い方はプロシージャの処理を見れば分かると思います。
・Long 型
・DWord 型
・GetLastError API で取得したエラー コードに対応するエラー メッセージ
・COM 関連の API が返したエラー コードに対応するエラー メッセージ
を、デバッガに出力するか MessageBox API で表示するかです。
16 進数で表示させることも出来ます。
GetLastError API と FormatMessage API は内部で呼び出している為、
単にプロシージャを呼ぶだけで簡単にエラー メッセージが表示されます。
しかし COM 関連の API は GetLastError API で取得する形ではなく
直接エラー コードを返す形を取っているので、
1:
|
COMErrorMessageBox(CoInitialize())
|
こうして直接返ってきたエラー コードをプロシージャに渡すとよいでしょう。
ページの先頭へ戻る
プログラムのテーブルへ戻る
トップ ページへ戻る