Форум: "WinAPI";
Текущий архив: 2003.04.21;
Скачать: [xml.tar.bz2];
ВнизНе работает ENUMPrinters : почему-то возвращает 0 ? Найти похожие ветки
← →
DALEX (2003-02-22 20:29) [0]Уважаемые Мастера Delphi ! Подскажите пожалуйста как определить установленные в системе принтеры? Я пробовал воспользоваться функцией ENUMPrinters, но она почему-то возвращает 0. Скорее всего я что-то не так делаю :((( Помогите кто чем может, а то Ламеру не справиться...
Код следующий:
procedure TForm1.TabSheet3Show(Sender: TObject);
var dw : DWORD;
C : Cardinal;
PI1 : PRINTER_INFO_1;
Name : Array of Char;
Result : LONGBOOL;
begin
Result:=ENUMPrinters(PRINTER_ENUM_LOCAL,PChar(Name),
1,@PI1,SizeOf(PI1),dw,C);
if Result <> 0 then
StaticText25.Caption:=PI1.pName
else StaticText25.Caption:="Error"
end;
А зачем нужны dw и C так и не понял...
← →
Cobalt (2003-02-23 03:25) [1]Продолжаем разъяснять, кто есть ху....
Ламер - человек(?), который на все предложения почитать, посмотреть и т.п. отвечает типа "сам умный, дай код!"
Чайник - новичок в к-либо области (как правило, в большинстве)
Внимательно перечитайте справку, а также перед вызовом функции покажите (showmessage), какой размер у PI1.pDescription, .pName и .pComment.
Также, pcb Needed
Pointer to a value that receives the number of bytes copied if the function succeeds or the number of bytes required if cbBuf is too small.
сравнивали с cBuf? (после вызова функции)
Ну, а уж насчет pcReturned (надеюсь, что это не клиника...)
Pointer to a value that receives the number of PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_4, or PRINTER_INFO_5 structures that the function returns in the array to which pPrinterEnum points.
P.S. Учите английский
P.P.S. Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
← →
DALEX (2003-02-23 11:35) [2]Уважаемые Мастера поздравляю всех (М) с 23 февраля!
Неужели никто не порадует кодом ?! чтобы я до конца разобрался с этой функцией и подобными ей ;)
← →
Набережных С. (2003-02-23 15:54) [3]
type
TEnumStructCallback = function(pItem, Value: Pointer): bool; stdcall;
procedure CheckResult(ResCode: Cardinal);
begin
if ResCode <> ERROR_SUCCESS then
begin
SetLastError(ResCode);
RaiseLastOSError;
end;
end;
procedure EnumStruct(StructArray: pointer; Count, ItemSize: Cardinal; EnumFunc, Value: Pointer);
var
n: Cardinal;
begin
if StructArray = nil then Exit;
for n:=0 to Pred(Count) do
begin
if not TEnumStructCallback(EnumFunc)(StructArray, Value) then Break;
Inc(PByte(StructArray), ItemSize);
end;
end;
function PrintersEnum(Flags, Level: Cardinal; Name: PChar;
EnumFunc, Value: pointer): Cardinal; stdcall;
var
pPI: Pointer;
Size, Count,
ItemSize: Cardinal;
begin
case Level of
1: ItemSize:=SizeOf(TPrinterInfo1);
2: ItemSize:=SizeOf(TPrinterInfo2);
4: ItemSize:=SizeOf(TPrinterInfo4);
5: ItemSize:=SizeOf(TPrinterInfo5);
else
Result:=ERROR_INVALID_LEVEL;
Exit;
end;
pPI:=nil; Size:=0;
try
repeat
ReallocMem(pPI, Size);
if EnumPrinters(Flags, Name, Level, pPI, Size, Size, Count) then
Result:= ERROR_SUCCESS else Result:=GetLastError;
until Result <> ERROR_INSUFFICIENT_BUFFER;
if (Result = ERROR_SUCCESS) and (Count > 0) then
EnumStruct(pPI, Count, ItemSize, EnumFunc, Value);
finally
FreeMem(pPI);
end;
end;
//##############################################
function EnumCallback(var Item: TPrinterInfo1; List: TStrings): bool; stdcall;
begin
List.Add("Name:"#9#9+Item.pName);
List.Add("Description:"#9+Item.pDescription);
List.Add("Comment:"#9#9+Item.pComment);
List.Add(StringOfChar("%",32));
Result:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CheckResult(PrintersEnum(PRINTER_ENUM_LOCAL, 1, nil, @EnumCallback, Memo1.Lines));
end;
← →
DALEX (2003-02-23 16:28) [4]> Набережных С. !
Спасибо тебе огромное, сейчас буду смотреть!
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2003.04.21;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.009 c