1

I'd like to compare the memory at 2 addresses for equality. I've seen people use this:

Private Declare Function RtlCompareMemory Lib "ntdll" ( _
    ByRef Source1 As Any, _
    ByRef Source2 As Any, _
    ByVal Length As Long _
) As Long

However when I tried it gives a Bad Dll Calling convention error, which often means this function uses something other than stdcall. However these forum posts 1,2 suggest people have been using the API for VB6 applications successfully.

Has something changed in the calling convention used in some ntdll functions since that post in 2005 and can anyone suggest a workaround? I'm looking for something widely available across many VBA distributions.

Greedo
  • 4,967
  • 2
  • 30
  • 78
  • Calling convention has, of course, not changed. Your problem is something else I guess. – David Heffernan Jul 31 '20 at 12:27
  • @DavidHeffernan I only mentioned because one of the threads I linked says _`"Weird thing is, from MSDN October 2002, RTLCompareMemory() is only included in Win2K and XP"`_, but goes on to provide some benchmarks showing it's still there and working. So I'm really stumped - the calling convention I think is defined by `NTSYSAPI`, but I don't know enough C++ to work out what that expands to – Greedo Jul 31 '20 at 15:02
  • It is `stdcall` still – David Heffernan Jul 31 '20 at 15:14
  • Greedo, please post the code that is calling this function. – tcarvin Jul 31 '20 at 15:34
  • 1
    [Here](https://github.com/tannerhelland/VB6-Compression/blob/master/VB_Hacks.bas#L35) is a correct declaration for the API function. Search below in the same code for sample usage. – wqw Aug 02 '20 at 13:32
  • Hi, @Greedo did you solve this issue? I can get it work with 2 `String`s with `PtrSafe` keyword in the Declare statement. If this didn't solve it, could you provide a [mcve](https://stackoverflow.com/help/minimal-reproducible-example)? – Drake Wu Aug 05 '20 at 06:29

0 Answers0