CodefoundryDE / LegacyWrapper

LegacyWrapper uses a x86 wrapper to call legacy dlls from a 64 bit process (or vice versa).
MIT License
79 stars 20 forks source link

Invalid pointer error for void *lp parameter #43

Open avkoli opened 1 year ago

avkoli commented 1 year ago

I used a 32 bit DLL method that has void *lp parameter. When IntPtr returned by Marshall.StructureToPtr was passed, DLL method returned invalid pointer error.

Solution is to cast structure to byte array, create a pointer in Codefoundry.LegacyWrapper32 process memory and pass this pointer to DLL method.

Process legacyWrapper32 = Process.GetProcessesByName("Codefoundry.LegacyWrapper32")[0];

IntPtr pnt = Internals.VirtualAllocEx(legacyWrapper32.Handle, IntPtr.Zero, buf.Length, Internals.AllocationType.Commit | Internals.AllocationType.Reserve, Internals.MemoryProtection.ReadWrite);