Hi all,
I'm having problems passing a blittable type (bool) from unmanaged C++ code
to a managed callback function.
I have an unmanaged C callback function declared as follows:
typedef int __stdcall PostProcFileCallback(void *pData, LPCTSTR pszFilename,
bool bSkipped);
and some code that calls is, passing a boolean bSkipped value to the
assigned callback function:
. . .
bool bSkipped = false;
. . .
if (m_pPostProcFileCB && nCode != AT_ABORT)
nCode = m_pPostProcFileCB(m_pPostProcFileData, pszFilePath, bSkipped);
. . .
I have an associated C# delegate registered as the callback function. The
delegate is prototyped as below:
public delegate int PostProcFileCallback(IntPtr pData, string pszFilename,
ref bool bSkipped);
and the callback method is defined below:
protected int OnPostProcFile(IntPtr pData, string pszFilename, bool bSkipped)
{
. . .
if (!bSkipped) { . . . }
. . .
}
What I'm seeing is when my delegated callback method is invoked, the
bSkipped parameter is always true even when a false value is passed as the
bSkipped parameter in the unmanaged callback function invocation.
Any help would be greatly appreciated. Thanks!
Ken Soh - 22 Oct 2004 20:35 GMT
Made a typo. The delegate is actually declared as
public delegate int PostProcFileCallback(IntPtr pData, string pszFilename,
bool bSkipped);
I did try declaring the bSkipped parameter as ref bool, instead of bool, but
that did not resolve my problem.
Thanks,
Ken
> Hi all,
>
[quoted text clipped - 37 lines]
>
> Any help would be greatly appreciated. Thanks!
Robert Jordan - 23 Oct 2004 14:03 GMT
Hi Ken,
> I'm having problems passing a blittable type (bool) from unmanaged C++ code
> to a managed callback function.
[quoted text clipped - 3 lines]
> typedef int __stdcall PostProcFileCallback(void *pData, LPCTSTR pszFilename,
> bool bSkipped);
The C++ bool type is one byte large. You should try this:
public delegate int PostProcFileCallback(IntPtr pData, string
pszFilename, byte bSkipped);
bye
Rob