[英]Visual C++ GetModuleFileName() Problems
I have used the following code to open the executable file when a button is pressed: 按下按钮时,我已使用以下代码打开可执行文件:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
TCHAR buffer[MAX_PATH];
GetModuleFileName(NULL,buffer,sizeof(buffer));
ShellExecuteW(NULL, L"Open", buffer, NULL, NULL, SW_SHOWNORMAL);
}
I am now trying to open a PDF file by replacing the NULL with the PDF file name as shown: 我现在正尝试通过将NULL替换为PDF文件名来打开PDF文件,如下所示:
GetModuleFileName(_T("testt.pdf"),buffer,sizeof(buffer));
When I compile this, I get the following error: 编译时,出现以下错误:
error C2664: 'GetModuleFileNameW' : cannot convert parameter 1 from 'const wchar_t [10]' to 'HMODULE'
Once this works, the exe file will be kept in a folder with the PDF but the directory for this file may be changed, will this code update automatically to accommodate for this since I have used the GetModuleFileName? 一旦可行,该exe文件将与PDF一起保存在一个文件夹中,但该文件的目录可能会更改,由于我使用了GetModuleFileName,此代码会自动更新以适应此问题吗? Also, could someone please explain to me how I would fix this code?
另外,有人可以向我解释如何解决此代码吗?
Thank you. 谢谢。
Why do you think calling: 您为什么认为致电:
GetModuleFileName(_T("testt.pdf"),buffer,sizeof(buffer));
will open a PDF file? 将打开PDF文件?
this function is defined as follows: 该函数定义如下:
DWORD WINAPI GetModuleFileName(
_In_opt_ HMODULE hModule,
_Out_ LPTSTR lpFilename,
_In_ DWORD nSize
);
example to comment: 注释示例:
ShellExecuteW(
NULL, L"open",
L"C:\\my.pdf",
NULL,
NULL,
SW_SHOWNORMAL
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.