本文整理匯總了C++中GetCurrentDirectoryW函數的典型用法代碼示例。如果您正苦於以下問題:C++ GetCurrentDirectoryW函數的具體用法?C++ GetCurrentDirectoryW怎麽用?C++ GetCurrentDirectoryW使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetCurrentDirectoryW函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: getCurrentDir
wchar_t * getCurrentDir() {
// current directory 를 구한다.
wchar_t *buf = NULL;
uint32_t buflen = 0;
buflen = GetCurrentDirectoryW(buflen, buf); // 디렉토리 문자열의 길이를 모르니 0이나 -1을 넣으면 return해줌
if (0 == buflen)
{
print("err, GetCurrentDirectoryW() failed. gle = 0x%08x", GetLastError());
return false;
}
buf = (PWSTR)malloc(sizeof(WCHAR) * buflen);
if (0 == GetCurrentDirectoryW(buflen, buf))
{
print("err, GetCurrentDirectoryW() failed. gle = 0x%08x", GetLastError());
free(buf);
return false;
}
return buf;
}
示例2: GetCurrentDirectoryPath
gs2d::str_type::string GetCurrentDirectoryPath()
{
gs2d::str_type::char_t currentDirectoryBuffer[65536];
#ifdef GS2D_STR_TYPE_WCHAR
GetCurrentDirectoryW(65535, currentDirectoryBuffer);
#else
GetCurrentDirectoryA(65535, currentDirectoryBuffer);
#endif
return AddLastSlash(currentDirectoryBuffer);
}
示例3: tb_directory_curt
tb_size_t tb_directory_curt(tb_char_t* path, tb_size_t maxn)
{
// check
tb_assert_and_check_return_val(path && maxn > 4, 0);
// the current directory
tb_wchar_t curt[TB_PATH_MAXN] = {0};
GetCurrentDirectoryW(TB_PATH_MAXN, curt);
// wtoa
return tb_wtoa(path, curt, maxn);
}
示例4: ExitAndRestart
void ExitAndRestart() {
// This preserves arguments (for example, config file) and working directory.
wchar_t moduleFilename[MAX_PATH];
wchar_t workingDirectory[MAX_PATH];
GetCurrentDirectoryW(MAX_PATH, workingDirectory);
const wchar_t *cmdline = RemoveExecutableFromCommandLine(GetCommandLineW());
GetModuleFileName(GetModuleHandle(NULL), moduleFilename, MAX_PATH);
ShellExecute(NULL, NULL, moduleFilename, cmdline, workingDirectory, SW_SHOW);
ExitProcess(0);
}
示例5: sys_curdir
/*
* Arguments: [path (string)]
* Returns: [boolean | pathname (string)]
*/
static int
sys_curdir (lua_State *L)
{
const char *path = lua_tostring(L, 1);
if (path) {
int res;
#ifndef _WIN32
res = chdir(path);
#else
{
void *os_path = utf8_to_filename(path);
if (!os_path)
return sys_seterror(L, ERROR_NOT_ENOUGH_MEMORY);
res = is_WinNT
? !SetCurrentDirectoryW(os_path)
: !SetCurrentDirectoryA(os_path);
free(os_path);
}
#endif
if (!res) {
lua_pushboolean(L, 1);
return 1;
}
} else {
#ifndef _WIN32
char dir[MAX_PATHNAME];
if (getcwd(dir, MAX_PATHNAME)) {
lua_pushstring(L, dir);
return 1;
}
#else
WCHAR os_dir[MAX_PATHNAME];
const int n = is_WinNT
? GetCurrentDirectoryW(MAX_PATHNAME, os_dir)
: GetCurrentDirectoryA(MAX_PATHNAME, (char *) os_dir);
if (n != 0 && n < MAX_PATHNAME) {
void *dir = filename_to_utf8(os_dir);
if (!dir)
return sys_seterror(L, ERROR_NOT_ENOUGH_MEMORY);
lua_pushstring(L, dir);
free(dir);
return 1;
}
#endif
}
return sys_seterror(L, 0);
}
示例6: set_working_directory
bool set_working_directory(string dname) {
tstring tstr_dname = widen(dname);
replace(tstr_dname.begin(), tstr_dname.end(), '/', '\\');
if (SetCurrentDirectoryW(tstr_dname.c_str()) != 0) {
WCHAR wstr_buffer[MAX_PATH + 1];
if (GetCurrentDirectoryW(MAX_PATH + 1, wstr_buffer) != 0) {
working_directory = add_slash(shorten(wstr_buffer));
return true;
}
}
return false;
}
示例7: win32_getcwd
/*
** Get the current working directory.
**
** On windows, the name is converted from unicode to UTF8 and all '\\'
** characters are converted to '/'. No conversions are needed on
** unix.
*/
void win32_getcwd(char *zBuf, int nBuf){
int i;
char *zUtf8;
wchar_t *zWide = fossil_malloc( sizeof(wchar_t)*nBuf );
if( GetCurrentDirectoryW(nBuf, zWide)==0 ){
fossil_fatal("cannot find current working directory.");
}
zUtf8 = fossil_filename_to_utf8(zWide);
fossil_free(zWide);
for(i=0; zUtf8[i]; i++) if( zUtf8[i]=='\\' ) zUtf8[i] = '/';
strncpy(zBuf, zUtf8, nBuf);
fossil_filename_free(zUtf8);
}
示例8: mPath
Directory::Directory() :
mPath(L""),
mName(L""),
mAttributes(0)
{
wchar_t Path[MAX_PATH] = {L'\0'};
GetCurrentDirectoryW(MAX_PATH, Path);
mAttributes = GetFileAttributesW(Path);
mPath = Path;
mName = Path;
};
示例9: get_current_directory
/**
* @brief retrieve currnt directory
* caller must free returned memroy pointer.
* @param
* @see
* @remarks
* @code
* @endcode
* @return
**/
wchar_t* get_current_directory(void)
{
wchar_t *buf = NULL;
uint32_t buflen = 0;
buflen = GetCurrentDirectoryW(buflen, buf);
if (0 == buflen)
{
print("err ] GetCurrentDirectoryW() failed. gle = 0x%08x", GetLastError());
return NULL;
}
buf = (PWSTR)malloc(sizeof(WCHAR)* buflen);
if (0 == GetCurrentDirectoryW(buflen, buf))
{
print("err ] GetCurrentDirectoryW() failed. gle = 0x%08x", GetLastError());
free(buf);
return NULL;
}
return buf;
}
示例10: GetCurrentDirectoryW
QString Application::CurrentWorkingDirectory()
{
#ifdef _WINDOWS
WCHAR str[MAX_PATH+1] = {};
GetCurrentDirectoryW(MAX_PATH, str);
QString qstr = WStringToQString(str);
#else
QString qstr = QDir::currentPath();
#endif
if (!qstr.endsWith(QDir::separator()))
qstr += QDir::separator();
return qstr;
}
示例11: ReadFromFile
BOOL ReadFromFile()
{
IFileOpenDialog *pDlg;
COMDLG_FILTERSPEC FileTypes[] = {
{ L"PS2 MemoryCard files", L"*.ps2" },
{ L"All files", L"*.*" }
};
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDlg));
WCHAR cPath[MAX_PATH] = L"";
GetCurrentDirectoryW(sizeof(cPath) / sizeof(cPath[0]), cPath);
IShellItem *psiFolder, *psiParent;
SHCreateItemFromParsingName(cPath, NULL, IID_PPV_ARGS(&psiFolder));
psiFolder->GetParent(&psiParent);
//初期フォルダの指定
pDlg->SetFolder(psiFolder);
//フィルターの指定
pDlg->SetFileTypes(_countof(FileTypes), FileTypes);
//ダイアログ表示
hr = pDlg->Show(NULL);
//ファイル名
LPOLESTR pwsz = NULL;
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pDlg->GetResult(&pItem);
if (SUCCEEDED(hr))
{
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pwsz);
if (SUCCEEDED(hr))
{
HANDLE hFile;
hFile = CreateFile(pwsz, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile)
{
DWORD BytesRead;
BOOL b = ReadFile(hFile, &(byteMemDat.Byte), sizeof(byteMemDat), &BytesRead, NULL);
if (BytesRead)
{
CloseHandle(hFile);
}
}
}
}
}
UpdateDataList(&byteMemDat);
return TRUE;
}
示例12: do_QueryInterface
/**
* Loads the plugin into memory using NSPR's shared-library loading
* mechanism. Handles platform differences in loading shared libraries.
*/
nsresult nsPluginFile::LoadPlugin(PRLibrary **outLibrary)
{
nsCOMPtr<nsILocalFile> plugin = do_QueryInterface(mPlugin);
if (!plugin)
return NS_ERROR_NULL_POINTER;
PRBool protectCurrentDirectory = PR_TRUE;
nsAutoString pluginFolderPath;
plugin->GetPath(pluginFolderPath);
PRInt32 idx = pluginFolderPath.RFindChar('\\');
if (kNotFound == idx)
return NS_ERROR_FILE_INVALID_PATH;
if (Substring(pluginFolderPath, idx).LowerCaseEqualsLiteral("\\np32dsw.dll")) {
protectCurrentDirectory = PR_FALSE;
}
pluginFolderPath.SetLength(idx);
BOOL restoreOrigDir = FALSE;
WCHAR aOrigDir[MAX_PATH + 1];
DWORD dwCheck = GetCurrentDirectoryW(MAX_PATH, aOrigDir);
NS_ASSERTION(dwCheck <= MAX_PATH + 1, "Error in Loading plugin");
if (dwCheck <= MAX_PATH + 1) {
restoreOrigDir = SetCurrentDirectoryW(pluginFolderPath.get());
NS_ASSERTION(restoreOrigDir, "Error in Loading plugin");
}
if (protectCurrentDirectory) {
mozilla::NS_SetDllDirectory(NULL);
}
nsresult rv = plugin->Load(outLibrary);
if (NS_FAILED(rv))
*outLibrary = NULL;
if (protectCurrentDirectory) {
mozilla::NS_SetDllDirectory(L"");
}
if (restoreOrigDir) {
BOOL bCheck = SetCurrentDirectoryW(aOrigDir);
NS_ASSERTION(bCheck, "Error in Loading plugin");
}
return rv;
}
示例13: GetCurrentDirectoryW
SString SharedUtil::GetSystemCurrentDirectory ( void )
{
#ifdef WIN32
wchar_t szResult [ 1024 ] = L"";
GetCurrentDirectoryW ( NUMELMS ( szResult ), szResult );
if ( IsShortPathName( szResult ) )
return GetSystemLongPathName( ToUTF8( szResult ) );
return ToUTF8( szResult );
#else
char szBuffer[ MAX_PATH ];
getcwd ( szBuffer, MAX_PATH - 1 );
return szBuffer;
#endif
}
示例14: GetCurrentDirectoryW
StString StProcess::getWorkingFolder() {
StString aWorkingFolder;
#ifdef _WIN32
// determine buffer length (in characters, including NULL-terminated symbol)
DWORD aBuffLen = GetCurrentDirectoryW(0, NULL);
stUtfWide_t* aBuff = new stUtfWide_t[size_t(aBuffLen + 1)];
// take current directory
GetCurrentDirectoryW(aBuffLen, aBuff);
aBuff[aBuffLen - 1] = (aBuff[aBuffLen - 2] == L'\\') ? L'\0' : L'\\';
aBuff[aBuffLen] = L'\0';
aWorkingFolder = StString(aBuff);
delete[] aBuff;
#else
char* aPath = getcwd(NULL, 0);
if(aPath == NULL) {
// allocation error - should never happens
return StString();
}
aWorkingFolder = StString(aPath) + SYS_FS_SPLITTER;
free(aPath); // free alien buffer
#endif
return aWorkingFolder;
}
示例15: uv_split_path
static int uv_split_path(const WCHAR* filename, WCHAR** dir,
WCHAR** file) {
size_t len, i;
if (filename == NULL) {
if (dir != NULL)
*dir = NULL;
*file = NULL;
return 0;
}
len = wcslen(filename);
i = len;
while (i > 0 && filename[--i] != '\\' && filename[i] != '/');
if (i == 0) {
if (dir) {
*dir = (WCHAR*)uv__malloc((MAX_PATH + 1) * sizeof(WCHAR));
if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!GetCurrentDirectoryW(MAX_PATH, *dir)) {
uv__free(*dir);
*dir = NULL;
return -1;
}
}
*file = wcsdup(filename);
} else {
if (dir) {
*dir = (WCHAR*)uv__malloc((i + 2) * sizeof(WCHAR));
if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
wcsncpy(*dir, filename, i + 1);
(*dir)[i + 1] = L'\0';
}
*file = (WCHAR*)uv__malloc((len - i) * sizeof(WCHAR));
if (!*file) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
wcsncpy(*file, filename + i + 1, len - i - 1);
(*file)[len - i - 1] = L'\0';
}
return 0;
}