本文整理汇总了C++中GetWindowsDirectory函数的典型用法代码示例。如果您正苦于以下问题:C++ GetWindowsDirectory函数的具体用法?C++ GetWindowsDirectory怎么用?C++ GetWindowsDirectory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetWindowsDirectory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: noise_get_heavy
void noise_get_heavy(void (*func) (void *, int))
{
HANDLE srch;
WIN32_FIND_DATA finddata;
DWORD pid;
char winpath[MAX_PATH + 3];
GetWindowsDirectory(winpath, sizeof(winpath));
strcat(winpath, "\\*");
srch = FindFirstFile(winpath, &finddata);
if (srch != INVALID_HANDLE_VALUE) {
do {
func(&finddata, sizeof(finddata));
} while (FindNextFile(srch, &finddata));
FindClose(srch);
}
pid = GetCurrentProcessId();
func(&pid, sizeof(pid));
read_random_seed(func);
/* Update the seed immediately, in case another instance uses it. */
random_save_seed();
}
示例2: GetWindowsDirectory
//////////////////
// Set "hand" cursor to cue user that this is a link. If app has not set
// g_hCursorLink, then try to get the cursor from winhlp32.exe,
// resource 106, which is a pointing finger. This is a bit of a kludge,
// but it works.
//
BOOL CStaticLink::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (g_hCursorLink == NULL) {
static BOOL bTriedOnce = FALSE;
if (!bTriedOnce) {
CString windir;
GetWindowsDirectory(windir.GetBuffer(MAX_PATH), MAX_PATH);
windir.ReleaseBuffer();
windir += _T("\\winhlp32.exe");
HMODULE hModule = LoadLibrary(windir);
if (hModule) {
g_hCursorLink =
CopyCursor(::LoadCursor(hModule, MAKEINTRESOURCE(106)));
}
FreeLibrary(hModule);
bTriedOnce = TRUE;
}
}
if (g_hCursorLink) {
::SetCursor(g_hCursorLink);
return TRUE;
}
return FALSE;
}
示例3: noise_get_heavy
void noise_get_heavy(void (*func) (void *, int)) {
HANDLE srch;
HANDLE seedf;
WIN32_FIND_DATA finddata;
char winpath[MAX_PATH+3];
GetWindowsDirectory(winpath, sizeof(winpath));
strcat(winpath, "\\*");
srch = FindFirstFile(winpath, &finddata);
if (srch != INVALID_HANDLE_VALUE) {
do {
func(&finddata, sizeof(finddata));
} while (FindNextFile(srch, &finddata));
FindClose(srch);
}
if (!seedpath[0])
get_seedpath();
seedf = CreateFile(seedpath, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (seedf != INVALID_HANDLE_VALUE) {
while (1) {
char buf[1024];
DWORD len;
if (ReadFile(seedf, buf, sizeof(buf), &len, NULL) && len)
func(buf, len);
else
break;
}
CloseHandle(seedf);
}
}
示例4: location
/***************************************************************************
Function: FixFilePath
Purpose: Adds the correct path string to a file name according
to given file location
Input: Original file name
File location (Windows dir, System dir, Current dir or none)
Output: TRUE only if successful
Remarks: Trashes original file name
****************************************************************************/
BOOL CDLLVersion::FixFilePath (char * szFileName, int FileLoc)
{
char szPathStr [_MAX_PATH]; // Holds path prefix
switch (FileLoc)
{
case WIN_DIR:
// Get the name of the windows directory
if (GetWindowsDirectory (szPathStr, _MAX_PATH) == 0)
return FALSE; // Cannot get windows directory
break;
case SYS_DIR:
// Get the name of the windows SYSTEM directory
if (GetSystemDirectory (szPathStr, _MAX_PATH) == 0)
return FALSE; // Cannot get system directory
break;
case CUR_DIR:
// Get the name of the current directory
if (GetCurrentDirectory (_MAX_PATH, szPathStr) == 0)
return FALSE; // Cannot get current directory
break;
case NO_DIR:
lstrcpy (szPathStr,"");
break;
default:
return FALSE;
}
lstrcat (szPathStr, _T("\\"));
lstrcat (szPathStr, szFileName);
lstrcpy (szFileName, szPathStr);
return TRUE;
}
示例5: dha_uninstall
int dha_uninstall(void)
{
SC_HANDLE hSCManager = NULL;
SC_HANDLE hService = NULL;
char szPath[MAX_PATH];
int result = 0;
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
hService = OpenService(hSCManager, DRV_NAME, SERVICE_ALL_ACCESS);
dha_stop();
result = DeleteService(hService);
if(!result) print_last_error("Error while deleting service");
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
GetWindowsDirectory(szPath, MAX_PATH);
strcpy(szPath + strlen(szPath), "\\system32\\drivers\\" DRV_FILENAME);
DeleteFile(szPath);
return 0;
}
示例6: TRACE
///////////////////////////////////////////////////////////////////////////////
// SetDefaultCursor
void CXHyperLink::SetDefaultCursor()
{
if (m_hLinkCursor == NULL) // No cursor handle - try to load one
{
// First try to load the Win98 / Windows 2000 hand cursor
TRACE(_T("loading from IDC_HAND\n"));
m_hLinkCursor = AfxGetApp()->LoadStandardCursor(IDC_HAND);
if (m_hLinkCursor == NULL) // Still no cursor handle -
// load the WinHelp hand cursor
{
// The following appeared in Paul DiLascia's Jan 1998 MSJ articles.
// It loads a "hand" cursor from the winhlp32.exe module.
TRACE(_T("loading from winhlp32\n"));
// Get the windows directory
CString strWndDir;
GetWindowsDirectory(strWndDir.GetBuffer(MAX_PATH), MAX_PATH);
strWndDir.ReleaseBuffer();
strWndDir += _T("\\winhlp32.exe");
// This retrieves cursor #106 from winhlp32.exe, which is a hand pointer
HMODULE hModule = LoadLibrary(strWndDir);
if (hModule)
{
HCURSOR hHandCursor = ::LoadCursor(hModule, MAKEINTRESOURCE(106));
if (hHandCursor)
m_hLinkCursor = CopyCursor(hHandCursor);
FreeLibrary(hModule);
}
}
}
}
示例7: get_home
static void
get_home(void)
{
int len;
char tmpstr[MAX_PATH+1];
char* homedrive;
char* homepath;
homedrive = get_env("HOMEDRIVE");
homepath = get_env("HOMEPATH");
if (!homedrive || !homepath) {
if (len = GetWindowsDirectory(tmpstr,MAX_PATH)) {
home = emalloc(len+1);
strcpy(home,tmpstr);
} else
error("HOMEDRIVE or HOMEPATH is not set and GetWindowsDir failed");
} else {
home = emalloc(strlen(homedrive)+strlen(homepath)+1);
strcpy(home, homedrive);
strcat(home, homepath);
}
free_env_val(homedrive);
free_env_val(homepath);
}
示例8: php_init_config
int php_init_config(char *php_ini_path_override)
{
char *env_location, *php_ini_search_path;
int safe_mode_state;
char *open_basedir;
int free_ini_search_path=0;
zend_file_handle fh;
PLS_FETCH();
if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
return FAILURE;
}
zend_llist_init(&extension_lists.engine, sizeof(zval), (llist_dtor_func_t) free_estring, 1);
zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1);
safe_mode_state = PG(safe_mode);
open_basedir = PG(open_basedir);
env_location = getenv("PHPRC");
if (!env_location) {
env_location="";
}
if (php_ini_path_override) {
php_ini_search_path = php_ini_path_override;
free_ini_search_path = 0;
} else {
char *default_location;
int free_default_location;
#ifdef PHP_WIN32
default_location = (char *) emalloc(512);
if (!GetWindowsDirectory(default_location,255)) {
default_location[0]=0;
}
free_default_location=1;
#else
default_location = PHP_CONFIG_FILE_PATH;
free_default_location=0;
#endif
php_ini_search_path = (char *) emalloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1);
free_ini_search_path = 1;
if(env_location && env_location[0]) {
sprintf(php_ini_search_path, ".%c%s%c%s", ZEND_PATHS_SEPARATOR, env_location, ZEND_PATHS_SEPARATOR, default_location);
} else {
sprintf(php_ini_search_path, ".%c%s", ZEND_PATHS_SEPARATOR, default_location);
}
if (free_default_location) {
efree(default_location);
}
}
PG(safe_mode) = 0;
PG(open_basedir) = NULL;
fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path);
if (free_ini_search_path) {
efree(php_ini_search_path);
}
PG(safe_mode) = safe_mode_state;
PG(open_basedir) = open_basedir;
if (!fh.handle.fp) {
return SUCCESS; /* having no configuration file is ok */
}
fh.type = ZEND_HANDLE_FP;
fh.filename = php_ini_opened_path;
zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
if (php_ini_opened_path) {
zval tmp;
tmp.value.str.len = strlen(php_ini_opened_path);
tmp.value.str.val = zend_strndup(php_ini_opened_path, tmp.value.str.len);
tmp.type = IS_STRING;
zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"),(void *) &tmp,sizeof(zval), NULL);
persist_alloc(php_ini_opened_path);
}
return SUCCESS;
}
示例9: GetComspecFromEnvVar
LPCWSTR GetComspecFromEnvVar(wchar_t* pszComspec, DWORD cchMax, ComSpecBits Bits/* = csb_SameOS*/)
{
if (!pszComspec || (cchMax < MAX_PATH))
{
_ASSERTE(pszComspec && (cchMax >= MAX_PATH));
return NULL;
}
*pszComspec = 0;
BOOL bWin64 = IsWindows64();
if (!((Bits == csb_x32) || (Bits == csb_x64)))
{
if (GetEnvironmentVariable(L"ComSpec", pszComspec, cchMax))
{
// Не должен быть (даже случайно) ConEmuC.exe
const wchar_t* pszName = PointToName(pszComspec);
if (!pszName || !lstrcmpi(pszName, L"ConEmuC.exe") || !lstrcmpi(pszName, L"ConEmuC64.exe")
|| !FileExists(pszComspec)) // ну и существовать должен
{
pszComspec[0] = 0;
}
}
}
// Если не удалось определить через переменную окружения - пробуем обычный "cmd.exe" из System32
if (pszComspec[0] == 0)
{
int n = GetWindowsDirectory(pszComspec, cchMax - 20);
if (n > 0 && (((DWORD)n) < (cchMax - 20)))
{
// Добавить \System32\cmd.exe
// Warning! 'c:\Windows\SysNative\cmd.exe' не прокатит, т.к. доступен
// только для 32битных приложений. А нам нужно в общем виде.
// Если из 32битного нужно запустить 64битный cmd.exe - нужно выключать редиректор.
if (!bWin64 || (Bits != csb_x32))
{
_wcscat_c(pszComspec, cchMax, (pszComspec[n-1] == L'\\') ? L"System32\\cmd.exe" : L"\\System32\\cmd.exe");
}
else
{
_wcscat_c(pszComspec, cchMax, (pszComspec[n-1] == L'\\') ? L"SysWOW64\\cmd.exe" : L"\\SysWOW64\\cmd.exe");
}
}
}
if (pszComspec[0] && !FileExists(pszComspec))
{
_ASSERTE("Comspec not found! File not exists!");
pszComspec[0] = 0;
}
// Last chance
if (pszComspec[0] == 0)
{
_ASSERTE(pszComspec[0] != 0); // Уже должен был быть определен
//lstrcpyn(pszComspec, L"cmd.exe", cchMax);
wchar_t *psFilePart;
DWORD n = SearchPathW(NULL, L"cmd.exe", NULL, cchMax, pszComspec, &psFilePart);
if (!n || (n >= cchMax))
_wcscpy_c(pszComspec, cchMax, L"cmd.exe");
}
return pszComspec;
}
示例10: CPropertyPage
CThirdPage::CThirdPage()
: CPropertyPage(CThirdPage::IDD),
m_manufacturerSelected( NULL ),
m_modelSelected( NULL ),
m_genericPostscript( NULL ),
m_genericPCL( NULL ),
m_initialized(false),
m_printerImage( NULL )
{
static const int bufferSize = 32768;
TCHAR windowsDirectory[bufferSize];
CString header;
WIN32_FIND_DATA findFileData;
HANDLE findHandle;
CString prnFiles;
CString ntPrint;
OSStatus err;
BOOL ok;
m_psp.dwFlags &= ~(PSP_HASHELP);
m_psp.dwFlags |= PSP_DEFAULT|PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE;
m_psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_INSTALL_TITLE);
m_psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_INSTALL_SUBTITLE);
//
// load printers from ntprint.inf
//
ok = GetWindowsDirectory( windowsDirectory, bufferSize );
err = translate_errno( ok, errno_compat(), kUnknownErr );
require_noerr( err, exit );
//
// <rdar://problem/4826126>
//
// If there are no *prn.inf files, we'll assume that the information
// is in ntprint.inf
//
prnFiles.Format( L"%s\\%s", windowsDirectory, kVistaPrintFiles );
findHandle = FindFirstFile( prnFiles, &findFileData );
if ( findHandle != INVALID_HANDLE_VALUE )
{
CString absolute;
absolute.Format( L"%s\\inf\\%s", windowsDirectory, findFileData.cFileName );
err = LoadPrintDriverDefsFromFile( m_manufacturers, absolute, false );
require_noerr( err, exit );
while ( FindNextFile( findHandle, &findFileData ) )
{
absolute.Format( L"%s\\inf\\%s", windowsDirectory, findFileData.cFileName );
err = LoadPrintDriverDefsFromFile( m_manufacturers, absolute, false );
require_noerr( err, exit );
}
FindClose( findHandle );
}
else
{
ntPrint.Format(L"%s\\%s", windowsDirectory, kNTPrintFile);
err = LoadPrintDriverDefsFromFile( m_manufacturers, ntPrint, false );
require_noerr(err, exit);
}
//
// load printer drivers that have been installed on this machine
//
err = LoadPrintDriverDefs( m_manufacturers );
require_noerr(err, exit);
//
// load our own special generic printer defs
//
err = LoadGenericPrintDriverDefs( m_manufacturers );
require_noerr( err, exit );
exit:
return;
}
示例11: PH_GetSysFolerInfo
//取得系統環境
void PH_GetSysFolerInfo()
{
GetSystemDirectory(SystemDirectory,MAX_PATHa);
GetWindowsDirectory(WindowDirectory,MAX_PATHa);
printf("系統目錄 : %s\nWIN目錄 : %s\n",SystemDirectory,WindowDirectory);
}
示例12: getDefaultConfigFileName
static Common::String getDefaultConfigFileName() {
char configFile[MAXPATHLEN];
#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
OSVERSIONINFO win32OsVersion;
ZeroMemory(&win32OsVersion, sizeof(OSVERSIONINFO));
win32OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&win32OsVersion);
// Check for non-9X version of Windows.
if (win32OsVersion.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) {
// Use the Application Data directory of the user profile.
if (win32OsVersion.dwMajorVersion >= 5) {
if (!GetEnvironmentVariable("APPDATA", configFile, sizeof(configFile)))
error("Unable to access application data directory");
} else {
if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile)))
error("Unable to access user profile directory");
strcat(configFile, "\\Application Data");
CreateDirectory(configFile, NULL);
}
strcat(configFile, "\\ScummVM");
CreateDirectory(configFile, NULL);
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
FILE *tmp = NULL;
if ((tmp = fopen(configFile, "r")) == NULL) {
// Check windows directory
char oldConfigFile[MAXPATHLEN];
GetWindowsDirectory(oldConfigFile, MAXPATHLEN);
strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE);
if ((tmp = fopen(oldConfigFile, "r"))) {
strcpy(configFile, oldConfigFile);
fclose(tmp);
}
} else {
fclose(tmp);
}
} else {
// Check windows directory
GetWindowsDirectory(configFile, MAXPATHLEN);
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
}
#elif defined(UNIX)
// On UNIX type systems, by default we store the config file inside
// to the HOME directory of the user.
//
// GP2X is Linux based but Home dir can be read only so do not use
// it and put the config in the executable dir.
//
// On the iPhone, the home dir of the user when you launch the app
// from the Springboard, is /. Which we don't want.
#if defined(ANDROID)
const char *home = "/sdcard";
#else
const char *home = getenv("HOME");
#endif
if (home != NULL && strlen(home) < MAXPATHLEN)
snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE);
else
strcpy(configFile, DEFAULT_CONFIG_FILE);
#else
strcpy(configFile, DEFAULT_CONFIG_FILE);
#endif
return configFile;
}
示例13: CK_DEFINE_FUNCTION
//.........这里部分代码省略.........
rv = CKR_GENERAL_ERROR;
CI_VarLogEntry("CI_FindConfFile",
"opening file '%s': %s",
rv, 0, CK_I_config_fname, strerror(errno));
return rv;
}else
{
TC_free(CK_I_config_fname);
CK_I_config_fname = NULL_PTR; /* nicht gefunden */
}
}
else
{
fclose(f);
}
}
/* if no config-file was found in the user profile, search the system-directory */
if ( CK_I_config_fname == NULL )
{
CK_CHAR_PTR system_dir = NULL_PTR;
UINT retlen;
system_dir = TC_malloc(sizeof(CK_CHAR) * MAX_PATH);
if( system_dir == NULL_PTR )
{
rv = CKR_HOST_MEMORY;
CI_LogEntry("CI_FindConfFile", "Allocating Buffer Space",
rv, 0);
return rv;
}
retlen =GetWindowsDirectory(system_dir, MAX_PATH);
if(retlen == 0 )
{
rv = CKR_GENERAL_ERROR;
CI_VarLogEntry("CI_FindConfFile",
"Retrieving Windows System Directory GetLastError(): %i",
rv, 0, GetLastError());
return rv;
}
if(retlen > MAX_PATH)
{
/* realloc would move the block first */
TC_free(system_dir);
system_dir = TC_malloc(sizeof(CK_CHAR) * retlen);
if( system_dir == NULL_PTR )
{
rv = CKR_HOST_MEMORY;
CI_LogEntry("CI_FindConfFile", "Allocating Buffer Space",
rv, 0);
return rv;
}
GetSystemDirectory(system_dir , retlen);
if(retlen == 0 )
{
rv = CKR_GENERAL_ERROR;
CI_VarLogEntry("CI_FindConfFile",
"Retrieving Windows System Directory GetLastError(): %i",
rv, 0, GetLastError());
TC_free(system_dir);
return rv;
示例14: WinMain
//.........这里部分代码省略.........
/* Warn user about what we are about to do */
if (!silent) {
TCHAR buf[256];
LoadString(phInstance, IDS_INTRO, buf, sizeof(buf)/sizeof(TCHAR)-1);
if (MessageBox(HWND_DESKTOP, buf, title, MB_YESNO) != IDYES)
return 0;
}
/* Check if monitor is still in use */
rc = EnumPorts(NULL, 2, (LPBYTE)buffer, sizeof(buffer),
&needed, &returned);
pi2 = (PORT_INFO_2 *)buffer;
if (rc) {
for (i=0; i<returned; i++) {
if (lstrcmp(pi2[i].pMonitorName, monitorname) == 0) {
TCHAR buf[256];
LoadString(phInstance, IDS_INUSE, buf, sizeof(buf)/sizeof(TCHAR)-1);
wsprintf(sysdir, buf, pi2[i].pPortName);
MessageBox(HWND_DESKTOP, sysdir, title, MB_OK);
return 1;
}
}
}
else
return message(IDS_ENUMPORTS_FAILED);
/* Try to delete the monitor */
if (!DeleteMonitor(NULL,
NULL /* is_winnt ? MONITORENVNT : MONITORENV95 */,
monitorname))
return message(IDS_DELETEMONITOR_FAILED);
/* Delete the monitor files */
if (!GetSystemDirectory(sysdir, sizeof(sysdir)))
return message(IDS_NOSYSDIR);
lstrcpy(buffer, sysdir);
lstrcat(buffer, "\\");
lstrcat(buffer, is_winnt ? MONITORDLLNT : MONITORDLL95);
if (!DeleteFile(buffer))
return message(IDS_ERROR_DELETE_DLL);
lstrcpy(buffer, sysdir);
lstrcat(buffer, "\\");
lstrcat(buffer, MONITORHLP);
if (!DeleteFile(buffer))
return message(IDS_ERROR_DELETE_HELP);
lstrcpy(buffer, sysdir);
lstrcat(buffer, "\\");
lstrcat(buffer, REDCONF);
if (!DeleteFile(buffer))
return message(IDS_ERROR_DELETE_REDCONF);
/* delete registry entries for uninstall */
if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, UNINSTALLKEY, 0,
KEY_ALL_ACCESS, &hkey)) == ERROR_SUCCESS) {
RegDeleteKey(hkey, MONITORKEY);
RegCloseKey(hkey);
}
/* Delete this program, but we can't do it while we are running.
* Defer deletion until next reboot
*/
wsprintf(buffer, TEXT("%s\\%s"), sysdir, UNINSTALLPROG);
if (is_winnt) {
MoveFileEx(buffer, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
}
else {
char ininame[256];
GetWindowsDirectory(ininame, sizeof(ininame));
lstrcat(ininame, "\\wininit.ini");
/* This method is dodgy, because multiple applications
* using this method to delete files will overwrite
* earlier delete instructions.
*/
WritePrivateProfileString("Rename", "NUL", buffer, ininame);
SetLastError(0);
}
#ifdef UNUSED
/* We should delete this program, but we can't do it
* while we are running.
* I think there is a registry key we can create which says
* "Delete these files on next reboot", but I can't find the
* documentation about it.
* Instead, run a DOS window once to delete the file
*/
if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
0, KEY_ALL_ACCESS, &hkey)) == ERROR_SUCCESS) {
wsprintf(buffer, "command /c del %s\\%s", sysdir, UNINSTALLPROG);
RegSetValueEx(hkey, MONITORKEY, 0, REG_SZ,
(CONST BYTE *)buffer, lstrlen(buffer)+1);
}
#endif
message(IDS_UNINSTALLED);
return 0;
}
示例15: Create
/*****************************************************************************
* Create: allocates osd-text video thread output method
*****************************************************************************
* This function allocates and initializes a Clone vout method.
*****************************************************************************/
static int Create( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys;
char *psz_fontfile = NULL;
int i, i_error;
int i_fontsize = 0;
vlc_value_t val;
/* Allocate structure */
p_sys = malloc( sizeof( filter_sys_t ) );
if( !p_sys )
{
msg_Err( p_filter, "out of memory" );
return VLC_ENOMEM;
}
p_sys->p_face = 0;
p_sys->p_library = 0;
for( i = 0; i < 256; i++ )
{
p_sys->pi_gamma[i] = (uint8_t)( pow( (double)i * 255.0f, 0.5f ) );
}
var_Create( p_filter, "freetype-font",
VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_Create( p_filter, "freetype-fontsize",
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_filter, "freetype-rel-fontsize",
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
/* Look what method was requested */
var_Get( p_filter, "freetype-font", &val );
psz_fontfile = val.psz_string;
if( !psz_fontfile || !*psz_fontfile )
{
if( psz_fontfile ) free( psz_fontfile );
psz_fontfile = (char *)malloc( PATH_MAX + 1 );
#ifdef WIN32
GetWindowsDirectory( psz_fontfile, PATH_MAX + 1 );
strcat( psz_fontfile, "\\fonts\\arial.ttf" );
#elif SYS_DARWIN
strcpy( psz_fontfile, DEFAULT_FONT );
#else
msg_Err( p_filter, "user didn't specify a font" );
goto error;
#endif
}
i_error = FT_Init_FreeType( &p_sys->p_library );
if( i_error )
{
msg_Err( p_filter, "couldn't initialize freetype" );
goto error;
}
i_error = FT_New_Face( p_sys->p_library, psz_fontfile ? psz_fontfile : "",
0, &p_sys->p_face );
if( i_error == FT_Err_Unknown_File_Format )
{
msg_Err( p_filter, "file %s have unknown format", psz_fontfile );
goto error;
}
else if( i_error )
{
msg_Err( p_filter, "failed to load font file %s", psz_fontfile );
goto error;
}
i_error = FT_Select_Charmap( p_sys->p_face, ft_encoding_unicode );
if( i_error )
{
msg_Err( p_filter, "Font has no unicode translation table" );
goto error;
}
p_sys->i_use_kerning = FT_HAS_KERNING( p_sys->p_face );
var_Get( p_filter, "freetype-fontsize", &val );
if( val.i_int )
{
i_fontsize = val.i_int;
}
else
{
var_Get( p_filter, "freetype-rel-fontsize", &val );
i_fontsize = (int)p_filter->fmt_out.video.i_height / val.i_int;
}
if( i_fontsize <= 0 )
{
msg_Warn( p_filter, "Invalid fontsize, using 12" );
i_fontsize = 12;
}
msg_Dbg( p_filter, "Using fontsize: %i", i_fontsize);
//.........这里部分代码省略.........