![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hi Paul, I've carefully reviewed your question but I'm still unclear about some points: 1) Is the legacy product a standalone application or a DLL? 2) Is your to-be-written Win32 API reside in the same module as the legacy product or a separate DLL? Without these information, I'm not sure if your objective here can be achieved using the approach like how we use P/Invoke to call Win32 API that requires a callback, such as EnumWindows: http://www.pinvoke.net/default.aspx/...umWindows.html Regards, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Hi Paul, Sorry for asking you for more information again, but I'm not sure if I've fully understood the question. Per your initial message, you said you need to callback into the *unmanaged* code; however, since the .NET code is the caller, the unmanaged code is in a DLL, then I think this is not *callback* into unmanaged, it's actually .NET *calls* unmanaged code. If this is the case, then I think you don't need to define a delegate in .NET: you simply use P/Invoke to call the win32 API FileTransfer_Transfer. (If you do use a delegate in FileTransfer.Transfer, then you simply create a .NET function with the signature of the delegate and calls the API in this function). However, in this case, I'm not sure how you will make sure the class in C++ DLL get instantiated? On the other hand, if you need to callback into *managed* code from unmanaged code, then you may find following article useful: #David Notario's WebLog : Gotchas with Reverse Pinvoke (unmanaged to managed code callbacks) http://blogs.msdn.com/davidnotario/a...13/512436.aspx I really hope I haven't misunderstood anything. If I do, please feel free to correct me and tell me more about your application. Thanks. Regards, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
Hi Paul, Thank you for your waiting. So the key issue here is how to call a function pointer returned from unmanaged code in C#, right? I've spent much time on this but unfortunately it turns out it's not possible in C# to cast the function pointer into a delegate and call it from managed code. A workaround is to pass the function pointer (of IntPtr data type in C#) to the Win32 API wrapper DLL and let it call the function instead. I've also found a related example on this issue and with the above workaround: #Enumerate and Host Control Panel Applets using C#. - The Code Project - C# Programming http://www.codeproject.com/csharp/appletengine.asp Hope this helps. Please feel free to let me know if there's anything else I can help. Regards, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
Walter Wang [MSFT] wrote: I've spent much time on this but unfortunately it turns out it's not possible in C# to cast the function pointer into a delegate and call it from managed code. What's wrong with Marshal.GetDelegateForFunctionPointer (.NET 2.0)? |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |