How to check the result of PrintUIEntry call

青春壹個敷衍的年華 提交于 2019-12-25 12:54:00

问题


I'd like to use PrintUIEntryW (of printui.dll ) to install a printer driver on Windows system. My code looks like following (pseudo).

m = LoadLibrary(L"printui.dll");
printuientry = GetProcAddress(m, "PrintUIEntryW");
// set arg_string
printuientry(NULL, m, arg_string, SW_SHOW);

Could I check the return value of the function or something like GetLastError() to check if the desired call is successful? There seems no msdn entry for this function.

Thanks in advance.


回答1:


PrintUIEntry is documented here:

Rundll32 printui.dll,PrintUIEntry

rundll32 is documented is here:

INFO: Windows Rundll and Rundll32 Interface

Most importantly:

In your DLL, write the function with the following prototype:

16-bit DLL:

void FAR PASCAL __loads EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

32-bit DLL:

void CALLBACK EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

...

On Windows NT, Windows 2000, and Windows XP the behavior of Rundll32.exe is slightly different, in order to accommodate UNICODE command lines.

Windows NT first attempts to GetProcAddress for W. If this entry point is found, then the prototype is assumed to be:

void CALLBACK EntryPointW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow);

This is the same as the ANSI EntryPoint, except that the lpszCmdLine parameter is now a UNICODE string.

As you can see, functions designed to be used with rundll32 do not have a return value. And PrintUIEntry is not documented as using SetLastError() for error reporting. So, in this case, you cannot do any kind of error handling. You will have to use a different API that reports errors.



来源:https://stackoverflow.com/questions/32505112/how-to-check-the-result-of-printuientry-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!