UnmanagedFunctionPointer call generates an AccessViolation on vista
Posted on 2009-05-19
Hi, I have a problem of something that works perfectly on xp, but not on vista. This make me think it might be related to some vista security features that xp does not have, but I couldn't seem to be able to find any relevant info on the net.
I declare the delegate as follow:
private unsafe delegate WFuncList** fnInitializeModule(void* lpPtr2Table);
WFuncList being a struct:
[StructLayout(LayoutKind.Explicit, Size = 0x10)]
private struct WFuncList
public int fpGenerateKeys;
public int fpUnload;//0x04
public int fpHandler;
public int fpTick;
I call it as follow:
fnInitializeModule init = (fnInitializeModule)Marshal.GetDelegateForFunctionPointer(new IntPtr(pInit + module), typeof(fnInitializeModule));
WFuncList** ppWFuncList = init(ppFuncList);
The last line throws and access violation on vista, and works perfectly fine on XP. I came across a post on a forum with someone having a similar issue, they said that it was probably due to the external module trying to allocate data in a pointer that was passed from managed code, and generating an exception.
Anyone experienced similar behavior on vista and found a solution?