Article View: borland.public.csharpbuilder.language.csharp
Article #162Passing a delegate to a DLL as a 'void *'
From: Andrue Cope [TeamB]
Date: Mon, 18 Sep 2006 09:43
Date: Mon, 18 Sep 2006 09:43
30 lines
2034 bytes
2034 bytes
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.
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
Technical Details
Message-ID:
<450e6a4a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.news2me.com!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,497a94e42bdc0848,start X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Andrue Cope [TeamB]" <no.spam@not.a.valid.address> Subject: Passing a delegate to a DLL as a 'void *' Newsgroups: borland.public.csharpbuilder.language.csharp User-Agent: XanaNews/1.18.1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 217.207.223.34 Message-ID: <450e6a4a$1@newsgroups.borland.com> Date: 18 Sep 2006 02:43:38 -0700 X-Trace: newsgroups.borland.com 1158572618 217.207.223.34 (18 Sep 2006 02:43:38 -0700) Lines: 30 X-Authenticated-User: acope Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.news2me.com!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail