AutoHotkey Community

It is currently May 25th, 2012, 2:55 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: April 26th, 2007, 8:42 pm 
Offline

Joined: January 14th, 2005, 5:30 pm
Posts: 17
Anyone have an idea why this works:

Code:
  VarSetCapacity(MidiBuf, 12)
  DllCall("RtlMoveMemory", "Str", MidiBuf, "UInt", &MIDIEVENT, "UInt", 12)


But this does not?

Code:
  VarSetCapacity(MidiBuf, 12)
  DllCall("RtlCopyMemory", "Str", MidiBuf, "UInt", &MIDIEVENT, "UInt", 12)


The only difference between the two is the first is RtlMoveMemory and the 2nd is RtlCopyMemory.

The 2nd code snippet sets errorlevel to -4, which according to the AHK help file means the function could not be found.

According to MSDN, these two functions have identical structures.

I can make do with RtlMoveMemory, but since RtlCopyMemory is faster, I would rather use that.

Thanks,
TomB


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 26th, 2007, 11:31 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
TomB wrote:
I can make do with RtlMoveMemory, but since RtlCopyMemory is faster, I would rather use that.
I doubt you will see a real difference with the DllCall overhead...
Shouldn't you indicate the DLL?
Isn't the faulty one a simple C macro?
(no time to check right now)

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2007, 12:11 am 
Offline

Joined: January 14th, 2005, 5:30 pm
Posts: 17
Thanks for the reply, PhiLho:

Quote:
Shouldn't you indicate the DLL?
Isn't the faulty one a simple C macro?


I am fairly sure that the DLL is the same for both functions - I am not sure which dll they reside in, but they are listed on MSDN as part of the Windows Kernel Run-Time Library.

http://msdn2.microsoft.com/en-us/library/ms802981.aspx

As to indicating the DLL - I would try that if I knew what dll they reside in. It shouldn't be necessary, though, since it is almost certainly one of the key dll's that AHK looks in automatically (and you don't need to indicate it for RtlMoveMemory.

TomB


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2007, 12:35 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
TomB wrote:
I am fairly sure that the DLL is the same for both functions - I am not sure which dll they reside in, but they are listed on MSDN as part of the Windows Kernel Run-Time Library.

There is no exported function like RtlCopyMemory in kernel32.dll/ntdll.dll.
So, I guess this function is exposed only to kernel-mode, not to user-mode apps.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2007, 3:21 am 
Offline

Joined: January 14th, 2005, 5:30 pm
Posts: 17
Interesting - thanks Sean.

How did you know that or figure it out? I don't see anything on MSDN that would clue someone in to that.

Tom


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2007, 4:00 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
TomB wrote:
How did you know that or figure it out? I don't see anything on MSDN that would clue someone in to that.

'Cause the linked page is on the Kernel-Mode Drivers.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2007, 9:52 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Sean wrote:
There is no exported function like RtlCopyMemory in kernel32.dll/ntdll.dll.
So, I guess this function is exposed only to kernel-mode, not to user-mode apps.
Nope, this message shows the culprit: http://forums.microsoft.com/MSDN/ShowPo ... 6&SiteID=1
Quote:
WINBASE.H:
#define CopyMemory RtlCopyMemory
#define MoveMemory RtlMoveMemory
#define ZeroMemory RtlZeroMemory

and:

WINNT.H:

#define RtlCopyMemory(dst, src, len) memcpy(dst, src, len)

As I suspected, RtlCopyMemory is a C macro, not a real DLL function.

You can try and call MSCVRT\memcpy if you want.

It seems that MSDN greatly improved their search, it doesn't show dozen of similar links on a function name, and we get the API function before the MFC or other framework wrappers.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2007, 1:52 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
PhiLho wrote:
As I suspected, RtlCopyMemory is a C macro, not a real DLL function.

Yes, but RtlMoveMemory is also an alias to memmove in C run-time library.
(Actually, there are identical functions, memcpy & memmove, in ntdll.dll too)

The point was that RtlCopyMemory is not exported while RtlMoveMemory is from kernel32.dll which is forwarded to that in ntdll.dll.

PS. I realized this: what you meant is that RtlCopyMemory is accessible from C/C++ (user-mode) apps. Right?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2007, 5:20 am 
Offline

Joined: January 14th, 2005, 5:30 pm
Posts: 17
MSVCRT\memcpy did work - thanks for the tip.

For anyone who wants to try this - note that the dll is MSVCRT, not MSCVRT.

TomB


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2007, 7:54 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Yes, sorry for the typo...
FYI, it is MicroSoft Visual C++ RunTime...

Sean wrote:
I realized this: what you meant is that RtlCopyMemory is accessible from C/C++ (user-mode) apps. Right?
Uh, no, I just didn't took time to look further, but indeed in WinNT.h, all the RtlXxxMemory are macros. But it seems that some of them has a real function counterpart, which might be just a thin wrapper.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, Google [Bot], Google Feedfetcher and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group