• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GetCurrentDirectoryA函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ResolveIgniteHome

        std::string ResolveIgniteHome(const std::string& path)
        {
            // 1. Check passed argument.
            if (IsValidDirectory(path))
                return path;

            // 2. Check environment variable.
            std::string home = GetEnv(IGNITE_HOME);

            if (IsValidDirectory(home))
                return home;

            // 3. Check current work dir.
            DWORD curDirLen = GetCurrentDirectoryA(0, NULL);

            if (!curDirLen)
                return std::string();

            FixedSizeArray<char> curDir(curDirLen);

            curDirLen = GetCurrentDirectoryA(curDir.GetSize(), curDir.GetData());

            if (!curDirLen)
                return std::string();

            std::string curDirStr(curDir.GetData());

            return ResolveIgniteHome0(curDirStr);
        }
开发者ID:gridgain,项目名称:gridgain,代码行数:29,代码来源:utils.cpp


示例2: error

/// Switches you into a working directory
void Window::cd( char *path )
{
  if( !path )
  {
    error( "You can't change directory to NULL, nothing done" ) ;
    return ;
  }

  // Save the current directory to the stack
  char *cwd = (char*)malloc( MAX_PATH ) ;
  GetCurrentDirectoryA( MAX_PATH, cwd ) ;
  directories.push( cwd ) ;
  
  if( !SetCurrentDirectoryA( path ) )
  {
    error( "Couldn't switch directory to %s", path ) ;
  }
  else
  {
    // This verifies the cd command worked
    char nowDir[MAX_PATH];
    GetCurrentDirectoryA( MAX_PATH, nowDir ) ;
    info( "Current working directory is '%s'", nowDir ) ;
  }
}
开发者ID:sdp0et,项目名称:gtp,代码行数:26,代码来源:WindowClass.cpp


示例3: getcwd

cv::String getcwd()
{
    CV_INSTRUMENT_REGION();
    cv::AutoBuffer<char, 4096> buf;
#if defined WIN32 || defined _WIN32 || defined WINCE
#ifdef WINRT
    return cv::String();
#else
    DWORD sz = GetCurrentDirectoryA(0, NULL);
    buf.allocate((size_t)sz);
    sz = GetCurrentDirectoryA((DWORD)buf.size(), buf.data());
    return cv::String(buf.data(), (size_t)sz);
#endif
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__
    for(;;)
    {
        char* p = ::getcwd(buf.data(), buf.size());
        if (p == NULL)
        {
            if (errno == ERANGE)
            {
                buf.allocate(buf.size() * 2);
                continue;
            }
            return cv::String();
        }
        break;
    }
    return cv::String(buf.data(), (size_t)strlen(buf.data()));
#else
    return cv::String();
#endif
}
开发者ID:JoeHowse,项目名称:opencv,代码行数:33,代码来源:filesystem.cpp


示例4: GetModuleBase

static ULONG_ADDR CALLBACK GetModuleBase(HANDLE hProcess, ULONG_ADDR dwAddress)
{
    MEMORY_BASIC_INFORMATION memoryInfo;
    ULONG_ADDR dwAddrBase = SymGetModuleBase(hProcess, dwAddress);
    if (dwAddrBase) {
        return dwAddrBase;
    }
    if (VirtualQueryEx(hProcess, (void*)(GC_ULONG_PTR)dwAddress, &memoryInfo,
                       sizeof(memoryInfo))) {
        char filePath[_MAX_PATH];
        char curDir[_MAX_PATH];
        char exePath[_MAX_PATH];
        DWORD size = GetModuleFileNameA((HINSTANCE)memoryInfo.AllocationBase,
                                        filePath, sizeof(filePath));

        /* Save and restore current directory around SymLoadModule, see KB  */
        /* article Q189780.                                                 */
        GetCurrentDirectoryA(sizeof(curDir), curDir);
        GetModuleFileNameA(NULL, exePath, sizeof(exePath));
#if defined(_MSC_VER) && _MSC_VER == 1200
        /* use strcat for VC6 */
        strcat(exePath, "\\..");
#else
        strcat_s(exePath, sizeof(exePath), "\\..");
#endif /* _MSC_VER >= 1200 */
        SetCurrentDirectoryA(exePath);
#ifdef _DEBUG
        GetCurrentDirectoryA(sizeof(exePath), exePath);
#endif
        SymLoadModule(hProcess, NULL, size ? filePath : NULL, NULL,
                      (ULONG_ADDR)(GC_ULONG_PTR)memoryInfo.AllocationBase, 0);
        SetCurrentDirectoryA(curDir);
    }
    return (ULONG_ADDR)(GC_ULONG_PTR)memoryInfo.AllocationBase;
}
开发者ID:qykth-git,项目名称:bdwgc,代码行数:35,代码来源:msvc_dbg.c


