 |
madshi.net high quality low level programming
|
| View previous topic :: View next topic |
| Author |
Message |
Davita
Joined: 13 Sep 2005 Posts: 106
|
Posted: Sun Feb 22, 2009 4:41 pm Post subject: Several Questions with madCodeHook |
|
|
Hello
Again I need your support guys, thanks in advance
1) I'm using heavilly madshi's IPC in my project. Everything worked fine until now. Here's my problem. When I want to send a message and get a reply as string, the program throws access violation exceptions. The problem is that I don't know length of replied string while calling IPCSendMessage. I tried increasing AnswerLen to 1024 and more(reply string is much less then 1024 bytes, but still, don't know the exact length), but doesn't help. any solutions? here's the code
var Msg, TempRules: string;
begin
SendIpcMessage(IPC_CHANNEL, PChar(Msg), Length(Msg) + 1,
@TempRules, sizeof(string) {what have i to put here?}, INFINITE, False);
end;
2) Will I get some speedups(over delphi version) if I rewrite the hook dll to C? I have C++ compiler 11 installed. |
|
| Back to top |
|
 |
dcsoft
Joined: 11 Dec 2004 Posts: 353 Location: San Francisco Bay Area, CA USA
|
Posted: Mon Feb 23, 2009 4:40 am Post subject: Don't use string |
|
|
It's easier to use the fixed character buffer for the answer:
| Code: |
var
TempRules : Array[0..4096] of Char;
begin
SendIpcMessage(IPC_CHANNEL, Msg, StrLen(Msg) + 1, @TempRules, sizeOf(TempRules), INFINITE, FALSE);
end;
|
And in the .exe:
| Code: |
procedure HandleIPCRequest(name : pchar;
messageBuf : pointer;
messageLen : dword;
answerBuf : pointer;
answerLen : dword); stdcall;
// this function is called by the ipc message whenever our dll contacts us
begin
if (answerBuf <> nil) and (answerLen > 0) then
StrPLCopy (PChar(answerBuf), 'my string answer', answerLen - 1);
end;
|
-- David |
|
| Back to top |
|
 |
Davita
Joined: 13 Sep 2005 Posts: 106
|
Posted: Mon Feb 23, 2009 5:11 am Post subject: |
|
|
wow. You can't imagine how you helped me. many many thanks
what about second question?  |
|
| Back to top |
|
 |
dcsoft
Joined: 11 Dec 2004 Posts: 353 Location: San Francisco Bay Area, CA USA
|
Posted: Mon Feb 23, 2009 4:08 pm Post subject: |
|
|
Glad it worked for you! I'm no Delphi expert by any means but recently had to struggle through this same issue.
So I've plenty of experience using MadCodeHook and Visual C++. I don't know for sure, but I really don't think that performance is that much different than in Delphi. Both probably spend most of their time in the Windows system calls and not in the VC or Delphi code itself.
Theoretically you might get smaller hook DLL's in Delphi since both share the same runtime library, and you don't need the VC++ one in addition to the Delphi one linked in with the madcodehook library.
Many years ago I was good at Turbo Pascal, but now all these @, PChar, etc. is foreign to me and I'm much more productive in VC++, that's why I use MadCodeHook and VC++, not because of any performance increase.
Cheers,
David |
|
| Back to top |
|
 |
Davita
Joined: 13 Sep 2005 Posts: 106
|
Posted: Tue Feb 24, 2009 8:17 pm Post subject: |
|
|
Thank you very much for your help  |
|
| Back to top |
|
 |
madshi Site Admin
Joined: 21 Mar 2004 Posts: 5908
|
Posted: Wed Feb 25, 2009 10:32 am Post subject: |
|
|
| Delphi and MSVC++ don't differ much in performance. So using MSVC++ instead of Delphi will most probably not make any difference. However, the Delphi version you're using could make a difference. Personally, I'm still using Delphi 7 for hook dlls, cause that has proven to be a very stable environment to create hook dlls. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|