[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

Pass through object above c-callback

Michael Sabo

2/9/2007 1:17:00 PM

Hello,

is in C# no way to realize this problem?

{
object x = new xy();
callback = new CBDelegate(callback_func);
c_call_callback(callback, ref x);
....
<wait until finished long operation>
GC.SuppressFinalize(callback);
}


private callback(ref object context)
{
if( context is xy )
{
xy x = (xy)context;
}
}


Calling the callback with type int or IntPtr is no problem, but 'ref object'
(defined as signatur in CBDelegate) occours a VARIANT exception.

Thanks
Michael


1 Answer

Michael Sabo

2/9/2007 1:42:00 PM

0

I searched a few hours for this information. But now, when I posted this
topic, I found the solution at
http://msdn.microsoft.com/msdnmag/issues/...

// lparam is IntPtr now
delegate bool EnumWindowsCB(int hwnd, IntPtr lparam);

// wrap object in GCHandle
MyClass obj = new MyClass();
GCHandle gch = GCHandle.Alloc(obj);
EnumWindowsCB cb = new EnumWindowsCB(MyEWP);
Win32.EnumWindows(cb, (IntPtr)gch);
gch.Free();
public static bool MyEWP(int hwnd, IntPtr param) {
GCHandle gch = (GCHandle)param;
MyClass c = (MyClass)gch.Target;
// ... use it
return true;
}