If the put the code,
IntPtr ptr = Marshal.AllocCoTaskMem(4);
hr = em.Next(monikers.Length, monikers, ptr);
x = Marshal.ReadInt32(p);
// Use x below
....
....
Marshal.FreeCoTaskMem(p);
into a loop like this,
while(i < 5)
{
IntPtr ptr = Marshal.AllocCoTaskMem(4);
hr = em.Next(monikers.Length, monikers, ptr);
x = Marshal.ReadInt32(p);
// Use x below
...
...
Marshal.FreeCoTaskMem(p);
}
It would throw AccessViolation exception. Sometimes at AllocCoTaskMem();
other times at FreeCoTaskMem(). Any idea why that?
Thanks!
DH