Deadly Delegates

Hi

No idea where I should post this, my problem involves MSSCCI Intergration, C#, PInvokes and Function Pointers. Basically I am trying to create an application that uses the existing MSSCCI plugins out there. I have hit many problems along the way, but may latest involves function pointers.

I am in C#, so I am using PInvoke to call to the MSSCCI dlls, for example:

[DllImport(@"C:\Program Files\Microsoft Visual Studio\Common\VSS\win32\SSSCC.DLL")]
public static extern int SccGetVersion();

[DllImport(@"C:\Program Files\Microsoft Visual Studio\Common\VSS\win32\SSSCC.DLL")]
public static extern int SccCheckout(IntPtr ppContext, IntPtr hWnd, int nFiles, IntPtr[] lpFileNames, string lpComment, int fOptions, IntPtr pvOptions);

etc...

Now some of these dll functions require me to pass in a function pointer, for example SccPopulateList. I am using delegates to pass this in as follows:


[DllImport(strMSSCCIDll)]
public static extern int SccPopulateList(IntPtr ppContext, int nCommand, int nFiles, IntPtr[] lpFileNames, rageVersionControl.POPLISTFUNCDelegate pfnPopulate, IntPtr pvCallerData, ref int lpStatus, int fOptions);

public static bool POPLISTFUNC(IntPtr pvCallerData, bool bAddRemove, int nStatus, StringBuilder lpFileName)
{
Console.WriteLine("POPLISTFUNC("+ pvCallerData +", "+ bAddRemove +", "+ nStatus +", "+ lpFileName.ToString() +")");
return true;
}

/// <summary>
/// Delegate for the POPLISTFUNC method
/// </summary>
public delegate bool POPLISTFUNCDelegate(IntPtr pvCallerData, bool bAddRemove, int nStatus, StringBuilder lpFileName);


...code...
SccPopulateList(m_ppContext, (int)iCommand, nFiles, lpFileNames, new POPLISTFUNCDelegate(POPLISTFUNC), pvCallerData, ref nStatus, fOptions);
...more code...

My problem is my delegate function DOES get called, but only once and then an exception occurs within the black box of the MSSCCI dll saying it is referencing protected memory. This obviously could be anything, but I have found it happens with all of the calls to MSSCCI functions that require function callbacks so it must me something going on with the delegates. It is as if all the delegates are being killed after their first use, somehow.

Anyone have any ideas This stuff is driving me mad.

Thanks
Kevin


Answer this question

Deadly Delegates

  • Deadly Delegates