目標是通過 Windows-API 列印一個 htm/html 檔案::ShellExecuteExW。
的引數::ShellExecuteExW是
shell_info.lpVerb = "open";
shell_info.lpFile = "C:\Windows\System32\rundll32.exe";
shell_info.lpParameters = "C:\Windows\System32\mshtml.dll ,PrintHTML "C:\Temp\test.html"";
lpFile并lpParameters從注冊表項中獲取"\HKEY_CLASSES_ROOT\htmlfile\shell\print\command"
錯誤資訊:

C:\Windows\system32\rundll32.exe C:\Windows\system32\mshtml.dll ,PrintHTML "C:\Temp\test.html"如果運行via cmd,一切都很好。出現列印對話框。
需要如何::ShellExecuteExW呼叫才能實作與cmd相同的行為?
uj5u.com熱心網友回復:
螢屏截圖中生成錯誤的代碼是否可能與您在此處顯示的不同?我問這個是因為你似乎沒有逃避任何雙引號或反斜杠。在我看來,您的編譯器在編譯該代碼時至少應該給出一個錯誤。
但是我只是嘗試了下面的代碼,這似乎有效。希望能幫助到你。
int main()
{
SHELLEXECUTEINFOW shell_info = { 0 };
shell_info.cbSize = sizeof(SHELLEXECUTEINFOW);
shell_info.lpVerb = L"open";
shell_info.lpFile = L"C:\\Windows\\System32\\rundll32.exe";
shell_info.lpParameters = L"C:\\Windows\\System32\\mshtml.dll ,PrintHTML \"C:\\Temp\\test.html\"";
shell_info.nShow = SW_SHOWNORMAL;
ShellExecuteExW(&shell_info);
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/483259.html
