⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxerr9.pas

📁 3D GameStudio 的Delphi开发包
💻 PAS
字号:
{******************************************************************************}
{*                                                                            *}
{*  Copyright (C) Microsoft Corporation.  All Rights Reserved.                *}
{*                                                                            *}
{*  File:       dxerr9.h                                                      *}
{*  Content:    DirectX Error Library Include File                            *}
{*                                                                            *}
{*  DirectX 9.0 Delphi / FreePascal adaptation by Alexey Barkovoy             *}
{*  E-Mail: directx@clootie.ru                                                *}
{*                                                                            *}
{*  Latest version can be downloaded from:                                    *}
{*    http://clootie.ru                                                       *}
{*    http://sourceforge.net/projects/delphi-dx9sdk                           *}
{*                                                                            *}
{*----------------------------------------------------------------------------*}
{*  $Id: DXErr9.pas,v 1.8 2006/01/15 21:09:29 clootie Exp $ }
{******************************************************************************}
{                                                                              }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI)        }
{                                                                              }
{ The contents of this file are used with permission, subject to the Mozilla   }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at      }
{ http://www.mozilla.org/MPL/MPL-1.1.html                                      }
{                                                                              }
{ Software distributed under the License is distributed on an "AS IS" basis,   }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License.    }
{                                                                              }
{ Alternatively, the contents of this file may be used under the terms of the  }
{ GNU Lesser General Public License (the  "LGPL License"), in which case the   }
{ provisions of the LGPL License are applicable instead of those above.        }
{ If you wish to allow use of your version of this file only under the terms   }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting  the provisions above and  }
{ replace  them with the notice and other provisions required by the LGPL      }
{ License.  If you do not delete the provisions above, a recipient may use     }
{ your version of this file under either the MPL or the LGPL License.          }
{                                                                              }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{                                                                              }
{******************************************************************************}

{$I DirectX.inc}

unit DXErr9;

interface

{$HPPEMIT '#include "dxerr9.h"'}

uses
  Windows;

(*==========================================================================;
 *
 *
 *  File:   dxerr9.h
 *  Content:    DirectX Error Library Include File
 *
 ****************************************************************************)

const
  //////////// DLL export definitions ///////////////////////////////////////
  dxerr9dll = 'dxerr9ab.dll';


type
  TDXGetError9A = function (hr: HRESULT): PAnsiChar; stdcall;
  TDXGetError9W = function (hr: HRESULT): PWideChar; stdcall;
  TDXGetError9 = {$IFDEF UNICODE}TDXGetError9W{$ELSE}TDXGetError9A{$ENDIF};

function Dummy_DXGetError9A(hr: HRESULT): PAnsiChar; stdcall;
function Dummy_DXGetError9W(hr: HRESULT): PWideChar; stdcall;


//
//  DXGetErrorString9
//
//  Desc:  Converts a DirectX 9 or earlier HRESULT to a string
//
//  Args:  HRESULT hr   Can be any error code from
//                      D3D9 D3DX9 D3D8 D3DX8 DDRAW DPLAY8 DMUSIC DSOUND DINPUT DSHOW
//
//  Return: Converted string
//
var
  DXGetErrorString9A: TDXGetError9A = Dummy_DXGetError9A;
  DXGetErrorString9W: TDXGetError9W = Dummy_DXGetError9W;
  DXGetErrorString9: TDXGetError9 = {$IFDEF UNICODE}Dummy_DXGetError9W{$ELSE}Dummy_DXGetError9A{$ENDIF};


//
//  DXGetErrorDescription9
//
//  Desc:  Returns a string description of a DirectX 9 or earlier HRESULT
//
//  Args:  HRESULT hr   Can be any error code from
//                      D3D9 D3DX9 D3D8 D3DX8 DDRAW DPLAY8 DMUSIC DSOUND DINPUT DSHOW
//
//  Return: String description
//
var
  DXGetErrorDescription9A: TDXGetError9A = Dummy_DXGetError9A;
  DXGetErrorDescription9W: TDXGetError9W = Dummy_DXGetError9W;
  DXGetErrorDescription9: TDXGetError9 = {$IFDEF UNICODE}Dummy_DXGetError9W{$ELSE}Dummy_DXGetError9A{$ENDIF};


//
//  DXTrace
//
//  Desc:  Outputs a formatted error message to the debug stream
//
//  Args:  CHAR* strFile   The current file, typically passed in using the
//                         __FILE__ macro.
//         DWORD dwLine    The current line number, typically passed in using the
//                         __LINE__ macro.
//         HRESULT hr      An HRESULT that will be traced to the debug stream.
//         CHAR* strMsg    A string that will be traced to the debug stream (may be NULL)
//         BOOL bPopMsgBox If TRUE, then a message box will popup also containing the passed info.
//
//  Return: The hr that was passed in.
//
type
  TDXTraceA = function (strFile: PAnsiChar; dwLine: DWORD; hr: HRESULT; strMsg: PAnsiChar; bPopMsgBox: BOOL{$IFDEF SUPPORTS_DEFAULTPARAMS} = FALSE{$ENDIF}): HRESULT; stdcall;
  TDXTraceW = function (strFile: PAnsiChar; dwLine: DWORD; hr: HRESULT; strMsg: PWideChar; bPopMsgBox: BOOL{$IFDEF SUPPORTS_DEFAULTPARAMS} = FALSE{$ENDIF}): HRESULT; stdcall;
  TDXTrace = {$IFDEF UNICODE}TDXTraceW{$ELSE}TDXTraceA{$ENDIF};

function Dummy_DXTraceA(strFile: PAnsiChar; dwLine: DWORD; hr: HRESULT; strMsg: PAnsiChar; bPopMsgBox: BOOL{$IFDEF SUPPORTS_DEFAULTPARAMS} = FALSE{$ENDIF}): HRESULT; stdcall;
function Dummy_DXTraceW(strFile: PAnsiChar; dwLine: DWORD; hr: HRESULT; strMsg: PWideChar; bPopMsgBox: BOOL{$IFDEF SUPPORTS_DEFAULTPARAMS} = FALSE{$ENDIF}): HRESULT; stdcall;

var
  DXTraceA: TDXTraceA = Dummy_DXTraceA;
  DXTraceW: TDXTraceW = Dummy_DXTraceW;
  DXTrace: TDXTrace = {$IFDEF UNICODE}Dummy_DXTraceW{$ELSE}Dummy_DXTraceA{$ENDIF};


//
// Helper macros
//
function DXTRACE_MSG(str: PChar; FileName: PChar{$IFDEF SUPPORTS_DEFAULTPARAMS} = nil{$ENDIF}; Line: DWORD{$IFDEF SUPPORTS_DEFAULTPARAMS} = $FFFFFFFF{$ENDIF}): HRESULT;{$IFDEF SUPPORTS_INLINE} inline;{$ENDIF}
{$EXTERNALSYM DXTRACE_MSG}
function DXTRACE_ERR(str: PChar; hr: HRESULT; FileName: PChar{$IFDEF SUPPORTS_DEFAULTPARAMS} = nil{$ENDIF}; Line: DWORD{$IFDEF SUPPORTS_DEFAULTPARAMS} = $FFFFFFFF{$ENDIF}): HRESULT;{$IFDEF SUPPORTS_INLINE} inline;{$ENDIF}
{$EXTERNALSYM DXTRACE_ERR}
function DXTRACE_ERR_MSGBOX(str: PChar; hr: HRESULT; FileName: PChar{$IFDEF SUPPORTS_DEFAULTPARAMS} = nil{$ENDIF}; Line: DWORD{$IFDEF SUPPORTS_DEFAULTPARAMS} = $FFFFFFFF{$ENDIF}): HRESULT;{$IFDEF SUPPORTS_INLINE} inline;{$ENDIF}
{$EXTERNALSYM DXTRACE_ERR_MSGBOX}


implementation

uses SysUtils;

resourcestring
  SDXGetErrorString9 = dxerr9dll + ' library is not found. Description for 0x%x is not available.';

var
  TempStringA: AnsiString;
  TempStringW: WideString;

function Dummy_DXGetError9A(hr: HRESULT): PAnsiChar; stdcall;
begin
  TempStringA:= Format(SDXGetErrorString9, [hr]);
  Result:= PAnsiChar(TempStringA);
end;

function Dummy_DXGetError9W(hr: HRESULT): PWideChar; stdcall;
begin
{$IFNDEF COMPILER6_UP}
  {$DEFINE D5_OR_LOWER}
{$ENDIF}
{$IFDEF D5_OR_LOWER}
  TempStringW:= Format(SDXGetErrorString9, [hr]);
{$ELSE}
  TempStringW:= WideFormat(SDXGetErrorString9, [hr]);
{$ENDIF}
  Result:= PWideChar(TempStringW);
end;

function Dummy_DXTraceA(strFile: PAnsiChar; dwLine: DWORD; hr: HRESULT; strMsg: PAnsiChar; bPopMsgBox: BOOL{$IFDEF SUPPORTS_DEFAULTPARAMS} = FALSE{$ENDIF}): HRESULT; stdcall;
begin
  Result:= hr;
end;

function Dummy_DXTraceW(strFile: PAnsiChar; dwLine: DWORD; hr: HRESULT; strMsg: PWideChar; bPopMsgBox: BOOL{$IFDEF SUPPORTS_DEFAULTPARAMS} = FALSE{$ENDIF}): HRESULT; stdcall;
begin
  Result:= hr;
end;


{$IFNDEF DEBUG}
function DXTRACE_MSG(str: PChar; FileName: PChar{$IFDEF SUPPORTS_DEFAULTPARAMS} = nil{$ENDIF}; Line: DWORD{$IFDEF SUPPORTS_DEFAULTPARAMS} = $FFFFFFFF{$ENDIF}): HRESULT;
begin Result:= 0; end;

function DXTRACE_ERR(str: PChar; hr: HRESULT; FileName: PChar{$IFDEF SUPPORTS_DEFAULTPARAMS} = nil{$ENDIF}; Line: DWORD{$IFDEF SUPPORTS_DEFAULTPARAMS} = $FFFFFFFF{$ENDIF}): HRESULT;
begin Result:= hr; end;

function DXTRACE_ERR_MSGBOX(str: PChar; hr: HRESULT; FileName: PChar{$IFDEF SUPPORTS_DEFAULTPARAMS} = nil{$ENDIF}; Line: DWORD{$IFDEF SUPPORTS_DEFAULTPARAMS} = $FFFFFFFF{$ENDIF}): HRESULT;
begin Result:= hr; end;
{$ELSE}
function DXTRACE_MSG(str: PChar; FileName: PChar{$IFDEF SUPPORTS_DEFAULTPARAMS} = nil{$ENDIF}; Line: DWORD{$IFDEF SUPPORTS_DEFAULTPARAMS} = $FFFFFFFF{$ENDIF}): HRESULT;
begin
  Result:= DXTrace(FileName, Line, 0, str, False);
end;

function DXTRACE_ERR(str: PChar; hr: HRESULT; FileName: PChar{$IFDEF SUPPORTS_DEFAULTPARAMS} = nil{$ENDIF}; Line: DWORD{$IFDEF SUPPORTS_DEFAULTPARAMS} = $FFFFFFFF{$ENDIF}): HRESULT;
begin
  Result:= DXTrace(FileName, Line, hr, str, False);
end;

function DXTRACE_ERR_MSGBOX(str: PChar; hr: HRESULT; FileName: PChar{$IFDEF SUPPORTS_DEFAULTPARAMS} = nil{$ENDIF}; Line: DWORD{$IFDEF SUPPORTS_DEFAULTPARAMS} = $FFFFFFFF{$ENDIF}): HRESULT;
begin
  Result:= DXTrace(FileName, Line, hr, str, True);
end;
{$ENDIF}

var
  dxerr9DllInstance: THandle = 0;
  temp: Pointer;

initialization
  dxerr9DllInstance := LoadLibrary(dxerr9dll);
  if (dxerr9DllInstance <> 0) then
  begin
    temp:= GetProcAddress(dxerr9DllInstance, 'DXGetErrorString9A'); if (temp<>nil) then DXGetErrorString9A:= temp;
    temp:= GetProcAddress(dxerr9DllInstance, 'DXGetErrorString9W'); if (temp<>nil) then DXGetErrorString9W:= temp;
    temp:= GetProcAddress(dxerr9DllInstance, 'DXGetErrorDescription9A'); if (temp<>nil) then DXGetErrorDescription9A:= temp;
    temp:= GetProcAddress(dxerr9DllInstance, 'DXGetErrorDescription9W'); if (temp<>nil) then DXGetErrorDescription9W:= temp;
    temp:= GetProcAddress(dxerr9DllInstance, 'DXTraceA'); if (temp<>nil) then DXTraceA:= temp;
    temp:= GetProcAddress(dxerr9DllInstance, 'DXTraceW'); if (temp<>nil) then DXTraceW:= temp;

    {$IFDEF UNICODE}
    DXGetErrorString9 := DXGetErrorString9W;
    DXGetErrorDescription9 := DXGetErrorDescription9W;
    DXTrace := DXTraceW;
    {$ELSE}
    DXGetErrorString9 := DXGetErrorString9A;
    DXGetErrorDescription9 := DXGetErrorDescription9A;
    DXTrace := DXTraceA;
    {$ENDIF}
  end;
finalization
  if (dxerr9DllInstance <> 0) then
  begin
    FreeLibrary(dxerr9DllInstance);
    dxerr9DllInstance := 0;
  end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -