Autor Beitrag
scrooge
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 200



BeitragVerfasst: Fr 11.07.03 19:37 
Hi,

ahb da ein Problem mit CreateFile etc. Un zwar hab ich in eine Datei Records (Integer, wParam, lParam, TDateTime) geschrieben. Hab gehofft das auf die gleiche Methode wieder aus lesen zu können, bekomme allerdings ne Fehlermeldung. Hab den verwendeten Code unten mal aufgeführt.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var HookData:array of THookData; // Integer, wParam,lParam, TDateTime
PHookData :^THookData;
begin
setlength(HookData, 2);

s := Edit1.text;
DataFile := CreateFile(Pchar(s),GENERIC_READ or GENERIC_WRITE, 0nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);


for i := 1 to SizeofFile div sizeof(THookData) do
begin
ReadFile(DataFile, PHookData, sizeof(THookData),h,nil);
HookData[i] := PHookData^;
end;


Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Fr 11.07.03 20:45 
Ich glaube, du musst erstmal mit New(PHookData) ausführen, um der Variable Speicher zuzuweisen.

Oder:
ausblenden Delphi-Quelltext
1:
ReadFile (DataFile, @HookData[i], sizeof(THookData),h,nil);					

Das würde ich machen.

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.

_________________
Life is a bad adventure, but the graphic is really good!
scrooge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 200



BeitragVerfasst: Fr 11.07.03 21:50 
Hab da ganze jetzt mal so probiert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
New(PHookData);
s := Edit2.Text;
DataFile := CreateFile(Pchar(s),GENERIC_READ or GENERIC_WRITE, 
  0nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
int2 := GetFileSize(DataFile, nil);
setlength(HookData, int2 div sizeof(THookDAta) + 1);
for i := 1 to int2 div sizeof(THookData) do
begin
ReadFile(DataFile, PHookdata, sizeof(THookData),h,nil);
HookData[i] := PHookDAta^;
end;

die zweite Variante kommt erst gar nicht durch die Fehlersuche ohne, dass der Arlam schlägt.

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Fr 11.07.03 22:00 
Welche Fehlermeldung genau?

_________________
Life is a bad adventure, but the graphic is really good!
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Fr 11.07.03 23:07 
Ich tippe stark auf EAccessViolation.

Du setzt erstens die Länge von HookData auf 2, liest aber sicher mehr ein und dann zeigt, wie Andreas Pfau schon bemerkt hat, PHookData ins Nirana.

Mit einem TFileStream würdest du dir das Leben etwas einfacher machen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var HookData:array of THookData;
begin 
  s := Edit1.Text; 
  DataFile := CreateFile(PChar(s), GENERIC_READ or GENERIC_WRITE, 
    0nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

  ...
  SetLength(HookData, SizeofFile div SizeOf(THookData));
  ReadFile(DataFile, @HookData[0], SizeofFile, h, nil); 

  ...

_________________
Ist Zeit wirklich Geld?
scrooge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 200



BeitragVerfasst: So 13.07.03 14:41 
Hi,
hab das mal mit nem FileStream probiert und es klappt. Nur noch ne letzte Frage: Da ich das ganze mit einem Hook verbunden hab, der die Eingaben bei jedem AUfruf der Hook-Funktion speichert, musste ich das ganze in eine Dll auslagern. Das Problem ist jetzt, dass ich ne Proc hab mit der man den fertigen Hook erstellen kann.In diser Proc kann man unter anderem den Datei-Namen für die Log Datei angeben. Und genau hier ein Problem.Wenn ich in der Hook-Proc jedesmal neu die Datei öffne, stzelle ich plötzich fest, dass der String in dem ich den Datei-Namen gespeichert habe plötzlich leer ist. Wenn ich die Datei einmal z.B mit einem FileStream oder CreateFile öffne (in der Proc mit der ich den Hook erstelle) und dann in der Hook-Proc einfach darauf zugreifen will um weitere Einträge zu machen, führt der die Hook-Proc erst gar nicht aus.
wIe krieg das jetzt also hin, dass der die Hook-Infos in die Datei einträgt und ich mir trotzdem den Log-Filename aussuchen kann ??