Invalid callback object instance



I have a COM library written in C++. For asynchronous operations I use
a callback interface to notify the application of completions. Here's
the interface definition:

interface ICallback : IUnknown
{
HRESULT Execute(IUnknown* caller, DWORD data);
}

It's pretty standard from what I can tell. You pass in an object that
implements ICallback and the Execute method of that object is called
when the operation completes. The object that calls Execute passes a
pointer to itself (this) back via the first parameter, and a result
code via the second.

This all works great so long as the application is written in C++. I'm
having a problem with a sample app I wrote in C#, however. The object
I receive as the first parameter (caller) is not valid. The debugger
shows that it has the correct type, but if you try to access it you
wind up with invalid cast exceptions. Here's the shell of the Execute
method in my C# callback:

public void Execute(object caller, uint Data)
{
// caller has the right type, but it is not a valid object
}

Any ideas about what may be going on here? As far as I can tell, this
is the only place I'm having this kind of problem. Everything else in
the library works fine, and I'm creating, returning, and passing
various objects all over the place. It's just this one place.

I also wrote the same app in VB.NET, and got the exact same exceptions.

.



Relevant Pages

  • Re: [PATCH 1/7] async: Asynchronous function calls to speed up kernel boot
    ... called within the caller's context. ... Hence this interface cannot be used to call might-sleep functions from ... will need to pass in the memory for the administration. ... If the callback function can sleep then the caller must be able to ...
    (Linux-Kernel)
  • Re: aspnet_wp.exe and COM+
    ... For releasing the interface i am not sure what you mean by, ... Such components do run "in-process", that means they run in the security context of the caller, so here the caller is allowed to call LogonUser(which I suppose you do in your Impersonate method) and the CreateEventEmailFolder Method doesn't need distributed transaction services either. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [UPDATE PATCH] push rounding up of relative request to schedule_timeout()
    ... >>sleeps probably need to use a different interface. ... > Adding 1 is easy enough for the caller and even easier to explain in the ... > instructions (i.e. this call sleeps for X jiffies edges). ... Lots of drivers basically do something like ...
    (Linux-Kernel)
  • Re: Why Thread-Safe VB6 ActiveX when it is single threaded?
    ... > When VisualBasic calls RaiseEvent() .. ... event sink is a wrong mechanism. ... should pass the callback interface as part of the job parameters: ... method on the callback interface when done. ...
    (microsoft.public.win32.programmer.ole)
  • Re: [Lit.] Buffer overruns
    ... interface to getsays that it is the caller's responsibility to supply ... receive an exception if the index is out of bounds. ... You raised a concern that the caller might be "aborted". ... I do not know why you call it irresponsible programming. ...
    (sci.crypt)