Cool. Now, how would you turn this delegate over to a COM object? How would you actually make the interface in a COM object to turn over a delegate?
Regards Thomas Tomiczek THONA Consulting Ltd. (Microsoft MVP C#/.NET) -----Original Message----- From: Chris M. Szurgot [mailto:[EMAIL PROTECTED]] Sent: Dienstag, 23. April 2002 15:06 To: [EMAIL PROTECTED] Subject: Re: [DOTNET] Callback? Possibble from C#? Yes, it is possible (and quite easy too...) Create the delegate callback to be as close to the expected function, and then put that delegate into the [DllImport] for the unmanaged code. Then, when you call it, it should work fine. Below is the pertinent code for using CopyFileEx, since that's the one I have handy. Chris -------------------------------------------------------------------- public delegate int ProgressCallback( long totalSize, long totalTransfered, long streamSize, long streamTransfered, int streamNumber, int callbackReason, IntPtr hSourceFile, IntPtr hDestFile, IntPtr data); [DllImport("Kernel32.dll")] public static extern bool CopyFileEx(String existingFileName, String newFileName, ProgressCallback callback, IntPtr callbackData, bool cancel, int copyFlags); CopyFileEx(fromFile, toFile, new ProgressCallback(Progress), IntPtr.Zero, false, COPY_FILE_RESTARTABLE); -------------------------------------------------------------------- -----Original Message----- From: Thomas Tomiczek [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 23, 2002 8:37 AM To: [EMAIL PROTECTED] Subject: [DOTNET] Callback? Possibble from C#? Hello, I have an API (C style, DLL based) that requires me to register a callback. The DLL has a function where as one parameter it either gets a pointer to the function to call or NULL. Can I somehow pass a delegate in there? Any samples around? Regards Thomas Tomiczek THONA Consulting Ltd. (Microsoft MVP C#/.NET) You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.