为什么PowerBuilder中不能正常调用Delphi写的Dll(0分)

  • 主题发起人 flyballball
  • 开始时间
F

flyballball

Unregistered / Unconfirmed
GUEST, unregistred user!
我用delphi开发了一个设置打印参数的动态链接库,在PB6.0中调用,却总说
calling external function err
PB中调用方式为 FUNCTION int set_print(int xpos,int ypos) Library "./setprintdll.dll"

DLL代码为
library setprintdll;
uses
SysUtils,Windows,
Classes, printers,winspool;
{$R *.res}
procedure DLLEntryPoint(dwReason: DWord);
begin
case dwReason of
DLL_PROCESS_ATTACH : MessageBeep(0);
DLL_PROCESS_DETACH : MessageBeep(0);
DLL_THREAD_ATTACH : MessageBeep(0);
DLL_THREAD_DETACH : MessageBeep(0);
end;
end;
function Set_Print(Height:Integer;Width:Integer):Integer;stdcall;
var
PrintDevice, PrintDriver, PrintPort : array[0..255] of Char;
hDMode : THandle;
hPrinter: THandle;
FormInfo: TFormInfo1;
PaperSize: TSize;
PaperRect: TRect;
errcode: integer;
s: string;
begin
Printer.GetPrinter(PrintDevice, PrintDriver, PrintPort, hDMode);
OpenPrinter(PrintDevice, hPrinter, nil);
if hPrinter = 0 then
raise Exception.Create('Failed to open printer!');
//设置纸张格式结构参数
FormInfo.Flags := FORM_USER;
FormInfo.pName := 'custom';
PaperSize.cx := Width;
PaperSize.cy := Height;
PaperRect.Left := 0;
PaperRect.Top := 0;
PaperRect.Right := Width;
PaperRect.Bottom := Height;
FormInfo.Size := PaperSize;
FormInfo.ImageableArea := PaperRect;
if not AddForm(hPrinter, 1, @FormInfo) then
begin
errcode := GetLastError;
if errcode <> ERROR_FILE_EXISTS then // Form name exists?
begin
case errcode of
ERROR_ACCESS_DENIED: s := 'Access is denied';
ERROR_INVALID_HANDLE: s := 'The handle is invalid';
ERROR_NOT_READY: s := 'The device is not ready';
ERROR_CALL_NOT_IMPLEMENTED:
s := 'Function "AddForm" is not supported on this system';
else
s := 'Failed to add a Form (paper) name!';
end;
raise Exception.Create(s);
end;
end;
SetForm(hPrinter,'custom', 1, @FormInfo);
ClosePrinter(hPrinter);
Result :=1;
end;
exports
Set_Print;
begin
DLLProc := @DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.

请各位帮帮忙,谢谢
 
顶部