本文整理汇总了C++中GetCurrentDirectoryW函数的典型用法代码示例。如果您正苦于以下问题:C++ GetCurrentDirectoryW函数的具体用法?C++ GetCurrentDirectoryW怎么用?C++ GetCurrentDirectoryW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetCurrentDirectoryW函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:ian0371,项目名称:BoB_4th,代码行数:20,代码来源:lib.cpp
示例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);
}
开发者ID:andresan87,项目名称:Torch,代码行数:12,代码来源:Platform.windows.cpp
示例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);
}
开发者ID:1060460048,项目名称:tbox,代码行数:12,代码来源:directory.c
示例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);
}
开发者ID:AdmiralCurtiss,项目名称:ppsspp,代码行数:12,代码来源:Misc.cpp
示例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);
}
开发者ID:ELMERzark,项目名称:luasys,代码行数:57,代码来源:sys_fs.c
示例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;
}
开发者ID:enigma-dev,项目名称:enigma-dev,代码行数:13,代码来源:WINDOWSmain.cpp
示例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);
}
开发者ID:LitleWaffle,项目名称:sampleDirectory,代码行数:20,代码来源:winfile.c
示例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;
};
开发者ID:PaperBirdMaster,项目名称:Code,代码行数:13,代码来源:Directory.cpp
示例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;
}
开发者ID:northplorer,项目名称:homework_2,代码行数:32,代码来源:stdafx.cpp
示例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;
}
开发者ID:Pouique,项目名称:naali,代码行数:13,代码来源:Application.cpp
示例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;
}
开发者ID:elepro,项目名称:Anthony,代码行数:51,代码来源:Anthony.cpp
示例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;
}
开发者ID:Akin-Net,项目名称:mozilla-central,代码行数:55,代码来源:nsPluginsDirWin.cpp
示例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
}
开发者ID:Cazomino05,项目名称:Test1,代码行数:14,代码来源:SharedUtil.File.hpp
示例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;
}
开发者ID:angelstudio,项目名称:sview,代码行数:23,代码来源:StProcess.cpp
示例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;
}
开发者ID:mitar,项目名称:node,代码行数:50,代码来源:fs-event.c
示例16: fix_path
Error DirAccessWindows::change_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
p_dir = fix_path(p_dir);
wchar_t real_current_dir_name[2048];
GetCurrentDirectoryW(2048, real_current_dir_name);
String prev_dir = real_current_dir_name;
SetCurrentDirectoryW(current_dir.c_str());
bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0);
String base = _get_root_path();
if (base != "") {
GetCurrentDirectoryW(2048, real_current_dir_name);
String new_dir;
new_dir = String(real_current_dir_name).replace("\\", "/");
if (!new_dir.begins_with(base)) {
worked = false;
}
}
if (worked) {
GetCurrentDirectoryW(2048, real_current_dir_name);
current_dir = real_current_dir_name; // TODO, utf8 parser
current_dir = current_dir.replace("\\", "/");
} //else {
SetCurrentDirectoryW(prev_dir.c_str());
//}
return worked ? OK : ERR_INVALID_PARAMETER;
}
开发者ID:allkhor,项目名称:godot,代码行数:37,代码来源:dir_access_windows.cpp
示例17: DIALOG_FileSaveAs
BOOL DIALOG_FileSaveAs(VOID)
{
OPENFILENAMEW saveas;
WCHAR szPath[MAX_PATH];
WCHAR szDir[MAX_PATH];
static const WCHAR szDefaultExt[] = { 't','x','t',0 };
static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
ZeroMemory(&saveas, sizeof(saveas));
GetCurrentDirectoryW(ARRAY_SIZE(szDir), szDir);
lstrcpyW(szPath, txt_files);
saveas.lStructSize = sizeof(OPENFILENAMEW);
saveas.hwndOwner = Globals.hMainWnd;
saveas.hInstance = Globals.hInstance;
saveas.lpstrFilter = Globals.szFilter;
saveas.lpstrFile = szPath;
saveas.nMaxFile = ARRAY_SIZE(szPath);
saveas.lpstrInitialDir = szDir;
saveas.Flags = OFN_ENABLETEMPLATE | OFN_ENABLEHOOK | OFN_EXPLORER |
OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
OFN_HIDEREADONLY | OFN_ENABLESIZING;
saveas.lpfnHook = OfnHookProc;
saveas.lpTemplateName = MAKEINTRESOURCEW(IDD_OFN_TEMPLATE);
saveas.lpstrDefExt = szDefaultExt;
/* Preset encoding to what file was opened/saved last with. */
Globals.encOfnCombo = Globals.encFile;
Globals.bOfnIsOpenDialog = FALSE;
retry:
if (!GetSaveFileNameW(&saveas))
return FALSE;
switch (DoSaveFile(szPath, Globals.encOfnCombo))
{
case SAVED_OK:
SetFileNameAndEncoding(szPath, Globals.encOfnCombo);
UpdateWindowCaption();
return TRUE;
case SHOW_SAVEAS_DIALOG:
goto retry;
default:
return FALSE;
}
}
开发者ID:bilboed,项目名称:wine,代码行数:49,代码来源:dialog.c
示例18: tb_directory_current
tb_size_t tb_directory_current(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 current[TB_PATH_MAXN] = {0};
GetCurrentDirectoryW(TB_PATH_MAXN, current);
// wtoa
tb_size_t size = tb_wtoa(path, current, maxn);
// ok?
return size != -1? size : 0;
}
开发者ID:ljx0305,项目名称:tbox,代码行数:15,代码来源:directory.c
示例19: TestGetCurrentDirectoryW
static
VOID
TestGetCurrentDirectoryW(VOID)
{
WCHAR Buffer[MAX_PATH];
DWORD Length;
BOOL Ret;
BOOLEAN Okay;
Ret = SetCurrentDirectoryW(L"C:\\");
ok(Ret == TRUE, "SetCurrentDirectory failed with %lu\n", GetLastError());
Length = GetCurrentDirectoryW(0, NULL);
ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
Length = GetCurrentDirectoryW(sizeof(Buffer) / sizeof(WCHAR), Buffer);
ok(Length == sizeof("C:\\") - 1, "Length = %lu\n", Length);
Okay = CheckStringBufferW(Buffer, sizeof(Buffer), L"C:\\", 0x55);
ok(Okay, "CheckStringBufferW failed\n");
RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
Length = GetCurrentDirectoryW(0, Buffer);
ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
ok(Okay, "CheckBuffer failed\n");
RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
Length = GetCurrentDirectoryW(1, Buffer);
ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
ok(Okay, "CheckBuffer failed\n");
RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
Length = GetCurrentDirectoryW(2, Buffer);
ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
ok(Okay, "CheckBuffer failed\n");
RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
Length = GetCurrentDirectoryW(3, Buffer);
ok(Length == sizeof("C:\\"), "Length = %lu\n", Length);
Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55);
ok(Okay, "CheckBuffer failed\n");
RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
Length = GetCurrentDirectoryW(4, Buffer);
ok(Length == sizeof("C:\\") - 1, "Length = %lu\n", Length);
Okay = CheckStringBufferW(Buffer, sizeof(Buffer), L"C:\\", 0x55);
ok(Okay, "CheckStringBufferW failed\n");
}
开发者ID:hoangduit,项目名称:reactos,代码行数:51,代码来源:GetCurrentDirectory.c
示例20: ZeroMemory
int FileUtils::RunAndWait(std::string &path, std::vector<std::string> &args)
{
std::string cmdLine = "\"" + path + "\"";
for (size_t i = 0; i < args.size(); i++)
{
cmdLine += " \"" + args.at(i) + "\"";
}
#ifdef DEBUG
std::cout << "running: " << cmdLine << std::endl;
#endif
STARTUPINFO startupInfo;
ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
PROCESS_INFORMATION processInfo;
ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION));
startupInfo.cb = sizeof(STARTUPINFO);
// Get the current working directory
wchar_t cwd[MAX_PATH];
DWORD size = GetCurrentDirectoryW(MAX_PATH, (wchar_t*) cwd);
std::wstring wideCmdLine = UTILS_NS::UTF8ToWide(cmdLine);
DWORD rc = -1;
if (CreateProcessW(
NULL, // No module name (use command line)
(wchar_t*) wideCmdLine.c_str(), // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
(wchar_t*) cwd, // Use parent's starting directory
&startupInfo, // Pointer to STARTUPINFO structure
&processInfo)) // Pointer to PROCESS_INFORMATION structure
{
// Wait until child process exits.
WaitForSingleObject(processInfo.hProcess, INFINITE);
// set the exit code
GetExitCodeProcess(processInfo.hProcess, &rc);
// Close process and thread handles.
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
return rc;
}
开发者ID:maccman,项目名称:kroll,代码行数:48,代码来源:file_utils_win32.cpp
注:本文中的GetCurrentDirectoryW函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论