Форум: "Основная";
Текущий архив: 2006.08.20;
Скачать: [xml.tar.bz2];
Внизработа с DLL и ее интерфейсами Найти похожие ветки
← →
JohnnySE (2006-07-05 11:50) [0]Есть бинарный файл, как его прочитать и передать в dll у которой есть интерфейс IzlibEngine c методами pkCompress(Istream* lpstrmFrom, IStream* lpstrmTo) и pkDecompress(Istream* lpstrmFrom, IStream* lpstrmTo)
← →
guav © (2006-07-05 13:53) [1]Использовать TStreamAdapter для TFileStream
← →
JohnnySE (2006-07-05 17:04) [2]unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ActiveX, StdCtrls, ZLENGINELib_TLB;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
izl : izlibEngine;
iw : iUnknown; ff : Text;
const zG : tGUID = "{C5276425-F299-11D0-8149-004095E1F439}";
zlibG : tGuid = "{C5276436-F299-11D0-8149-004095E1F439}";
izg : tGuid = "{C5276445-F299-11D0-8149-004095E1F439}";
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
FileStreamIn: TFileStream;
FileStreamOut: TFileStream;
StreamIn: IStream;
StreamOut: IStream;
FileNameIn: String;
FileNameOut: String;
begin // читаем файл
// НАЗНАЧАЕМ ПУТЬ К ФАЙЛУ
FileNameIn:= "C:\sea\in.bin";
FileNameOut:= "C:\sea\Out.txt";
FileStreamIn := TFileStream.Create(FileNameIn, fmCreate);
FileStreamOut := TFileStream.Create(FileNameOut, fmCreate);
StreamIn := TStreamAdapter.Create(FileStreamIn, soReference);
StreamOut := TStreamAdapter.Create(FileStreamOut, soReference);
izl.pkdecompress(StreamIn as IStream,StreamOut as IStream);
... здесь вылетает ошибка.
/////////////////////////////////////////////
в ZLENGINELib_TLB
IzlibEngine = interface(IUnknown)
["{C5276445-F299-11D0-8149-004095E1F439}"]
procedure pkDecompress(const lpstrmFrom, lpstrmTo: IStream); safecall;
end;
← →
guav © (2006-07-05 18:03) [3]> ... здесь вылетает ошибка.
Какая ?
> izl : izlibEngine;
Как осуществляется присвоение этой переменной значения ?
ZLENGINELib_TLB - сгенерированный по команде Import Type Library ? Тогда там должен быть класс CozlibEngine, и izl должен быть инициализирован так: izl := CozlibEngine.Create;
> FileStreamIn := TFileStream.Create(FileNameIn, fmCreate);
Для открытия для чтения должно быть fmOpenRead
← →
JohnnySE (2006-07-06 09:15) [4]За fmOpenRead - спасибо, совсем заработался
Ошибка
Project Project2.exe raised exception class EAccessViolation with message "Access violation at address 0045EC9E in module "Project2.exe". Read of address 00000000".
вот текст ZLENGINELib_TLB
unit ZLENGINELib_TLB;
{ This file contains pascal declarations imported from a type library.
This file will be written during each import or refresh of the type
library editor. Changes to this file will be discarded during the
refresh process. }
{ zlEngine 1.0 Type Library }
{ Version 1.0 }
interface
uses Windows, ActiveX, Classes, Graphics, OleCtrls, StdVCL;
const
LIBID_ZLENGINELib: TGUID = "{C5276436-F299-11D0-8149-004095E1F439}";
const
{ Component class GUIDs }
Class_zlibEngine: TGUID = "{C5276425-F299-11D0-8149-004095E1F439}";
Class_jpegEngine: TGUID = "{E196D997-FB8C-11D0-AE1D-D9180F4C4641}";
Class_tiffEngine: TGUID = "{E196D999-FB8C-11D0-AE1D-D9180F4C4641}";
type
{ Forward declarations: Interfaces }
IzlibEngine = interface;
ISequentialStream = interface;
IjpegEngine = interface;
ItiffEngine = interface;
{ Forward declarations: CoClasses }
zlibEngine = IzlibEngine;
jpegEngine = IjpegEngine;
tiffEngine = ItiffEngine;
_LARGE_INTEGER = record
QuadPart: Comp;
end;
_FILETIME = record
dwLowDateTime: UINT;
dwHighDateTime: UINT;
end;
_ULARGE_INTEGER = record
QuadPart: Largeuint;
end;
tagSTATSTG = record
pwcsName: PWideChar;
atype: UINT;
cbSize: _ULARGE_INTEGER;
mtime: _FILETIME;
ctime: _FILETIME;
atime: _FILETIME;
grfMode: UINT;
grfLocksSupported: UINT;
clsid: TGUID;
grfStateBits: UINT;
reserved: UINT;
end;
{ IzlibEngine Interface }
IzlibEngine = interface(IUnknown)
["{C5276445-F299-11D0-8149-004095E1F439}"]
procedure pkZip(pszCommandLine: PWideChar); safecall;
procedure pkUnzip(pszCommandLine: PWideChar); safecall;
procedure pkCompress(const lpstrmFrom, lpstrmTo: IStream); safecall;
procedure pkDecompress(const lpstrmFrom, lpstrmTo: IStream); safecall;
end;
ISequentialStream = interface(IUnknown)
["{0C733A30-2A1C-11CE-ADE5-00AA0044773D}"]
procedure RemoteRead(out pv: Shortint; cb: UINT; out pcbRead: UINT); safecall;
procedure RemoteWrite(var pv: Shortint; cb: UINT; out pcbWritten: UINT); safecall;
end;
{ IjpegEngine Interface }
IjpegEngine = interface(IUnknown)
["{E196D996-FB8C-11D0-AE1D-D9180F4C4641}"]
procedure CreateDIBFromJPEG(pszPathName: PWideChar; var hBitmap: SYSUINT); safecall;
end;
{ ItiffEngine Interface }
ItiffEngine = interface(IUnknown)
["{E196D998-FB8C-11D0-AE1D-D9180F4C4641}"]
procedure CreateDIBFromTIFF(pszPathName: PWideChar; var hBitmap: SYSUINT); safecall;
end;
{ zlibEngine Class }
CozlibEngine = class
class function Create: IzlibEngine;
class function CreateRemote(const MachineName: string): IzlibEngine;
end;
{ jpegEngine Class }
CojpegEngine = class
class function Create: IjpegEngine;
class function CreateRemote(const MachineName: string): IjpegEngine;
end;
{ tiffEngine Class }
CotiffEngine = class
class function Create: ItiffEngine;
class function CreateRemote(const MachineName: string): ItiffEngine;
end;
implementation
uses ComObj;
class function CozlibEngine.Create: IzlibEngine;
begin
Result := CreateComObject(Class_zlibEngine) as IzlibEngine;
end;
class function CozlibEngine.CreateRemote(const MachineName: string): IzlibEngine;
begin
Result := CreateRemoteComObject(MachineName, Class_zlibEngine) as IzlibEngine;
end;
class function CojpegEngine.Create: IjpegEngine;
begin
Result := CreateComObject(Class_jpegEngine) as IjpegEngine;
end;
class function CojpegEngine.CreateRemote(const MachineName: string): IjpegEngine;
begin
Result := CreateRemoteComObject(MachineName, Class_jpegEngine) as IjpegEngine;
end;
class function CotiffEngine.Create: ItiffEngine;
begin
Result := CreateComObject(Class_tiffEngine) as ItiffEngine;
end;
class function CotiffEngine.CreateRemote(const MachineName: string): ItiffEngine;
begin
Result := CreateRemoteComObject(MachineName, Class_tiffEngine) as ItiffEngine;
end;
end.
← →
guav © (2006-07-06 14:00) [5]> Ошибка
> Project Project2.exe raised exception class EAccessViolation
> with message "Access violation at address 0045EC9E in module
> "Project2.exe". Read of address 00000000".
ошибка свидетельствует об обращении к нулевому адресу, что обычно происходит при попытке раобты с нулевым указателем.
> izl.pkdecompress(StreamIn as IStream,StreamOut as IStream);
т.к. StreamIn и StreamOut присваиваются выше, похоже что izl = nil
см. [3] guav © (05.07.06 18:03)
> izl должен быть инициализирован так: izl := CozlibEngine.Create;
← →
JohnnySE (2006-07-06 15:23) [6]СПАСИБО. Все получилось
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2006.08.20;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.781 c