//-----------------------------------------------------------------------------
// File: DXUtil.cpp
//
// Desc: Shortcut macros and functions for using DX objects
//
// Copyright (c) Microsoft Corporation. All rights reserved
//-----------------------------------------------------------------------------
#ifndef STRICT
#define STRICT
#endif // !STRICT
#include <windows.h>
#include <mmsystem.h>
#include <tchar.h>
#include <stdio.h>
#include <stdarg.h>
#include "DXUtil.h"
#ifdef UNICODE
typedef HINSTANCE (WINAPI* LPShellExecute)(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
#else
typedef HINSTANCE (WINAPI* LPShellExecute)(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd);
#endif
#ifndef UNDER_CE
//-----------------------------------------------------------------------------
// Name: DXUtil_GetDXSDKMediaPathCch()
// Desc: Returns the DirectX SDK media path
// cchDest is the size in TCHARs of strDest. Be careful not to
// pass in sizeof(strDest) on UNICODE builds.
//-----------------------------------------------------------------------------
HRESULT DXUtil_GetDXSDKMediaPathCch( TCHAR* strDest, int cchDest )
{
if( strDest == NULL || cchDest < 1 )
return E_INVALIDARG;
lstrcpy( strDest, TEXT("") );
// Open the appropriate registry key
HKEY hKey;
LONG lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
_T("Software\\Microsoft\\DirectX SDK"),
0, KEY_READ, &hKey );
if( ERROR_SUCCESS != lResult )
return E_FAIL;
DWORD dwType;
DWORD dwSize = cchDest * sizeof(TCHAR);
lResult = RegQueryValueEx( hKey, _T("DX9SDK Samples Path"), NULL,
&dwType, (BYTE*)strDest, &dwSize );
strDest[cchDest-1] = 0; // RegQueryValueEx doesn't NULL term if buffer too small
RegCloseKey( hKey );
if( ERROR_SUCCESS != lResult )
return E_FAIL;
const TCHAR* strMedia = _T("\\Media\\");
if( lstrlen(strDest) + lstrlen(strMedia) < cchDest )
_tcscat( strDest, strMedia );
else
return E_INVALIDARG;
return S_OK;
}
#endif // !UNDER_CE
#ifndef UNDER_CE
//-----------------------------------------------------------------------------
// Name: DXUtil_FindMediaFileCch()
// Desc: Returns a valid path to a DXSDK media file
// cchDest is the size in TCHARs of strDestPath. Be careful not to
// pass in sizeof(strDest) on UNICODE builds.
//-----------------------------------------------------------------------------
HRESULT DXUtil_FindMediaFileCch( TCHAR* strDestPath, int cchDest, TCHAR* strFilename )
{
HRESULT hr;
HANDLE file;
TCHAR* strShortNameTmp = NULL;
TCHAR strShortName[MAX_PATH];
int cchPath;
if( NULL==strFilename || NULL==strDestPath || cchDest < 1 )
return E_INVALIDARG;
lstrcpy( strDestPath, TEXT("") );
lstrcpy( strShortName, TEXT("") );
// Build full path name from strFileName (strShortName will be just the leaf filename)
cchPath = GetFullPathName(strFilename, cchDest, strDestPath, &strShortNameTmp);
if ((cchPath == 0) || (cchDest <= cchPath))
return E_FAIL;
if( strShortNameTmp )
lstrcpyn( strShortName, strShortNameTmp, MAX_PATH );
// first try to find the filename given a full path
file = CreateFile( strDestPath, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL );
if( INVALID_HANDLE_VALUE != file )
{
CloseHandle( file );
return S_OK;
}
// next try to find the filename in the current working directory (path stripped)
file = CreateFile( strShortName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL );
if( INVALID_HANDLE_VALUE != file )
{
_tcsncpy( strDestPath, strShortName, cchDest );
strDestPath[cchDest-1] = 0; // _tcsncpy doesn't NULL term if it runs out of space
CloseHandle( file );
return S_OK;
}
// last, check if the file exists in the media directory
if( FAILED( hr = DXUtil_GetDXSDKMediaPathCch( strDestPath, cchDest ) ) )
return hr;
if( lstrlen(strDestPath) + lstrlen(strShortName) < cchDest )
lstrcat( strDestPath, strShortName );
else
return E_INVALIDARG;
file = CreateFile( strDestPath, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL );
if( INVALID_HANDLE_VALUE != file )
{
CloseHandle( file );
return S_OK;
}
// On failure, just return the file as the path
_tcsncpy( strDestPath, strFilename, cchDest );
strDestPath[cchDest-1] = 0; // _tcsncpy doesn't NULL term if it runs out of space
return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
}
#endif // !UNDER_CE
//-----------------------------------------------------------------------------
// Name: DXUtil_ReadStringRegKeyCch()
// Desc: Helper function to read a registry key string
// cchDest is the size in TCHARs of strDest. Be careful not to
// pass in sizeof(strDest) on UNICODE builds.
//-----------------------------------------------------------------------------
HRESULT DXUtil_ReadStringRegKeyCch( HKEY hKey, TCHAR* strRegName, TCHAR* strDest,
DWORD cchDest, TCHAR* strDefault )
{
DWORD dwType;
DWORD cbDest = cchDest * sizeof(TCHAR);
if( ERROR_SUCCESS != RegQueryValueEx( hKey, strRegName, 0, &dwType,
(BYTE*)strDest, &cbDest ) )
{
_tcsncpy( strDest, strDefault, cchDest );
strDest[cchDest-1] = 0;
if( dwType != REG_SZ )
return E_FAIL;
return S_OK;
}
return E_FAIL;
}
//-----------------------------------------------------------------------------
// Name: DXUtil_WriteStringRegKey()
// Desc: Helper function to write a registry key string
//-----------------------------------------------------------------------------
HRESULT DXUtil_WriteStringRegKey( HKEY hKey, TCHAR* strRegName,
TCHAR* strValue )
{
if( NULL == strValue )
return E_INVALIDARG;
DWORD cbValue = ((DWORD)_tcslen(strValue)+1) * sizeof(TCHAR);
if( ERROR_SUCCESS != RegSetValueEx( hKey, strRegName, 0, REG_SZ,
(BYTE*)strValue, cbValue ) )
return E_FAIL;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DXUtil_ReadIntRegKey()
// Desc: Helper function to read a registry key int
//-----------------------------------------------------------------------------
HRESULT DXUtil_ReadIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD* pdwDest,
DWORD dwDefault )
{
DWORD dwType;
DWORD dwLength = sizeof(DWORD);
if( ERROR_SUCCESS != RegQueryValueEx( hKey, strRegName, 0, &dwType,
(BYTE*)pdwDest, &dwLength ) )
{
*pdwDest = dwDefault;
if( dwType != REG_DWORD )
return E_FAIL;
return S_OK;
}
return E_FAIL;
}
//-----------------------------------------------------------------------------
// Name: DXUtil_WriteIntRegKey()
// Desc: Helper function to write a registry key int
//-----------------------------------------------------------------------------
HRESULT DXUtil_WriteIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD dwValue )
{
if( ERROR_SUCCESS != RegSetValueEx( hKey, strRegName, 0, REG_DWORD,
(BYTE*)&dwValue, sizeof(DWORD) ) )
return E_FAIL;
return S_OK

jymstart
- 粉丝: 13
最新资源
- 恒润自研3611板卡422协议的三个驱动
- mat资源包jdk版本1.8 windows系统
- 基于Plecs的PSFB全桥原边移相+副边同步整流ZVS仿真研究
- 五相SVPWM技术:基于4矢量+双空间调制的反电势正弦与非正弦五相电机矢量控制 - 矢量控制 文档
- 基于Ansys Maxwell与OptiSlang的永磁同步电机多目标尺寸优化研究及实践
- COMSOL中单个金纳米颗粒光热仿真的波动光学与固体传热研究及文章复现
- 基于模糊PID控制器的风力温度智能调节与优化仿真模型构建分析 实战版
- 基于ADM自适应增量调制算法的Matlab性能仿真:功能介绍及使用matlab2022a版本详解
- 基于PI控制的PMSM永磁同步电机Simulink建模与仿真实践教程 (2025-07-28)
- 自动售货机MCGS7.7与西门子S7-1200PLC联机程序博途V14:带注释与IO分配表
- 风光储微电网并网协同运行的MATLAB Simulink仿真研究
- 纯电动汽车Simulink仿真模型建模详细步骤与技巧
- 移相与调频控制在LLC谐振变换器中的联合应用:宽范围调压仿真研究及文献参考 · 宽范围调压仿真 宝典
- 遗传算法GA在综合能源系统储能容量配置中的双层优化模型应用 详解
- 共交直流母线多台逆变器并联三相并网运行环流分析及抑制策略(含五种仿真)
- Spring Boot日志配置详细指南
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


