Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was trying to use enumprinters function in installshield to get the list of printer names.

One of the enumprinters parameter is of LPBYTE type, i couldnt get the datatype LPBYTE in installshield, if i use pointer type the function is crashing.

BOOL EnumPrinters(
_In_ DWORD Flags,
_In_ LPTSTR Name,
_In_ DWORD Level,
_Out_ LPBYTE pPrinterEnum,
_In_ DWORD cbBuf,
_Out_ LPDWORD pcbNeeded,
_Out_ LPDWORD pcReturned
);

Could any one please let me know how could i use the datatype LPBYTE in installshield

Thanks in advance.

What I have tried:

I was trying to use enumprinters function in installshield to get the list of printer names.

One of the enumprinters parameter is of LPBYTE type, i couldnt get the datatype LPBYTE in installshield, if i use pointer type the function is crashing.
Posted
Updated 1-May-21 4:16am

The LPBYTE type is just a pointer to a byte array; you can use unsigned char * instead. And the EnumPrinters function (Winspool.h) - Win32 apps | Microsoft Docs[^] explains the requirements for each of the parameters.
 
Share this answer
 
Comments
karthik836 29-Apr-21 10:02am    
Hi Richard,

How would i use unsigend char * in installshield, as i could see the datatype Char is only allowed.

Can i get an example of declaring the variable as unsigned char * in installshield

Thanks in advance
Richard MacCutchan 29-Apr-21 11:06am    
Sorry, I have not used installshield so I do not know the answer. Exactly how are you calling the EnumPrinters function?
karthik836 1-May-21 9:35am    
Hi Richard,

sorry for the delay

Please find the below code,
export prototype INT winspool.EnumPrintersA(LONG, BYREF STRING, LONG, BYREF POINTER, LONG, BYREF LONG, BYREF LONG);
prototype NUMBER KERNEL.LocalAlloc ( NUMBER, NUMBER );
prototype NUMBER KERNEL.LocalFree(NUMBER);
#define LPTR 0X0040

function enumtest()

NUMBER nResult;
STRING svName;

BOOL resa;

LONG neededa;
LONG returneda;


POINTER structpinfo;

LONG n;

begin
svName = "";

neededa = 0;
returneda = 0;

nResult = UseDLL("winspool.drv");
if (nResult < 0 ) then
return ERROR_FUNCTION_FAILED;
endif;


resa = EnumPrintersA(6, svName, 4, structpinfo, neededa, neededa, returneda);

LocalFree(structpinfo);
structpinfo = LocalAlloc(LPTR,neededa);

if(!structpinfo == NULL)then
SprintfBox(INFORMATION,"start buffering","[%d]", structpinfo);

endif;

resa = EnumPrintersA(6, svName, 4, structpinfo, neededa, neededa, returneda);


if(!resa)then
SprintfBox(INFORMATION,"buffering size","[%d]", neededa);
endif;

After allocation of memory the below line is getting crash
resa = EnumPrintersA(6, svName, 4, structpinfo, neededa, neededa, returneda)

I have followed the reference link from flexera community
https://community.flexera.com/t5/InstallShield-Forum/Enumerate-printers/td-p/97983
C++
resa = EnumPrintersA(6, svName, 4, structpinfo, neededa, neededa, returneda);

The last two parameters must be pointers to variables, but you are using the values. Also with level = 4, the name field should be NULL. It should be:
C++
resa = EnumPrintersA(6, NULL, 4, structpinfo, neededa, &neededa, &returneda);

Check EnumPrinters function (Winspool.h) - Win32 apps | Microsoft Docs[^] carefully.

And you should avoid calling
C++
LocalFree(structpinfo);

before you have allocated any space to it, as that may try to free some random address.
 
Share this answer
 

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