views:

260

answers:

3

I've noticed that RTL*Move*Memory seems to work just fine. But when I try to use RTL*Copy*Memory I get: "Can't find DLL entry point RtlCopyMemory in kernel32". Here is my declare:

Private Declare Sub CopyMem Lib "kernel32" Alias "RtlCopyMemory" ( _
    ByVal dest As Long, _
    ByVal source As Long, _
    ByVal bytLen As Long)
+4  A: 

RtlCopyMemory is provided inline. It is defined in winnt.h as memcpy. This means that it's not included in a Win32 DLL, it's part of the C runtime library. You could try importing memcpy from c:\windows\system32\msvcrt.dll.

Aaron Klotz
Wouldn't memcpy use _CDECL calling convention not _STDCALL? So you wouldn't be able to call it from VB6 (unless you used Matt Curland's heavy duty magic techniques)
MarkJ
+2  A: 

Why not just use RtlMoveMemory? It works just like RtlCopyMemory except that it handles overlapped memory in a different fashion.

Bruce McKinney pioneered the use of RtlMoveMemory over 10 years ago and it's been standard for VB6 memory copying ever since.

MarkJ
Because according to MS RtlCopyMemory performs faster, so I wanted to test the difference.
Oorang
Interesting. Do you have a declaration for `memcpy` you could share with us? What were the speed results?
MarkJ
Not yet, that was what I was working from: msdn.microsoft.com/en-us/library/… and if you google "declare sub RtlCopyMemory" you get an few hits. But it wasn't working so I thought I would just try to verify if should be working:)
Oorang
Note: Dependency walker can't find an entry for RtlCopyMemory in Kernel32.
Oorang
A: 

I know this is an old question, but I had the same problem, so I thought I could answer.

RtlCopyMemory in kernel32.dll should be an Export Forward into ntdll, but somehow guys at MS missed that one on x64 version of Vista (dunno how it's on x86) (see below).

You can try importing it directly from ntdll, if it's only for your needs.

EDIT: the method I mean is not exported, but with Symbols it's visible in ntdll as RtlCopyMemoryNonTemporal

EDIT2: Just to be sure I've checked some things, here's summary:

  • both RtlCopyMemory and RtlCopyMemoryNonTemporal are exported from ntdll.dll in x64 Vista's (plain, SP1, SP2)
  • there is export forward for RtlCopyMemory in kernel32.dll in x64 Vista's
  • there is unexported RtlCopyMemoryNonTemporal in ntdll.dll in x86 Vista's

So it all should be if you're writing x64 application.

P.S. I was wrong about x64 vs x86, because I was compiling x86 app, and running it on x64 (WOW mode), so it used 32-bit version of kernel32, ntdll and not the x64 one.

GiM