#include <windows.h>
#include <iostream> // wcerr
int wmain(int argc, wchar_t* argv[]) {
// Path to the PDF file (must be a wide string)
// You can use an absolute path or a relative path
LPCWSTR pdfPath = L"C:\\Users\\USER_NAME\\A_Directory\\letter_0093457341801.pdf";
// Check if the file exists before trying to open it
DWORD fileAttr = GetFileAttributesW(pdfPath);
if (fileAttr == INVALID_FILE_ATTRIBUTES || (fileAttr & FILE_ATTRIBUTE_DIRECTORY)) {
std::wcerr << L"Error: File not found: " << pdfPath << std::endl;
return 1;
}
// Open the PDF file with the default associated application
HINSTANCE result = ShellExecuteW(
nullptr, // No parent window
L"open", // Operation: "open", "print", etc.
pdfPath, // File to open
nullptr, // Parameters (not needed for PDF)
nullptr, // Default directory
SW_SHOWNORMAL // Show window normally
);
// ShellExecuteW returns a value > 32 if successful
if ((INT_PTR)result <= 32) {
std::wcerr << L"Failed to open PDF. Error code: " << (INT_PTR)result << std::endl;
return 1;
}
}
/*
run:
*/