Page 1 of 1

CopyFunction fails with memory access exception on x64

PostPosted: Mon Dec 24, 2012 5:21 pm
by wassily
As the subject says, my attempt to copy functions in x64 builds fail while everything works perfect for x86 builds. I use VC++ 2010 compiler and the copied functions are (mostly) simple thunks like
Code: Select all
STDMETHODIMP DropTargetProxy_DragLeave(IDropTargetProxy *self)
{
    return self->DropTarget->DragLeave();
}

It is necessary to set "acceptUnknownTargets" to true for such code, and I want copy inside of the current process so the call looks like
Code: Select all
   PVOID copy = CopyFunction(DropTargetProxy_DragLeave, NULL, TRUE);

Stepping into the implemention with the built in debugger shows that my function is copied just fine but after calling VirtualProtectEx(copyBuffer, ...) CopyFunction tries to write a value by pointer equal to 1 (ProcessMemory[1] = value), and naturally everything breaks

Re: CopyFunction fails with memory access exception on x64

PostPosted: Wed Jan 09, 2013 6:16 pm
by madshi
Hello,

and sorry for the late reply. Would it be possible for you to create a (very) small test project with which I could reproduce the issue? That would help a lot!