GetModuleFileName() C语言问题
3个回答
2013-08-26
展开全部
首先,这是一个Win32的API,必须使用Win32的编译器,用VC++还行,TC就算了。
然后,包含windows.h头文件,函数原型如下:
DWORD GetModuleFileName(
HMODULE hModule, // handle to module to find filename for
LPTSTR lpFilename, // pointer to buffer to receive module path
DWORD nSize // size of buffer, in characters
);
Parameters
hModule
Handle to the module whose executable filename is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file used to create the calling process.
lpFilename
Pointer to a buffer that is filled in with the path and filename of the given module.
nSize
Specifies the length, in characters, of the lpFilename buffer. If the length of the path and filename exceeds this limit, the string is truncated.
Return Values
If the function succeeds, the return value is the length, in characters, of the string copied to the buffer.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
然后,包含windows.h头文件,函数原型如下:
DWORD GetModuleFileName(
HMODULE hModule, // handle to module to find filename for
LPTSTR lpFilename, // pointer to buffer to receive module path
DWORD nSize // size of buffer, in characters
);
Parameters
hModule
Handle to the module whose executable filename is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file used to create the calling process.
lpFilename
Pointer to a buffer that is filled in with the path and filename of the given module.
nSize
Specifies the length, in characters, of the lpFilename buffer. If the length of the path and filename exceeds this limit, the string is truncated.
Return Values
If the function succeeds, the return value is the length, in characters, of the string copied to the buffer.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-26
展开全部
#include "windows.h"
char path[512];
GetModuleFileName(NULL,path,512);
这样就取得当前运行程序的全路径了
char path[512];
GetModuleFileName(NULL,path,512);
这样就取得当前运行程序的全路径了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-26
展开全部
头文件:WinBase.h
实例:
1 WCHAR path[MAX_PATH];
2 char chpath[MAX_PATH];
3
4 GetModuleFileName(NULL,path,sizeof(path));
5
6 wcstombs(chpath,path,MAX_PATH);
7 std::cout<<chpath<<std::endl;
实例:
1 WCHAR path[MAX_PATH];
2 char chpath[MAX_PATH];
3
4 GetModuleFileName(NULL,path,sizeof(path));
5
6 wcstombs(chpath,path,MAX_PATH);
7 std::cout<<chpath<<std::endl;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询