示例5: fs_GetFullPath

/* take a path with a drive letter, possibly relative, and return a full path
 * without the drive letter.  This is the full path relative to the working
 * dir for that drive letter.  The input and output paths can be the same.
 */
long fs_GetFullPath(char *pathp, char *outPathp, long outSize)
{
	char tpath[1000];
	char origPath[1000];
    char *firstp;
    long code;
    int pathHasDrive;
    int doSwitch;
    char newPath[3];

	if (pathp[0] != 0 && pathp[1] == ':') {
		/* there's a drive letter there */
        firstp = pathp+2;
        pathHasDrive = 1;
    } else {
        firstp = pathp;
		pathHasDrive = 0;
	}

    if (*firstp == '\\' || *firstp == '/') {
		/* already an absolute pathname, just copy it back */
        strcpy(outPathp, firstp);
        return 0;
    }

    GetCurrentDirectoryA(sizeof(origPath), origPath);

	doSwitch = 0;
    if (pathHasDrive && (*pathp & ~0x20) != (origPath[0] & ~0x20)) {
		/* a drive has been specified and it isn't our current drive.
         * to get path, switch to it first.  Must case-fold drive letters
         * for user convenience.
         */
		doSwitch = 1;
        newPath[0] = *pathp;
        newPath[1] = ':';
        newPath[2] = 0;
        if (!SetCurrentDirectoryA(newPath)) {
			code = GetLastError();
            return code;
        }
    }

    /* now get the absolute path to the current wdir in this drive */
    GetCurrentDirectoryA(sizeof(tpath), tpath);
    strcpy(outPathp, tpath+2);	/* skip drive letter */
	/* if there is a non-null name after the drive, append it */
	if (*firstp != 0) {
        strcat(outPathp, "\\");
        strcat(outPathp, firstp);
	}

	/* finally, if necessary, switch back to our home drive letter */
    if (doSwitch) {
        SetCurrentDirectoryA(origPath);
    }

    return 0;
}
开发者ID:chanke,项目名称:openafs-osd,代码行数:63,代码来源:fs_utils.c


示例6: current_path

path current_path() {
	std::vector<char> buffer(GetCurrentDirectoryA(0, NULL));
	DWORD length = GetCurrentDirectoryA(buffer.size(), &buffer.front());
	if(length == 0 || length + 1 >= buffer.size()) {
		buffer[0] = '\0';
	}
	return path(&buffer.front());
}
开发者ID:hulu1528,项目名称:ArxLibertatis,代码行数:8,代码来源:FilesystemWindows.cpp


示例7: snewn

/*
* Get local current directory. Returns a string which must be
* freed.
*/
char *psftp_getcwd(void)
{
   char *ret = snewn(256, char);
   int len = GetCurrentDirectoryA(256, ret);
   if (len > 256)
      ret = sresize(ret, len, char);
   GetCurrentDirectoryA(len, ret);
   return ret;
}
开发者ID:identity0815,项目名称:os45,代码行数:13,代码来源:WINSFTP.C


示例8: CurrentDirectory

std::string CurrentDirectory(void) {
    DWORD bufferLength = 0;
    bufferLength = GetCurrentDirectoryA(0, NULL);
    CHECK_WIN_ERROR;
    assert(bufferLength);
    std::string buffer(bufferLength - 1, '0');
    bufferLength = GetCurrentDirectoryA(bufferLength, &buffer[0]);
    CHECK_WIN_ERROR;
    assert(bufferLength);
    return buffer;
}
开发者ID:plainoldcj,项目名称:nubuck,代码行数:11,代码来源:common.cpp


示例9: iupdrvGetCurrentDirectory

