Click here to Skip to main content
15,033,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Has any one used the following windows API

C++
HRESULT UploadPrinterDriverPackage(
  _In_     LPCTSTR pszServer,
  _In_     LPCTSTR pszInfPath,
  _In_     LPCTSTR pszEnvironment,
  _In_     DWORD dwFlags,
  _In_     HWND hwnd,
  _Out_    LPTSTR pszDestInfPath,
  _Inout_  PULONG pcchDestInfPath
);


I want to know what is the 5th parameter to the API?The documentation says -
hwnd [in] - A handle to the copying user interface.


which simply does not make much sense.


I have had no success to make this API work and keep getting E_INVALIDARGS return value. Since other parameters are fairly straight forward , my assumption is something is wrong about the 5th parameter.
I can make a guess that it might be the handle to the windows which is supposed to show the progress of the upload operation, though I would be happy to use the silent flag. Nonetheless, I tried using NULL as well as a dialog handle (created using CreateDialog) into this API, both in vain.

Any help will be deeply appreciated.
Posted
Updated 2-May-17 1:20am
Comments
cariolihome 29-Nov-14 10:40am
   
Yes, You are right. Its a parent window for any window which will be shown by the system during upload
So, please specify other parameters. Its can help to solve E_INVALIDARGS return value.
kaushik_code 29-Nov-14 11:03am
   
Not sure if I understood you correctly. Here are the other arguments
pszServer = NULL
pszInfpath = local path to the driver inf file. (eg.c:\abcd.inf)
pszEnvironment = Windows NT x86 (as mentioned in the documentation, i am using a 32 bit system)
dwFlags - UPDP_UPLOAD_ALWAYS
hwnd - ?
pszDestInfPath - pointer to wchar array of 100 chars.
pcchDestInfPath - 100

Can you help me know what should be the 5th parameter or is there a problem with any other?
cariolihome 29-Nov-14 11:07am
   
5-th parameter can be NULL or a handle of any existing window
The reason of E_INVALIDARGS error is a bad value of other parameter
So, please specify exact values of all parameters.
(try set pszEnvironment to NULL since inf file has information about supported target system)
kaushik_code 29-Nov-14 11:25am
   
Thank you for your response . I think the first 5 parameters are clear by my earlier comment. Regarding 6th and 7th parameter , here is what I did:

WCHAR pszDestInfPath[100] = {0};
ULONG cchDestInfPath = sizeof(pszDestInfPath)/sizeof(WCHAR);

UploadPrinterDriverPackage (
NULL,
L"C:\abcd.inf",
L"Windows NT x86",
UPDP_UPLOAD_ALWAYS,
hwndDlg, /*valid handle created by an earlier call to CreateDialog*/
pszDestInfPath,
&cchDestInfPath
);

cariolihome 29-Nov-14 11:34am
   
Try this one:

WCHAR szDestInfPath[MAX_PATH];
ULONG cchDestInfPath = MAX_PATH;

UploadPrinterDriverPackage(
NULL,
L"C:\AnyFolder\InfFile.inf",
NULL,
0,
NULL,
szDestInfPath,
&cchDestInfPath);

Does inf file have CatalogFile directive ?
Does *.cat file specified in CatalogFile directive exist on file system ?
kaushik_code 29-Nov-14 11:45am
   
Yes I will try and let you know . It is a signed driver with a valid .cat file.
cariolihome 29-Nov-14 11:49am
   
You can find additional info about driver setup process in C:\Windows\Inf\setupapi.dev.log
kaushik_code 29-Nov-14 11:57am
   
Yes , you are right. But nothing related to copy or installation even starts. The API fails immediately without doing anything. But yes I will make sure I have a look at that as well.
cariolihome 29-Nov-14 12:24pm
   
According to the UploadPrinterDriverPackage function implementation cchDestInfPath cant be less then MAX_PATH characters.
kaushik_code 30-Nov-14 12:16pm
   
How did you find that ?
cariolihome 30-Nov-14 12:17pm
   
By disassembling function implementation.
kaushik_code 30-Nov-14 12:45pm
   
That is a very useful information indeed and a big drawback in the documentation. I can update you on my findings tomorrow. But meanwhile if you can let me know what tools are useful for disassembling and retrieving this kind of information , that will be great. A big thanks once again. Will keep you updated.
cariolihome 30-Nov-14 12:51pm
   
For retrieving parameter restrictions sufficient to use Microsoft Visual Studio in debugging mode.
kaushik_code 1-Dec-14 1:14am
   
Many thanks. It worked perfectly!
kaushik_code 1-Dec-14 22:27pm
   
Hi,

Stuck into another problem. Not sure if you indeed used this API ever to install drivers into remote machines.I got success to locally install the driver. But when I am trying to install in a remote 2008 R2/2012 server, I can see the driver files being copied initially as a result of this API call, but eventually the API fails with "operation not supported" and the copy operation is rolled back.

I saw exactly the same behavior when I used rundll32, printui.dll PrintUIENtry method to achieve the same objective.

Wondering if it is not possible to remotely install printer drivers unless you have an exe running in the remote machine. Or is it the specific OS?
cariolihome 4-Dec-14 16:30pm
   
Did You look at setupapi log files on both machines ?
Jochen Arndt 30-Nov-14 6:00am
   
The backslash in path names must be escaped. So you must use:
L"C:\\abcd.inf"
However, I don't know if this results in E_INVALIDARGS. I would expect some kind of file not found error.
cariolihome 30-Nov-14 8:09am
   
You are right. Of course backslash in path names must be escaped.
Function returns HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) and HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) when path doesn't exist or file doesn't found.

if you use the flag UPDP_SILENT_UPLOAD a NULL hwnd should be working. See UploadPrinterDriverPackage documentation.
   
Thanks to cariolihome for this comment

According to the UploadPrinterDriverPackage function implementation cchDestInfPath cant be less then MAX_PATH character
   
Comments
BillWoodruff 15-Dec-14 9:33am
   
Please post replies and comments to a person who left a comment to you, or answered your question, by using the "Have a Question or Comment?" button. Do not post replies/comments as "solutions" as you do here.
kaushik_code 15-Dec-14 22:45pm
   
But the comment led to a solution here. That is why it has been pasted as a solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900