当前位置: 首页>>代码示例>>C++>>正文


C++ SetCurrentDirectoryW函数代码示例

本文整理汇总了C++中SetCurrentDirectoryW函数的典型用法代码示例。如果您正苦于以下问题:C++ SetCurrentDirectoryW函数的具体用法?C++ SetCurrentDirectoryW怎么用?C++ SetCurrentDirectoryW使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SetCurrentDirectoryW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main2

ForceInline Int main2(Int argc, WChar **argv)
{
    if (argc == 1)
    {
        printf("ToB (Text of Binary) Compiler 0.3 [by dwing] 2009-02-28\n"
               "Usage: tobc <src_file> [dst_file]\n");
        return 1;
    }

    BOOL   Result;
    WCHAR  szCurPath[MAX_PATH], szScriptPath[MAX_PATH];
    LPWSTR fsrcname, fdstname;

    fsrcname = argv[1];
    fdstname = argc > 2 ? argv[2] : NULL;

    lstrcpyW(szScriptPath, fsrcname);
    rmnamew(szScriptPath);
    GetCurrentDirectoryW(countof(szCurPath), szCurPath);
    SetCurrentDirectoryW(szScriptPath);

    setlocale(LC_CTYPE, ".936");
    printf("Compiling %S ... ", (LPCTSTR)fsrcname);

    CTobCompiler compiler;

    Result = compiler.CompileFile(fsrcname, fdstname, &CTobCompiler::ErrorHandlerInternal);
    SetCurrentDirectoryW(szCurPath);
    if (!Result)
        return -1;

    fdstname = fdstname == NULL ? L"" : fdstname;
    printf("%S OK!\n", (LPCTSTR)fdstname);
    return 0;
}
开发者ID:QuocHuy7a10,项目名称:Arianrhod,代码行数:35,代码来源:tobc.cpp

示例2: FixAutoplay

void FixAutoplay( LPCWSTR wszApplicationName, LPCWSTR wszCommandLine, LPCWSTR wszCurrentDirectory )
{
	LPCWSTR uppApplicationName = _wcsupr( _wcsdup( wszApplicationName ) );

	// only UT2004
	if( wcsstr(uppApplicationName,L"UT2004.EXE") == NULL )
		return;

	// read mod name from commandline, must be specified
	LPCWSTR uppCommandLine = _wcsupr( _wcsdup( wszCommandLine ) );
	LPWSTR pb = wcsstr(uppCommandLine,L"-MOD=");
	if( pb == NULL )
		return;
	
	// mod name must be valid
	LPWSTR ps = pb + wcslen(L"-MOD=");
	LPWSTR token = wcstok( ps, L" " );
	if( token == NULL )
		return;

	// mod directory must be valid
	if( !SetCurrentDirectoryW(wszCurrentDirectory)
	||	!SetCurrentDirectoryW(L"..")
	||	!SetCurrentDirectoryW(token) )
		return;

	// copy Autoplay.ut2
	if( !CopyFileW( L"..\\Maps\\Autoplay.ut2", L"Maps\\Autoplay.ut2", FALSE ) )
		return;

	//MessageBox( NULL, TEXT("Copy OK"), TEXT("SwAutoplayFix"), MB_OK );
}
开发者ID:roman-dzieciol,项目名称:SwAutoplayFix,代码行数:32,代码来源:SwAutoplayFix.cpp

示例3: 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

示例4: SetCurrentDirectoryUW

static WINUSERAPI BOOL WINAPI SetCurrentDirectoryUW(LPCSTR lpPathName)
{
    if (!lpPathName)
    {
        // String not specified. Don't bother converting anything.
        return SetCurrentDirectoryW((LPCWSTR)lpPathName);
    }

    // Convert lpPathName from UTF-8 to UTF-16.
    wchar_t *lpwPathName = w32u_UTF8toUTF16(lpPathName);

    BOOL bRet = SetCurrentDirectoryW(lpwPathName);
    free(lpwPathName);
    return bRet;
}
开发者ID:PhilrocWP,项目名称:gens,代码行数:15,代码来源:w32u_windowsW.c

示例5: SheChangeDirW

