구글링을 하면서 찾아 보니
GetCurrentDirectory라는 Win32 API가 존재 하는데,
이녀석으로 할 경우 FILE dialog에서 경로를 변경시 다른 경로가 나올 우려가 있다고 한다.
그래서 GetModuleFileName 이라는 함수를 사용하라는데,
먼소리여 -ㅁ-!
[참조 : http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=806]
[출처 : http://www.codeguru.com/forum/showthread.php?threadid=462232]
Run-Time Library Reference
_pgmptr, _wpgmptr
The path of the executable file. Deprecated; use _get_pgmptr and _get_wpgmptr.
좀 더 간단한 녀석이 있어 보인다.
[원본 : http://msdn.microsoft.com/en-us/library/tza1y5f7(VS.80).aspx]
간단한 테스트 결과
1. VC++ 6.0 컴파일 환경 설정

2. 소스코드 작성
3. 결과
GetCurrentDirectory라는 Win32 API가 존재 하는데,
이녀석으로 할 경우 FILE dialog에서 경로를 변경시 다른 경로가 나올 우려가 있다고 한다.
그래서 GetModuleFileName 이라는 함수를 사용하라는데,
먼소리여 -ㅁ-!
[참조 : http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=806]
Code:
char path[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH); MessageBox(NULL, path, NULL, NULL);
[출처 : http://www.codeguru.com/forum/showthread.php?threadid=462232]
Run-Time Library Reference
_pgmptr, _wpgmptr
The path of the executable file. Deprecated; use _get_pgmptr and _get_wpgmptr.
Variable | Required header | Compatibility |
---|---|---|
_pgmptr, _wpgmptr |
<stdlib.h> |
Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Server 2003 |
[원본 : http://msdn.microsoft.com/en-us/library/tza1y5f7(VS.80).aspx]
1. VC++ 6.0 컴파일 환경 설정
2. 소스코드 작성
#include <windows.h> void main() { char path[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH); printf("path[%s]\n",path); GetCurrentDirectory(MAX_PATH,path); printf("path[%s]\n",path); } |
3. 결과
path[C:\Documents and Settings\morpheuz\바탕 화면\tt\Debug\t.exe] path[C:\] Press any key to continue |
'Programming > C Win32 MFC' 카테고리의 다른 글
The C Library Reference Guide (0) | 2009.02.24 |
---|---|
warning: array subscript has type ‘char’ (0) | 2009.01.02 |
Windows Registry 관련 함수 (0) | 2008.12.30 |
현재 실행파일이 있는 경로 알아 내기 - How to get full path of executed current file(not current directory) (2) | 2008.12.26 |
확장자별 우클릭 메뉴를 위한 레지스트리 등록(Windows Registry for file extension context-menu) (5) | 2008.12.18 |
File 길이 알아내기 (2) | 2008.10.29 |
댓글을 달아 주세요
GetCurrentDirectory 함수를 이용하여 디렉토리를 얻어오는 경우 해당 프로그램 내에서
2008.12.26 10:52 [ ADDR : EDIT/ DEL : REPLY ]File Dialog 등을 이용하여 Open/Save 등의 행동을 취했을때에 마지막에 Action이 이루어졌던 폴더를 되돌려줄 가능성이 있으므로, 해당 실행화일/모듈의 정확한 경로를 얻기 위해서는 GetModuleFileName을 이용하라는 얘기인것 같습니다.
실제로 저도 ISAPI 모듈등을 작업할때 GetModuleFileName를 이용해서 작업을 했었거든요.
code guru의 소스를 이용해서 한번 해봐야겠어요.
2008.12.26 10:59 [ ADDR : EDIT/ DEL ]저도 GetCurrentDirectory()란걸 생각해보니 웬지 바뀔것 같아서 검색해보니 역시나 바뀔 우려가 있다라고 되어 있더라구요. 좋은 내용 감사합니다 ^^