char* iupdrvGetCurrentDirectory(void)
{
  char* cur_dir = NULL;

  int len = GetCurrentDirectoryA(0, NULL);
  if (len == 0) return NULL;

  cur_dir = iupStrGetMemory(len + 2);
  GetCurrentDirectoryA(len + 1, cur_dir);
  cur_dir[len] = '\\';
  cur_dir[len + 1] = 0;

  return cur_dir;
}
开发者ID:mwoz,项目名称:Hildim.Source,代码行数:14,代码来源:iupwindows_info.c


示例10: dbgGetCurrentDirectory

/** Implement the Lua function GetCurrentDirectory().
 * 
 * Discover the current directory name and return it to the caller.
 * 
 * \todo There is a low-probability memory leak here. The buffer used 
 * to hold the current directory string came from malloc() and is held 
 * across a call to lua_pushlstring() which can potentially throw an
 * error, which will leak the allocated buffer. The other bits of Win32
 * API wrappers could have similar issues, and should be inspected.
 * 
 * \param L Lua state context for the function.
 * \returns The number of values on the Lua stack to be returned
 * to the Lua caller.
 */
static int dbgGetCurrentDirectory(lua_State *L)
{
	char *buf = 0;
	DWORD len = 0;
	len = GetCurrentDirectoryA(0,NULL);
	if (!len)
		return luaL_error(L, "GetCurrentDirectory failed (%d)", GetLastError());
	buf = malloc(len+1);
	if (!buf)
		return luaL_error(L,"GetCurrentDirectory can't allocate %ld chars", len);
	GetCurrentDirectoryA(len+1, buf);
	lua_pushlstring(L, buf, len);
	free(buf);
	return 1;
}
开发者ID:luaforge,项目名称:luaservice,代码行数:29,代码来源:LuaMain.c


示例11: CWE785_Path_Manipulation_Function_Without_Max_Sized_Buffer__w32_04_bad

void CWE785_Path_Manipulation_Function_Without_Max_Sized_Buffer__w32_04_bad()
{
    if(STATIC_CONST_TRUE)
    {
        {
            char path[BAD_PATH_SIZE];
            DWORD length;
            length = GetCurrentDirectoryA(BAD_PATH_SIZE, path);
            if (length == 0 || length >= BAD_PATH_SIZE) /* failure conditions for this API call */
            {
                exit(1);
            }
            /* FLAW: PathAppend assumes the 'path' parameter is MAX_PATH */
            /* INCIDENTAL: CWE 121 stack based buffer overflow, which is intrinsic to
             * this example identified on the CWE webpage */
            if (!PathAppendA(path, "AAAAAAAAAAAA"))
            {
                exit(1);
            }
            printSizeTLine(strlen(path));
            printIntLine(BAD_PATH_SIZE);
            printLine(path);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:25,代码来源:CWE785_Path_Manipulation_Function_Without_Max_Sized_Buffer__w32_04.c


示例12: is_a_valid_directory

int
is_a_valid_directory(char* pcszDirectory){
#ifndef WIN32
	struct stat	statbuf;

	if ( pcszDirectory[0] == '\0' )
		return 0;
	
	lstat(pcszDirectory, &statbuf);

	if (S_ISDIR(statbuf.st_mode) == 1){
		return 1;
	}

	write_log(LT_BOTH, "Error: %s is not a valid path!\n", pcszDirectory);
	return 0;
#else
	char		szPath[MAX_PATH];
	int			nRet = 0;

    GetCurrentDirectoryA(MAX_PATH, szPath);
    if ( SetCurrentDirectoryA(pcszDirectory) )
		nRet = 1;
	
    SetCurrentDirectoryA(szPath);
	if ( nRet == 0 )
		write_log(LT_BOTH, "Error: %s is not a valid path!\n",
		pcszDirectory);

	return nRet;
#endif //WIN32
}
开发者ID:pkxpp,项目名称:Study,代码行数:32,代码来源:str_operate.cpp


示例13: test_setdir

/* Routine to test that SetCurrentDirectory behaves as expected. */
static void test_setdir(CHAR *olddir,CHAR *newdir,
                        CHAR *cmprstr, INT pass, const CHAR *errstr)
{
  CHAR tmppath[MAX_PATH], *dirptr;
  DWORD val,len,chklen;

  val=SetCurrentDirectoryA(newdir);
  len=GetCurrentDirectoryA(MAX_PATH,tmppath);
/* if 'pass' then the SetDirectoryA was supposed to pass */
  if(pass) {
    dirptr=(cmprstr==NULL) ? newdir : cmprstr;
    chklen=lstrlenA(dirptr);
    ok(val,"%s: SetCurrentDirectoryA failed\n",errstr);
    ok(len==chklen,
       "%s: SetCurrentDirectory did not change the directory, though it passed\n",
       errstr);
    ok(lstrcmpiA(dirptr,tmppath)==0,
       "%s: SetCurrentDirectory did not change the directory, though it passed\n",
       errstr);
    ok(SetCurrentDirectoryA(olddir),
       "%s: Couldn't set directory to it's original value\n",errstr);
  } else {
/* else thest that it fails correctly */
    chklen=lstrlenA(olddir);
    ok(val==0,
       "%s: SetCurrentDirectoryA passed when it should have failed\n",errstr);
    ok(len==chklen,
       "%s: SetCurrentDirectory changed the directory, though it failed\n",
       errstr);
    ok(lstrcmpiA(olddir,tmppath)==0,
       "%s: SetCurrentDirectory changed the directory, though it failed\n",
       errstr);
  }
}
开发者ID:howard5888,项目名称:wineT,代码行数:35,代码来源:path.c


示例14: getCurrentDrive

// Get current drive prefix "a:", if any
// This is the same method as used in VC++ CRT.
FXString FXSystem::getCurrentDrive(){
#ifdef WIN32
  FXchar buffer[MAXPATHLEN];
  if(GetCurrentDirectoryA(MAXPATHLEN,buffer) && Ascii::isLetter((FXuchar)buffer[0]) && buffer[1]==':') return FXString(buffer,2);
#endif
  return FXString::null;
  }
开发者ID:Tetimaru,项目名称:LLSIF-Helper,代码行数:9,代码来源:FXSystem.cpp


示例15: getIniValue

bool getIniValue(string filename,string section,string key,string defultValue,string& value){
	

	char lpBuffer[PATH_BUFFER_LENGTH];
	ZeroMemory(lpBuffer,PATH_BUFFER_LENGTH);

	DWORD nBufferLength = GetCurrentDirectoryA(
									PATH_BUFFER_LENGTH,
									lpBuffer
								);
	string path = ""; 
	if (!nBufferLength) return false;

	path=lpBuffer;
	path+="\\";
	path+=filename;
	

	ZeroMemory(lpBuffer,PATH_BUFFER_LENGTH);

	nBufferLength=  GetPrivateProfileStringA(						  
						  section.c_str(),
						  key.c_str(),
						  defultValue.c_str(),
						  lpBuffer,
						  PATH_BUFFER_LENGTH,
						  path.c_str()
						);

	if (!nBufferLength) return false;

	value = lpBuffer;
	return true;

}
开发者ID:witwall,项目名称:planetariumfd,代码行数:35,代码来源:ConfigIni.cpp


示例16: win32_add_one_solib

static void
win32_add_one_solib (const char *name, CORE_ADDR load_addr)
{
  char buf[MAX_PATH + 1];
  char buf2[MAX_PATH + 1];

#ifdef _WIN32_WCE
  WIN32_FIND_DATA w32_fd;
  WCHAR wname[MAX_PATH + 1];
  mbstowcs (wname, name, MAX_PATH);
  HANDLE h = FindFirstFile (wname, &w32_fd);
#else
  WIN32_FIND_DATAA w32_fd;
  HANDLE h = FindFirstFileA (name, &w32_fd);
#endif

  /* The symbols in a dll are offset by 0x1000, which is the
     offset from 0 of the first byte in an image - because
     of the file header and the section alignment. */
  load_addr += 0x1000;

  if (h == INVALID_HANDLE_VALUE)
    strcpy (buf, name);
  else
    {
      FindClose (h);
      strcpy (buf, name);
#ifndef _WIN32_WCE
      {
	char cwd[MAX_PATH + 1];
	char *p;
	if (GetCurrentDirectoryA (MAX_PATH + 1, cwd))
	  {
	    p = strrchr (buf, '\\');
	    if (p)
	      p[1] = '\0';
	    SetCurrentDirectoryA (buf);
	    GetFullPathNameA (w32_fd.cFileName, MAX_PATH, buf, &p);
	    SetCurrentDirectoryA (cwd);
	  }
      }
#endif
    }

#ifndef _WIN32_WCE
  if (strcasecmp (buf, "ntdll.dll") == 0)
    {
      GetSystemDirectoryA (buf, sizeof (buf));
      strcat (buf, "\\ntdll.dll");
    }
#endif

#ifdef __CYGWIN__
  cygwin_conv_path (CCP_WIN_A_TO_POSIX, buf, buf2, sizeof (buf2));
#else
  strcpy (buf2, buf);
#endif

  loaded_dll (buf2, load_addr);
}
开发者ID:phausler,项目名称:binutils,代码行数:60,代码来源:win32-low.c


示例17: ShowOpenFileDialog

bool ShowOpenFileDialog(char* FileName, int FileNameLength, char* filter)
// Open a dialog for selecting a file and returns true if succeeded with the name of the file in the preallocated buffer <FileName>
{
    OPENFILENAMEA ofn ;

    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = GetActiveWindow(); 
    ofn.lpstrDefExt = 0;
    FileName[0] = '\0';
	ofn.lpstrFile = FileName;
    ofn.nMaxFile = FileNameLength;
    ofn.lpstrFilter = filter; 
    ofn.nFilterIndex = 1;
    char strAux[MAX_PATH];
	GetCurrentDirectoryA(MAX_PATH, strAux);
	ofn.lpstrInitialDir = strAux;
    ofn.lpstrTitle = LPSTR("Open File");
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ENABLESIZING;

    GetOpenFileNameA(&ofn);

    if (strlen(ofn.lpstrFile) == 0) return false;
    return true;
} // ShowOpenFileDialog
开发者ID:alhunor,项目名称:projects,代码行数:26,代码来源:filesystems.cpp


示例18: injectThread

void injectThread(const wchar_t *processName) {
	while (true) {
		// Wait for process to load.
		wprintf(L"Waiting for %s to load...\n", processName);
		DWORD dwProcessId = NULL;
		do {
			Sleep(10);
			dwProcessId = getProcessId(processName);
		} while (dwProcessId == NULL);

		// Attempt to inject DLL.
		char dllFile[MAX_PATH];
		GetCurrentDirectoryA(sizeof(dllFile), dllFile);
		sprintf(dllFile, "%s\\..\\Hook\\bin\\Hook.dll", dllFile);
		printf("Found PID %d, attempting to inject DLL... ", dwProcessId);
		if (injectDll(dwProcessId, dllFile)) {
			printf("done!\n");
		}

		// Now wait for it to unload.
		do {
			Sleep(10);
			dwProcessId = getProcessId(processName);
		} while (dwProcessId != NULL);
	}
}
开发者ID:danslo,项目名称:Celect,代码行数:26,代码来源:injector.cpp


示例19: PlatformChangeDirectoryToResources

void PlatformChangeDirectoryToResources()
{
	char buffer[MAX_PATH];
	GetCurrentDirectoryA(MAX_PATH, buffer);
	lstrcatA(buffer, TEXT("\\.."));
	SetCurrentDirectoryA(buffer);
}
开发者ID:Shtille,项目名称:ShtilleEngine,代码行数:7,代码来源:window_controller.cpp


示例20: test_define_dos_deviceA

static void test_define_dos_deviceA(void)
{
    char drivestr[3];
    char buf[MAX_PATH];
    DWORD ret;

    /* Find an unused drive letter */
    drivestr[1] = ':';
    drivestr[2] = 0;
    for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
        ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
        if (!ret) break;
    }
    if (drivestr[0] > 'z') {
        skip("can't test creating a dos drive, none available\n");
        return;
    }

    /* Map it to point to the current directory */
    ret = GetCurrentDirectoryA(sizeof(buf), buf);
    ok(ret, "GetCurrentDir\n");

    ret = DefineDosDeviceA(0, drivestr, buf);
    todo_wine
    ok(ret, "Could not make drive %s point to %s!\n", drivestr, buf);

    if (!ret) {
        skip("can't test removing fake drive\n");
    } else {
	ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
	ok(ret, "Could not remove fake drive %s!\n", drivestr);
    }
}
开发者ID:DusteDdk,项目名称:wine-multimedia,代码行数:33,代码来源:volume.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GetCurrentDirectoryW函数代码示例发布时间:2022-05-30
下一篇:
C++ GetCurrentDirectory函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap