I can't work out how to do the final assignment in C#.
If I try to just code the assignment:
fsCmd.Value_VOIDS_2=TheProgressCB;
I get "[C# Error] SDL_FileSystem.cs(116): Cannot implicitly convert
type 'SDL.TCBProgress' to 'void*'" which doesn't really surprise me.
The declarations are:
unsafe public delegate int TCBProgress( uint MaxValue,
uint NowValue,
sbyte * Message );
and fsCmd.Value_VOIDS_2 is 'void *'.
The only solution I've come up with so far seems a little silly and
that's to add a function to our DLL that takes a delegate and a void *
by reference then performs the assignment and returns. Surely there's a
way of performing that assignment using C#?
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
> I have a DLL written in C++ and I need to pass it a delegate so that it
> can call me back. The DLL has been around for a while and it takes
> commands using a structure to contain input and output data. Callbacks
> are passed to it in 'void *' pointers members.
Why don't you the type of fsCmd.Value_VOIDS_2 to be a TCBProgress
delegate instead?
A common trick is to have several different structures matching the
expected types of the fields and then overload the DLL call for each
possible type.
Another possibility which /might/ work is to either use type
information to get the _methodPtr and _methodPtrAux fields or just use
the HashCode (which currently is the same thing). Of course this is
not guaranteed to work the same in different versions of the
framework.
--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
> Why don't you the type of fsCmd.Value_VOIDS_2 to be a TCBProgress
> delegate instead?
>
I could do but traditionally we have one structure per module (which is
why the member name is so generic).
> A common trick is to have several different structures matching the
> expected types of the fields and then overload the DLL call for each
> possible type.
Yeah, makes sense.
> Another possibility which might work is to either use type
> information to get the _methodPtr and _methodPtrAux fields or just use
> the HashCode (which currently is the same thing). Of course this is
> not guaranteed to work the same in different versions of the
> framework.
Best not to do that.