madshi.net Forum Index madshi.net
high quality low level programming
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Several Questions with madCodeHook

 
Post new topic   Reply to topic    madshi.net Forum Index -> madCodeHook
View previous topic :: View next topic  
Author Message
Davita



Joined: 13 Sep 2005
Posts: 106

PostPosted: Sun Feb 22, 2009 4:41 pm    Post subject: Several Questions with madCodeHook Reply with quote

Hello

Again I need your support guys, thanks in advance smile

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? sad 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
View user's profile Send private message
dcsoft



Joined: 11 Dec 2004
Posts: 353
Location: San Francisco Bay Area, CA USA

PostPosted: Mon Feb 23, 2009 4:40 am    Post subject: Don't use string Reply with quote

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
View user's profile Send private message Visit poster's website
Davita



Joined: 13 Sep 2005
Posts: 106

PostPosted: Mon Feb 23, 2009 5:11 am    Post subject: Reply with quote

wow. You can't imagine how you helped me. many many thanks smile

what about second question? very happy
Back to top
View user's profile Send private message
dcsoft



Joined: 11 Dec 2004
Posts: 353
Location: San Francisco Bay Area, CA USA

PostPosted: Mon Feb 23, 2009 4:08 pm    Post subject: Reply with quote

Glad it worked for you! I'm no Delphi expert by any means but recently had to struggle through this same issue. wink

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
View user's profile Send private message Visit poster's website
Davita



Joined: 13 Sep 2005
Posts: 106

PostPosted: Tue Feb 24, 2009 8:17 pm    Post subject: Reply with quote

Thank you very much for your help smile
Back to top
View user's profile Send private message
madshi
Site Admin


Joined: 21 Mar 2004
Posts: 5908

PostPosted: Wed Feb 25, 2009 10:32 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    madshi.net Forum Index -> madCodeHook All times are GMT
Page 1 of 1

 
Jump to:  
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