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:
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? 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?
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
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.