?? dxutil.cpp
字號:
strLastSlash = _tcsrchr( strExeName, TEXT('.') );
if( strLastSlash )
*strLastSlash = 0;
}
if( !bFound )
{
// Search in "%EXE_DIR%\..\%EXE_NAME%". This matchs the DirectX SDK layout
_tcscpy( strReadmePath, strExePath );
strLastSlash = _tcsrchr( strReadmePath, TEXT('\\') );
if( strLastSlash )
*strLastSlash = 0;
lstrcat( strReadmePath, TEXT("\\") );
lstrcat( strReadmePath, strExeName );
lstrcat( strReadmePath, TEXT("\\readme.txt") );
if( GetFileAttributes( strReadmePath ) != 0xFFFFFFFF )
bFound = TRUE;
}
if( !bFound )
{
// Search in "%EXE_DIR%\"
_tcscpy( strReadmePath, strExePath );
lstrcat( strReadmePath, TEXT("\\readme.txt") );
if( GetFileAttributes( strReadmePath ) != 0xFFFFFFFF )
bFound = TRUE;
}
if( !bFound )
{
// Search in "%EXE_DIR%\.."
_tcscpy( strReadmePath, strExePath );
strLastSlash = _tcsrchr( strReadmePath, TEXT('\\') );
if( strLastSlash )
*strLastSlash = 0;
lstrcat( strReadmePath, TEXT("\\readme.txt") );
if( GetFileAttributes( strReadmePath ) != 0xFFFFFFFF )
bFound = TRUE;
}
if( !bFound )
{
// Search in "%EXE_DIR%\..\.."
_tcscpy( strReadmePath, strExePath );
strLastSlash = _tcsrchr( strReadmePath, TEXT('\\') );
if( strLastSlash )
*strLastSlash = 0;
strLastSlash = _tcsrchr( strReadmePath, TEXT('\\') );
if( strLastSlash )
*strLastSlash = 0;
lstrcat( strReadmePath, TEXT("\\readme.txt") );
if( GetFileAttributes( strReadmePath ) != 0xFFFFFFFF )
bFound = TRUE;
}
if( bFound )
{
// GetProcAddress for ShellExecute, so we don't have to include shell32.lib
// in every project that uses dxutil.cpp
LPShellExecute pShellExecute = NULL;
HINSTANCE hInstShell32 = LoadLibrary(TEXT("shell32.dll"));
if (hInstShell32 != NULL)
{
#ifdef UNICODE
pShellExecute = (LPShellExecute)GetProcAddress(hInstShell32, _TWINCE("ShellExecuteW"));
#else
pShellExecute = (LPShellExecute)GetProcAddress(hInstShell32, _TWINCE("ShellExecuteA"));
#endif
if( pShellExecute != NULL )
{
if( pShellExecute( hWnd, TEXT("open"), strReadmePath, NULL, NULL, SW_SHOW ) > (HINSTANCE) 32 )
bSuccess = true;
}
FreeLibrary(hInstShell32);
}
}
if( !bSuccess )
{
// Tell the user that the readme couldn't be opened
MessageBox( hWnd, TEXT("Could not find readme.txt"),
TEXT("DirectX SDK Sample"), MB_ICONWARNING | MB_OK );
}
#endif // UNDER_CE
}
//-----------------------------------------------------------------------------
// Name: DXUtil_Trace()
// Desc: Outputs to the debug stream a formatted string with a variable-
// argument list.
//-----------------------------------------------------------------------------
VOID DXUtil_Trace( TCHAR* strMsg, ... )
{
#if defined(DEBUG) | defined(_DEBUG)
TCHAR strBuffer[512];
va_list args;
va_start(args, strMsg);
_vsntprintf( strBuffer, 512, strMsg, args );
va_end(args);
OutputDebugString( strBuffer );
#else
UNREFERENCED_PARAMETER(strMsg);
#endif
}
//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertStringToGUID()
// Desc: Converts a string to a GUID
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertStringToGUID( const TCHAR* strSrc, GUID* pGuidDest )
{
UINT aiTmp[10];
if( _stscanf( strSrc, TEXT("{%8X-%4X-%4X-%2X%2X-%2X%2X%2X%2X%2X%2X}"),
&pGuidDest->Data1,
&aiTmp[0], &aiTmp[1],
&aiTmp[2], &aiTmp[3],
&aiTmp[4], &aiTmp[5],
&aiTmp[6], &aiTmp[7],
&aiTmp[8], &aiTmp[9] ) != 11 )
{
ZeroMemory( pGuidDest, sizeof(GUID) );
return E_FAIL;
}
else
{
pGuidDest->Data2 = (USHORT) aiTmp[0];
pGuidDest->Data3 = (USHORT) aiTmp[1];
pGuidDest->Data4[0] = (BYTE) aiTmp[2];
pGuidDest->Data4[1] = (BYTE) aiTmp[3];
pGuidDest->Data4[2] = (BYTE) aiTmp[4];
pGuidDest->Data4[3] = (BYTE) aiTmp[5];
pGuidDest->Data4[4] = (BYTE) aiTmp[6];
pGuidDest->Data4[5] = (BYTE) aiTmp[7];
pGuidDest->Data4[6] = (BYTE) aiTmp[8];
pGuidDest->Data4[7] = (BYTE) aiTmp[9];
return S_OK;
}
}
//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertGUIDToStringCch()
// Desc: Converts a GUID to a string
// cchDestChar is the size in TCHARs of strDest. Be careful not to
// pass in sizeof(strDest) on UNICODE builds
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertGUIDToStringCch( const GUID* pGuidSrc, TCHAR* strDest, int cchDestChar )
{
int nResult = _sntprintf( strDest, cchDestChar, TEXT("{%0.8X-%0.4X-%0.4X-%0.2X%0.2X-%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X}"),
pGuidSrc->Data1, pGuidSrc->Data2, pGuidSrc->Data3,
pGuidSrc->Data4[0], pGuidSrc->Data4[1],
pGuidSrc->Data4[2], pGuidSrc->Data4[3],
pGuidSrc->Data4[4], pGuidSrc->Data4[5],
pGuidSrc->Data4[6], pGuidSrc->Data4[7] );
if( nResult < 0 )
return E_FAIL;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: CArrayList constructor
// Desc:
//-----------------------------------------------------------------------------
CArrayList::CArrayList( ArrayListType Type, UINT BytesPerEntry )
{
if( Type == AL_REFERENCE )
BytesPerEntry = sizeof(void*);
m_ArrayListType = Type;
m_pData = NULL;
m_BytesPerEntry = BytesPerEntry;
m_NumEntries = 0;
m_NumEntriesAllocated = 0;
}
//-----------------------------------------------------------------------------
// Name: CArrayList destructor
// Desc:
//-----------------------------------------------------------------------------
CArrayList::~CArrayList( void )
{
if( m_pData != NULL )
delete[] m_pData;
}
//-----------------------------------------------------------------------------
// Name: CArrayList::Add
// Desc: Adds pEntry to the list.
//-----------------------------------------------------------------------------
HRESULT CArrayList::Add( void* pEntry )
{
if( m_BytesPerEntry == 0 )
return E_FAIL;
if( m_pData == NULL || m_NumEntries + 1 > m_NumEntriesAllocated )
{
void* pDataNew;
UINT NumEntriesAllocatedNew;
if( m_NumEntriesAllocated == 0 )
NumEntriesAllocatedNew = 16;
else
NumEntriesAllocatedNew = m_NumEntriesAllocated * 2;
pDataNew = new BYTE[NumEntriesAllocatedNew * m_BytesPerEntry];
if( pDataNew == NULL )
return E_OUTOFMEMORY;
if( m_pData != NULL )
{
CopyMemory( pDataNew, m_pData, m_NumEntries * m_BytesPerEntry );
delete[] m_pData;
}
m_pData = pDataNew;
m_NumEntriesAllocated = NumEntriesAllocatedNew;
}
if( m_ArrayListType == AL_VALUE )
CopyMemory( (BYTE*)m_pData + (m_NumEntries * m_BytesPerEntry), pEntry, m_BytesPerEntry );
else
*(((void**)m_pData) + m_NumEntries) = pEntry;
m_NumEntries++;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: CArrayList::Remove
// Desc: Remove the item at Entry in the list, and collapse the array.
//-----------------------------------------------------------------------------
void CArrayList::Remove( UINT Entry )
{
// Decrement count
m_NumEntries--;
// Find the entry address
BYTE* pData = (BYTE*)m_pData + (Entry * m_BytesPerEntry);
// Collapse the array
MoveMemory( pData, pData + m_BytesPerEntry, ( m_NumEntries - Entry ) * m_BytesPerEntry );
}
//-----------------------------------------------------------------------------
// Name: CArrayList::GetPtr
// Desc: Returns a pointer to the Entry'th entry in the list.
//-----------------------------------------------------------------------------
void* CArrayList::GetPtr( UINT Entry )
{
if( m_ArrayListType == AL_VALUE )
return (BYTE*)m_pData + (Entry * m_BytesPerEntry);
else
return *(((void**)m_pData) + Entry);
}
//-----------------------------------------------------------------------------
// Name: CArrayList::Contains
// Desc: Returns whether the list contains an entry identical to the
// specified entry data.
//-----------------------------------------------------------------------------
bool CArrayList::Contains( void* pEntryData )
{
for( UINT iEntry = 0; iEntry < m_NumEntries; iEntry++ )
{
if( m_ArrayListType == AL_VALUE )
{
if( memcmp( GetPtr(iEntry), pEntryData, m_BytesPerEntry ) == 0 )
return true;
}
else
{
if( GetPtr(iEntry) == pEntryData )
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
// Name: BYTE helper functions
// Desc: cchDestChar is the size in BYTEs of strDest. Be careful not to
// pass use sizeof() if the strDest is a string pointer.
// eg.
// TCHAR* sz = new TCHAR[100]; // sizeof(sz) == 4
// TCHAR sz2[100]; // sizeof(sz2) == 200
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertAnsiStringToWideCb( WCHAR* wstrDestination, const CHAR* strSource, int cbDestChar )
{
return DXUtil_ConvertAnsiStringToWideCch( wstrDestination, strSource, cbDestChar / sizeof(WCHAR) );
}
HRESULT DXUtil_ConvertWideStringToAnsiCb( CHAR* strDestination, const WCHAR* wstrSource, int cbDestChar )
{
return DXUtil_ConvertWideStringToAnsiCch( strDestination, wstrSource, cbDestChar / sizeof(CHAR) );
}
HRESULT DXUtil_ConvertGenericStringToAnsiCb( CHAR* strDestination, const TCHAR* tstrSource, int cbDestChar )
{
return DXUtil_ConvertGenericStringToAnsiCch( strDestination, tstrSource, cbDestChar / sizeof(CHAR) );
}
HRESULT DXUtil_ConvertGenericStringToWideCb( WCHAR* wstrDestination, const TCHAR* tstrSource, int cbDestChar )
{
return DXUtil_ConvertGenericStringToWideCch( wstrDestination, tstrSource, cbDestChar / sizeof(WCHAR) );
}
HRESULT DXUtil_ConvertAnsiStringToGenericCb( TCHAR* tstrDestination, const CHAR* strSource, int cbDestChar )
{
return DXUtil_ConvertAnsiStringToGenericCch( tstrDestination, strSource, cbDestChar / sizeof(TCHAR) );
}
HRESULT DXUtil_ConvertWideStringToGenericCb( TCHAR* tstrDestination, const WCHAR* wstrSource, int cbDestChar )
{
return DXUtil_ConvertWideStringToGenericCch( tstrDestination, wstrSource, cbDestChar / sizeof(TCHAR) );
}
HRESULT DXUtil_ReadStringRegKeyCb( HKEY hKey, TCHAR* strRegName, TCHAR* strDest, DWORD cbDest, TCHAR* strDefault )
{
return DXUtil_ReadStringRegKeyCch( hKey, strRegName, strDest, cbDest / sizeof(TCHAR), strDefault );
}
HRESULT DXUtil_ConvertGUIDToStringCb( const GUID* pGuidSrc, TCHAR* strDest, int cbDestChar )
{
return DXUtil_ConvertGUIDToStringCch( pGuidSrc, strDest, cbDestChar / sizeof(TCHAR) );
}
#ifndef UNDER_CE
HRESULT DXUtil_GetDXSDKMediaPathCb( TCHAR* szDest, int cbDest )
{
return DXUtil_GetDXSDKMediaPathCch( szDest, cbDest / sizeof(TCHAR) );
}
HRESULT DXUtil_FindMediaFileCb( TCHAR* szDestPath, int cbDest, TCHAR* strFilename )
{
return DXUtil_FindMediaFileCch( szDestPath, cbDest / sizeof(TCHAR), strFilename );
}
#endif // !UNDER_CE
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -