开发者

What is the equivalent C# code for this Canon SDK C++ code snippet?

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;
    }


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


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++).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