Solved

File access in DLL for windows hook

Posted on 2002-07-25
7
243 Views
Last Modified: 2010-04-04
With some help from old answers I have managed to get a couple of windows hooks working (thanks to past contributors!) ... but now when I try to access files ... problems!

I tried something REALLY SIMPLE using TFileStream, like so...

  outFile := 'c:\test.out';
  with TFileStream.Create(transFile, fmCreate or fmShareCompat) do try
    Write('TEST', 4);
  finally
    Free;
  end;

... but it crashes the application from which the hook event eminated ... No data written.

So I'm assuming there are some things I have to do to be a little more careful when attempting this stuff.

Now here comes the ugly part... Those with a faint heart, go no further ...

I am using Delphi 3 (because of certain BDE compatibility issues within the hooking app)

Wait, it gets worse!

The app being hooked is a 16-bit app.

I'm not sure if these a contributing factors, but heck if I knew why it was happening I'd just fix it and stop bothering you.
0
Comment
Question by:Hamlet081299
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 300 total points
ID: 7176869
Hi,

Shouldn't it be 'outFile'?

with TFileStream.Create(outFile, fmCreate or fmShareCompat) do try

What kind of hook are you using?

Regards, Geo
0
 
LVL 20

Expert Comment

by:Madshi
ID: 7176913
You can't write a string like that. This should work:

Write(pchar('TEST')^, 4);

Regards, Madshi.
0
 
LVL 5

Author Comment

by:Hamlet081299
ID: 7177314
oh shoot ... could be just a nasty cut and paste error ...

Originally I was reading some data from transfile and writing it to outfile.  When I had problems I simplified, but completely missed that booboo.

I'll check it out tomorrow --- Geo might have just earned himself the easiest 300pts ever!

And Madshi ... yes you can write a string like that.  Delphi easily handles literal constants as PChars.  I'm not sure why you would think that wouldn't work.  

Ironically when I got the email notification, I thought "Aha, Madshi is onto it, all my problems will be solved..."  ;-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Expert Comment

by:Madshi
ID: 7177347
Ha, you got me!!   :-)   That really works. I thought it doesn't work because "Write(strVar, Length(strVar))" doesn't work, either. But it seems that once more I underestimated Delphi's intelligence...

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:geobul
ID: 7177426
If it's the problem then you are right - easy. You just pasted the proper piece of code here, short but sufficient. Sometimes such errors are so difficult to find.

About 'Write': I didn't see that! If I had seen it I would have said the same as Madshi did. New things to learn every day.

Regards, Geo
0
 
LVL 5

Author Comment

by:Hamlet081299
ID: 7178681
Yeah, it's handy with constants that generally Delphi makes a smart decision about how to treat it.

I just tried it out and found it was just a stupid cut and paste!!!

Thanks Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 7179473
Thanks a lot. The pleasure was mine.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now