请帮忙解决以下问题(50分)

Y

yeo

Unregistered / Unconfirmed
GUEST, unregistred user!
请帮忙解决以下问题:
以下是程序段:
procedure prns(PrinterName:String;
S:String);
var
Handle: THandle;
N: DWORD;
do
cInfo1: TDocInfo;
pDocName : PChar;
pOutputFile : PChar;
pDataType : PChar;
begin
if not OpenPrinter(PChar(PrinterName), Handle, 0) then
begin
ShowMessage('error' + IntToStr(GetLastError));
Exit;
end;

withdo
cInfo1do
begin
pDocName:=PChar('testdo
c');
pOutputFile:=PChar(s);
pDataType:='RAW';
end;

if StartDocPrinter(Handle,1,@DocInfo1)=0 //问题就在这里
then
showmessage('startdo
c');
StartPagePrinter(Handle);
WritePrinter(Handle,PChar(S),Length(S),N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
prns('Epson LQ-1600K','A');
问题:
1、当StartDocPrinter(Handle,1 这里为1运行就会出现以下错误:
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 72F7AD86 in module 'winspool.drv'. Read of address 00000025'.
当设置为其他数值就没有此出错问题,但是返回值总是0(在API说明中,Level数值用于win95,为什么此处设置为1会有不一样?我的系统是xp)
2、对于StartDocPrinter函数,这里的pDocInfo具体该如何设置?(由于程序是参考别人的),看API说明,这里是缓冲区设置,什么意思??
 
W

wql

Unregistered / Unconfirmed
GUEST, unregistred user!
兄弟,DocInfo1: TDocInfo;
TDocInfo里面有未分配的空间啊,例
如PChar等,你不给他分配空间,当然就......,嘿嘿!
 
Y

yeo

Unregistered / Unconfirmed
GUEST, unregistred user!
还是不明白???
 
W

wql

Unregistered / Unconfirmed
GUEST, unregistred user!
例如:只是例如
TDocInfo=Record
a:dword;
b:pchar;
c:array [0..168] of char;
end;
Var
aa:TDocInfo;

begin
Get什么东西(aa);
// 出现'Access violation at
因为 b:pchar;没有分配内存,所以.....应该:
end;

Var
tm:array [1..255] of char;
begin
aa.b:=pchar(@tm);
end;
 
K

kinneng

Unregistered / Unconfirmed
GUEST, unregistred user!
New(DocInfo1);加这个看看
withdo
cInfo1do
begin
pDocName:=PChar('testdo
c');
.....
用完还有释放它
Dispose(DocInfo1);
 
Y

yeo

Unregistered / Unconfirmed
GUEST, unregistred user!
接受答案了.
 

Similar threads

S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
906
import
I
I
回复
0
查看
545
import
I
I
回复
0
查看
722
import
I
顶部