Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2004

Tip: Looking for answers? Try searching our database.

Passing blittable types in callback functions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken Soh - 22 Oct 2004 20:15 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.