cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
lmilesuk
Level 4

DeletePrinterDriver MSDN Function

Hi,

I wonder if someone could help, I'm having trouble porting an msdn function into my installscript; Im attempting to use the DeletePrinterDriver function;

https://msdn.microsoft.com/en-us/library/windows/desktop/dd183545(v=vs.85).aspx

When I run it I get a setup interrupted and the function never completes and moves on to the next call so I know there must be something fundamentally wrong here.

My typedef looks like;

prototype BOOL SETUPAPI.DeletePrinterDriver(
POINTER, //_In_ LPTSTR pName,
POINTER,//_In_ LPTSTR pEnvironment,
BYREF STRING //_In_ LPTSTR pDriverName
);


And my code looks like this;

function del_swi_DeletePrinterDriver(hMSI)

STRING szDriverName;

begin


szDriverName = "Canon iR C2880/C3380";


if( DeletePrinterDriver(NULL,NULL,szDriverName) = 0 ) then

MessageBox(FormatMessage(Err.LastDllError), WARNING);
Err = GetLastError();
SprintfBox( INFORMATION, "CustomAction: RegisterDriverINF", "SetupCopyOEMInfA Failed: %s",Err);

endif;


MessageBox("Function Delete Driver - Complete", WARNING);

end;



It compiles ok however every-time I run it I get the following error;

CustomAction del_swi_DeletePrinterDriver returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 11:01:23: del_swi_DeletePrinterDriver. Return value 3.

This isn't very helpful.

I'm already successfully using the SetupUninstallOEMInfA, SetupCopyOEMInfA functions in the same manner but can't work out why this isn't working and the error messages aren't v.helpful, anyone have any suggestions???

Thanks in advance
Labels (1)
0 Kudos
(6) Replies
MichaelU
Level 12 Flexeran
Level 12 Flexeran

Since InstallShield 2011 or so, we will default to using Unicode entry points when available. Because of this, you should either specify DeletePrinterDriverA, or use WSTRING and/or WPOINTER types to correspond to LPTSTR / LPCTSTR (or of course LPWSTR / LPCWSTR) parameters. I would start with that, and if that doesn't help, also consider seeing if you can get further information with a try/catch block.
0 Kudos
MarkusLatz
Level 8

You can try to write a little VBA (i.e. office or something else you have) and test the WIN API function.

Declare Function DeletePrinterDriver Lib "winspool.drv" Alias "DeletePrinterDriverA" (ByVal pName As String, ByVal pEnvironment As String, ByVal pDriverName As String) As Long

There you can check if it in principle work for your case.

regards

Markus
0 Kudos
lmilesuk
Level 4

MichaelU wrote:
Since InstallShield 2011 or so, we will default to using Unicode entry points when available. Because of this, you should either specify DeletePrinterDriverA, or use WSTRING and/or WPOINTER types to correspond to LPTSTR / LPCTSTR (or of course LPWSTR / LPCWSTR) parameters. I would start with that, and if that doesn't help, also consider seeing if you can get further information with a try/catch block.


How would I execute a try and catch block as none of the suggestions you've offered here seem to work?
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

See the help topic Exception Handling, and on the Err Object. When you catch an exception, you can examine the properties on the Err object for possible additional information.
0 Kudos
lmilesuk
Level 4

MichaelU wrote:
See the help topic Exception Handling, and on the Err Object. When you catch an exception, you can examine the properties on the Err object for possible additional information.


Thanks for that it's not too helpful though, no matter what I change I get the same error, I also get the same with OpenPrinter Call as well;


prototype BOOL SETUPAPI.DeletePrinterDriverW(c
WPOINTER, //_In_ LPTSTR pName,
WPOINTER,//_In_ LPTSTR pEnvironment,
WSTRING //_In_ LPTSTR pDriverName
);

prototype BOOL SETUPAPI.OpenPrinterW(
WSTRING, //_In_ LPTSTR pPrinterName,
NUMBER,//_Out_ LPHANDLE phPrinter,
WPOINTER//_In_ LPPRINTER_DEFAULTS pDefault
);
c

try
OpenPrinterW(szDriverName, Printer, NULL);


catch
Err = GetLastError();
SprintfBox (INFORMATION, "L862Error","Error occured: %i\n\n%s\n\n%s", Err.Number, Err.Description, Err.LastDllError);

endcatch;

MessageBox("Open Printer - Complete", WARNING);

MessageBox("DeletePrinterDriverW - Starting", WARNING);

try
if( DeletePrinterDriverW(NULL,NULL,szDriverName) = 0 ) then
MessageBox(FormatMessage(Err.LastDllError), WARNING);
Err = GetLastError();
SprintfBox( INFORMATION, "CustomAction: RegisterDriverINF", "DeletePrinterDriverA Failed: %s",Err);

endif;

catch

SprintfBox (INFORMATION, "Error","Error occured: %i\n\n%s\n\n%s", Err.Number, Err.Description, Err.LastDllError);

endcatch;


I always get a -2147219709 error so unable to run any of these functions, its especially weird as I can run the following two API's ok


prototype BOOL SETUPAPI.SetupCopyOEMInfA( // ASCII Version From SetupAPI.h
POINTER, //IN PCSTR SourceInfFileName,
POINTER, //IN PCSTR OEMSourceMediaLocation, OPTIONAL
POINTER, //IN DWORD OEMSourceMediaType,
POINTER, //IN DWORD CopyStyle,
BYREF STRING, //OUT PSTR DestinationInfFileName, OPTIONAL
POINTER, //IN DWORD DestinationInfFileNameSize, Set MAX_PATH
POINTER, //OUT PDWORD RequiredSize, OPTIONAL
POINTER //OUT PSTR *DestinationInfFileNameComponent OPTIONAL
);

//MSDN api to remove infe file from Magu to /inf and file repo
prototype BOOL SETUPAPI.SetupUninstallOEMInfA(
POINTER, // PCWSTR InfFileName,
NUMBER, // _In_ DWORD Flags,
POINTER //_In_ PVOID Reserved
);


And yes I've tried OpenPrinterA and DeletePrinterDriverA in teh same format as the OEMSetups, same error.

V.Strange!!

Any Idea's?
0 Kudos
lmilesuk
Level 4

MarkusLatz wrote:
You can try to write a little VBA (i.e. office or something else you have) and test the WIN API function.

Declare Function DeletePrinterDriver Lib "winspool.drv" Alias "DeletePrinterDriverA" (ByVal pName As String, ByVal pEnvironment As String, ByVal pDriverName As String) As Long

There you can check if it in principle work for your case.

regards

Markus


Hi Markus,

I'm also having problems with OpenPrinter, could you give me some pointer is what the VBS would look like to check I get a return value for this?
0 Kudos