此Canon SDK C ++代码段的等效C#代码是什么?

时间:2010-09-23 15:48:53

标签: c# c++ visual-c++

这个C ++代码的C#等价物是什么?

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 个答案:

答案 0 :(得分:4)

在行之间阅读 - 有一个用于Canon SDK here和另一个here

的.Net 2.0包装器(包括源代码)

答案 1 :(得分:2)

这是一个粗略翻译,仅用于说明目的:

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已更改为void,因为我们在C#中使用例外而不是错误代码; EDSCALLBACK定义为__stdcall,这与此无关;代码仅当存在所有隐含的类和方法时才有效;惯用的C#将使用event / EventHandler< T> / EventArgs而不是“NotifyObservers”方法;我假设您不希望与C ++进行任何互操作)。