 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
TomB
Joined: 14 Jan 2005 Posts: 17
|
Posted: Thu Apr 26, 2007 7:42 pm Post subject: Can't call RtlCopyMemory? |
|
|
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 |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Thu Apr 26, 2007 10:31 pm Post subject: Re: Can't call RtlCopyMemory? |
|
|
| 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) _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
TomB
Joined: 14 Jan 2005 Posts: 17
|
Posted: Thu Apr 26, 2007 11:11 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Thu Apr 26, 2007 11:35 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
TomB
Joined: 14 Jan 2005 Posts: 17
|
Posted: Fri Apr 27, 2007 2:21 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Fri Apr 27, 2007 3:00 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Fri Apr 27, 2007 8:52 am Post subject: |
|
|
| 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/ShowPost.aspx?PostID=330716&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. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Fri Apr 27, 2007 12:52 pm Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
TomB
Joined: 14 Jan 2005 Posts: 17
|
Posted: Sat Apr 28, 2007 4:20 am Post subject: |
|
|
MSVCRT\memcpy did work - thanks for the tip.
For anyone who wants to try this - note that the dll is MSVCRT, not MSCVRT.
TomB |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Sat Apr 28, 2007 6:54 am Post subject: |
|
|
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. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|