tags:

views:

141

answers:

2

What is the C# equivalent of this C++ code?

private:
    static EdsError EDSCALLBACK ProgressFunc (
                        EdsUInt32   inPercent,
                        EdsVoid *   inContext,
                        EdsBool *   outCancel
                        )
    {
        Command *command = (Command *)inContext;
        CameraEvent e("ProgressReport", &inPercent);
        command->getCameraModel()->notifyObservers(&e);
        return EDS_ERR_OK;
    }
+2  A: 

This is a rough translation for illustration purposes:

private static void ProgressFunc(uint percent, object context, out bool cancel)
{
    Command command = (Command)context;
    CameraEvent e = new CameraEvent("ProgressReport", percent);
    command.GetCameraModel().NotifyObservers(e);
    cancel = false;
}

(EdsError has been changed to void, because we use exceptions in C# instead of error codes; EDSCALLBACK is defined as __stdcall which is irrelevant here; the code only works if all implied classes and methods exist; idiomatic C# would be the use of event/EventHandler<T>/EventArgs instead of a "NotifyObservers" method; I assume you don't want to do any interop with C++).

dtb
We use exceptions in C++ too. That looks like COM to me or a similar interop API - nobody would use a void* without a seriously good reason.
DeadMG
Indeed, just illustrative. The odds that this will work are zero.
Hans Passant
+3  A: 

Reading between the lines - there is a.Net 2.0 wrapper (including source code) for the Canon SDK here and another here

Steve Townsend