INT
SheChangeDirW(
   register WCHAR *newdir
   )
{
   WCHAR       denvname[ 4 ];
   WCHAR       newpath[ MAX_PATH ];
   WCHAR       denvvalue[ MAX_PATH ];
   WCHAR       c, *s;
   DWORD       attr;

   GetCurrentDirectoryW( MAX_PATH, denvvalue );
   c = (WCHAR)(DWORD)CharUpperW((LPTSTR)(DWORD)denvvalue[0]);

   denvname[0] = WCHAR_EQUAL;
   if (IsCharAlphaW(*newdir) && newdir[1] == WCHAR_COLON) {
      denvname[1] = (WCHAR)(DWORD)CharUpperW((LPTSTR)(DWORD)*newdir);
      newdir += 2;
   } else {
      denvname[ 1 ] = c;
   }
   denvname[ 2 ] = WCHAR_COLON;
   denvname[ 3 ] = WCHAR_NULL;

   if ((*newdir == WCHAR_BSLASH) || (*newdir == WCHAR_SLASH)) {
      newpath[ 0 ] = denvname[ 1 ];
      newpath[ 1 ] = denvname[ 2 ];
      wcscpy( &newpath[ 2 ], newdir );
   } else {
      if (NULL != (s = SheGetEnvVarW( denvname ))) {
         wcscpy( newpath, s );
      } else {
         newpath[ 0 ] = denvname[ 1 ];
         newpath[ 1 ] = denvname[ 2 ];
         newpath[ 2 ] = WCHAR_NULL;
      }
      s = newpath + wcslen( newpath );
      *s++ = WCHAR_BSLASH;
      wcscpy( s, newdir );
   }

   if (!GetFullPathNameW(newpath, MAX_PATH, denvvalue, &s )) {
      return( ERROR_ACCESS_DENIED );
   }

   attr = GetFileAttributesW( denvvalue );
   if (attr == -1 || !(attr & FILE_ATTRIBUTE_DIRECTORY)) {
      return( ERROR_ACCESS_DENIED );
   }

   if (SheSetEnvVarW(denvname,denvvalue)) {
      return( ERROR_NOT_ENOUGH_MEMORY );
   }

   SetCurrentDirectoryW( denvvalue );

   // this seems wrong... SheGetDir(GD_DEFAULT, CurDrvDirW) ;
   wcscpy(CurDrvDirW, denvvalue);   // this seems right to me.
   return(SUCCESS) ;
}
开发者ID:mingpen,项目名称:OpenNT,代码行数:60,代码来源:psdocurd.c

示例6: __lib_SetCurrentDirectoryW

BOOL __lib_SetCurrentDirectoryW( LPCWSTR lpPathName )
/***************************************************/
{
    if( WIN32_IS_NT ) {                                 /* NT */
        return( SetCurrentDirectoryW( lpPathName ) );
    } else {                                            /* Win95 or Win32s */
        char *          mbPathName;
        BOOL            osrc;
        size_t          cvt;
        size_t          len;

        /*** Allocate some memory ***/
        len = wcslen( lpPathName ) * MB_CUR_MAX + 1;
        mbPathName = lib_malloc( len );
        if( mbPathName == NULL ) {
            return( FALSE );
        }

        /*** Prepare to call the OS ***/
        cvt = wcstombs( mbPathName, lpPathName, len );
        if( cvt == (size_t)-1 ) {
            lib_free( mbPathName );
            return( FALSE );
        }

        /*** Call the OS ***/
        osrc = SetCurrentDirectoryA( mbPathName );
        lib_free( mbPathName );
        return( osrc );
    }
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:31,代码来源:setcdir.c

示例7: SetCurrentDirectoryW

CPUTResult CPUTFileSystem::SetWorkingDirectory(const std::wstring &path)
{
    BOOL result = SetCurrentDirectoryW(path.c_str());
    ASSERT( 0 != result, L"Error setting current directory." );
    UNREFERENCED_PARAMETER(result);
    return CPUT_SUCCESS;
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:7,代码来源:CPUTOSServicesWin.cpp

示例8: wWinMain

int WINAPI wWinMain(HINSTANCE ins, HINSTANCE prev, LPWSTR cmd, int show)
{
   _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
   OleInitialize(NULL);

   WCHAR path [MAX_PATH];
   if(GetModuleFileNameW(NULL, path, _countof(path))) {
      PathRenameExtensionW(path, L".dll");
      //DONT_RESOLVE_DLL_REFERENCESを指定すると依存関係の解決や
      //DllMainの呼び出しが行われない
      hinstDLL = LoadLibraryExW(path, NULL, DONT_RESOLVE_DLL_REFERENCES);
   }
   if(!hinstDLL) {
      errmsg(IDS_DLL, HresultFromLastError());
   } else {
      PathRemoveFileSpecW(path);
      SetCurrentDirectoryW(path);

      HRESULT hr = HookAndExecute(show);
      if(hr != S_OK) {
         errmsg(IDC_EXEC, hr);
      }
   }

   OleUninitialize();
   return 0;
}
开发者ID:CoolOppo,项目名称:ezgdi,代码行数:27,代码来源:run.cpp

示例9: __tar_chdir

int
__tar_chdir(const char *path)
{
	wchar_t *ws;
	int r;

	r = SetCurrentDirectoryA(path);
	if (r == 0) {
		if (GetLastError() != ERROR_FILE_NOT_FOUND) {
			__tar_dosmaperr(GetLastError());
			return (-1);
		}
	} else
		return (0);
	ws = permissive_name(path);
	if (ws == NULL) {
		errno = EINVAL;
		return (-1);
	}
	r = SetCurrentDirectoryW(ws);
	free(ws);
	if (r == 0) {
		__tar_dosmaperr(GetLastError());
		return (-1);
	}
	return (0);
}
开发者ID:Bebere,项目名称:libarchive,代码行数:27,代码来源:bsdtar_windows.c

示例10: DllEntryPoint

//-------------------------------------------------------------------------------------------------
extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE hInstDll, DWORD fdwReason, LPVOID)
{
    if (fdwReason == DLL_PROCESS_ATTACH)
    {
        const DWORD dwLen = GetModuleFileNameW(nullptr, g_wBuf, MAX_PATH+1);
        if (dwLen >= 6 && dwLen < MAX_PATH)
        {
            wchar_t *pDelim = g_wBuf+dwLen;
            do
            {
                if (*--pDelim == L'\\')
                    break;
            } while (pDelim > g_wBuf);
            if (pDelim >= g_wBuf+4 && pDelim <= g_wBuf+MAX_PATH-g_dwPathMargin &&
                    (pDelim[1] = L'\0', SetCurrentDirectoryW(g_wBuf)) &&
                    DisableThreadLibraryCalls(hInstDll))
                if (const HANDLE hTimer = CreateWaitableTimerW(nullptr, FALSE, nullptr))
                {
                    LARGE_INTEGER liDueTime;
                    liDueTime.QuadPart = 0;
                    const bool bOk = SetWaitableTimer(hTimer, &liDueTime, 0, TimerAPCProc, hInstDll, FALSE);
                    if (CloseHandle(hTimer) && bOk)
                    {
                        *pDelim = L'\0';
                        return TRUE;
                    }
                }
        }
    }
    return FALSE;
}
开发者ID:korha,项目名称:Portablize,代码行数:32,代码来源:main.cpp

示例11: WinMain

	int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
		// Задаем рабочий путь откуда запущено приложение
		wchar_t appPath[MAX_PATH] = L"";
		GetModuleFileNameW(0, appPath, MAX_PATH);
		wchar_t *appDir = wcsrchr(appPath, L'\\');
		if(appDir) {
			++appDir;
			if(appDir) {
				*appDir = 0;
				SetCurrentDirectoryW(appPath);
			}
		}

		jappsyInit();
		/*
		init_cString();
		init_cObject();
		int res = _WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
		uninit_cObject();
		uninit_cString();

	#ifdef DEBUG
		uint32_t count = 0;
		memLogSort();
		memLogStats(&count, 0, 0, 0);
	#endif

		mmCleanup();
		return res;
		*/

		jappsyQuit();
		return 0;
	}
开发者ID:Jappsy,项目名称:jappsy,代码行数:34,代码来源:main.cpp

示例12: GetCurrentDirectoryW

void SaveSampleFilterProp::OnBnClickedButtonbrowse()
{
	WCHAR curDic[MAX_PATH] = {0};
	GetCurrentDirectoryW(MAX_PATH, curDic);
	OPENFILENAME openfn;
	WCHAR cFname[256];
	WCHAR szFilterOpn[]=TEXT("Config files (*.txt)\0*.txt\0All files (*.*)\0*.*\0\0");
	DWORD nFilterIndex=1;
	cFname[0]=0x00;
	ZeroMemory(&openfn, sizeof(openfn));
	openfn.hwndOwner=GetActiveWindow()->GetSafeHwnd();
	openfn.lpstrFile=cFname;
	openfn.nMaxFile=sizeof(cFname);
	openfn.lStructSize=sizeof(openfn);
	openfn.lpstrFilter=szFilterOpn; 
	openfn.nFilterIndex=nFilterIndex;
	//openfn.lpstrInitialDir=szCurDir;
	openfn.Flags= OFN_PATHMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;
	BOOL hr = GetOpenFileName(&openfn );
	SetCurrentDirectoryW(curDic);
	if (!hr)
	{
		return ;
	}
	m_ed_path.SetWindowText(openfn.lpstrFile);
}
开发者ID:shooting12,项目名称:imtop,代码行数:26,代码来源:SaveSampleFilterProp.cpp

示例13: efile_set_cwd

posix_errno_t efile_set_cwd(const efile_path_t *path) {
    const WCHAR *path_start;

    ASSERT_PATH_FORMAT(path);

    /* We have to use _wchdir since that's the only function that updates the
     * per-drive working directory, but it naively assumes that all paths
     * starting with \\ are UNC paths, so we have to skip the long-path prefix.
     *
     * _wchdir doesn't handle long-prefixed UNC paths either so we hand those
     * to SetCurrentDirectoryW instead. The per-drive working directory is
     * irrelevant for such paths anyway. */

    if(!IS_LONG_UNC_PATH(PATH_LENGTH(path), path->data)) {
        path_start = (WCHAR*)path->data + LP_PREFIX_LENGTH;

        if(_wchdir(path_start)) {
            return windows_to_posix_errno(GetLastError());
        }
    } else {
        if(!SetCurrentDirectoryW((WCHAR*)path->data)) {
            return windows_to_posix_errno(GetLastError());
        }
    }

    return 0;
}
开发者ID:HansN,项目名称:otp,代码行数:27,代码来源:win_prim_file.c

示例14: RTDECL

RTDECL(int) RTPathSetCurrent(const char *pszPath)
{
    /*
     * Validate input.
     */
    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
    AssertReturn(*pszPath, VERR_INVALID_PARAMETER);

    /*
     * This interface is almost identical to the Windows API.
     */
    PRTUTF16 pwszPath;
    int rc = RTStrToUtf16(pszPath, &pwszPath);
    if (RT_SUCCESS(rc))
    {
        /** @todo improve the slash stripping a bit? */
        size_t cwc = RTUtf16Len(pwszPath);
        if (    cwc >= 2
            &&  (   pwszPath[cwc - 1] == L'/'
                 || pwszPath[cwc - 1] == L'\\')
            &&  pwszPath[cwc - 2] != ':')
            pwszPath[cwc - 1] = L'\0';

        if (!SetCurrentDirectoryW(pwszPath))
            rc = RTErrConvertFromWin32(GetLastError());

        RTUtf16Free(pwszPath);
    }
    return rc;
}
开发者ID:greg100795,项目名称:virtualbox,代码行数:30,代码来源:path-win.cpp

示例15: main

int __cdecl main(int argc, char *argv[])
{
    char szDirName[MAX_PATH]  = "testing";
    WCHAR* szwDirName = NULL;
    char szFileName[MAX_PATH] = "setcurrentdirectorya.c";
    WCHAR* szwFileName = NULL;

    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    /* set the current directory to an unexistant folder */
    szwDirName = convert(szDirName);
    if (0 != SetCurrentDirectoryW(szwDirName))
    {
        free(szwDirName);
        Fail("ERROR: SetCurrentDirectoryW should have failed "
             "when trying to set the current directory to "
             "an invalid folder\n");
    }
    free(szwDirName);

    /* set the current directory to an unexistant folder */
    szwFileName = convert(szFileName);
    if (0 != SetCurrentDirectoryW(szwFileName))
    {
        free(szwFileName);
        Fail("ERROR: SetCurrentDirectoryW should have failed "
             "when trying to set the current directory to "
             "a valid file name\n");
    }
    free(szwFileName);
    
    /* set the current directory to NULL */
    if (0 != SetCurrentDirectoryW(NULL))
    {
        Fail("ERROR: SetCurrentDirectoryW should have failed "
             "when trying to set the current directory to "
             "NULL\n");
    }

    PAL_Terminate();

    return PASS;
}
开发者ID:Afshintm,项目名称:coreclr,代码行数:46,代码来源:setcurrentdirectoryw.c


注:本文中的SetCurrentDirectoryW函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。