Re: Cast between a function pointer and IntPtr
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Thu, 19 Jan 2006 14:04:56 +0100
Not sure what you mean with inter-process, and why you use unsafe
declarations of your delegates. Are you trying to:
1. use a function pointer to callback from another process, or
2. from the same process but from unmanged code, or
3. from the same process using managed code?
1. isnt possible, but I suppose you know that
2. you need to pass the delegate to unmanaged using a PInvoke declaration
3. not sure why would you use a delegate??
Willy.
"Abra" <nospam@xxxxxxxxxx> wrote in message
news:O0rQX7OHGHA.3120@xxxxxxxxxxxxxxxxxxxxxxx
|I have an application where I need to send a inter-process message (a
| data stream) that contains among other the address of a function (member
| of a class).
| For that, I need to serialize it, so I tried to cast it to an IntPtr,
| but without success. And of course, on the receiever side, I need to
| cast it back from IntPtr to the function pointer, in order to be able to
| perform the callback function call, but this doesn't work either.
| How could the needed casts be implemented ?
| Here is a sample of my code :
|
| On the sender side :
|
| ...
| unsafe public delegate bool MY_FPTR(int param1, int param2);
|
| class test {
|
| ...
|
| unsafe public bool functie_test(int param1, int param2)
| {
| ....
| }
|
| some_function()
| {
| MY_FPTR myFPtr = new MY_FPTR(test_function);
|
| -> this line does not compile !
| IntPtr myIntFPtr = (IntPtr)myFPtr;
|
| ..
|
| }
| ..
| }
|
| On the receiver side is similar :
|
| someReceiverFunction()
| {
|
| IntPtr callbackIntPtr = ...;
|
| -> this line does not compile either !
| MY_FPTR myCallbackPtr = (MY_FPTR)callbackIntPtr;
| ..
| }
|
| Thanks in advance for your help.
|
| *** Sent via Developersdex http://www.developersdex.com ***
.
- Follow-Ups:
- References:
- Cast between a function pointer and IntPtr
- From: Abra
- Cast between a function pointer and IntPtr
- Prev by Date: Re: getting client ip in sock-client on server
- Next by Date: Re: environment
- Previous by thread: Re: Cast between a function pointer and IntPtr
- Next by thread: Re: Cast between a function pointer and IntPtr
- Index(es):
Relevant Pages
|