EDSDK Live view problems using canon example

603 views Asked by At

I need to make a function for live view image in canon camera, but when I try to use the example code provided from canon I got some errors in variables. So I modified the code so that it could work. But the function EDSDK.EdsGetPropertyData returns the error code 98 (in hex 62) which represents the error EDS_ERR_INVALID_POINTER. I would like to know what is wrong in my code, and how can I proceed it.

IntPtr outData;
    public void startLiveview(IntPtr camera)
    {
       
        uint err = EDSDK.EDS_ERR_OK;
        EDSDK.EdsDataType device = new EDSDK.EdsDataType();
        int size;
        EDSDK.EdsOpenSession(camera);
        // Get the output device for the live view image EdsUInt32 device; err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice,  0 ,  , sizeof(device), &device ); 

        // PC live view starts by setting the PC as the output device for the live view image. if(err == EDS_ERR_OK) {  device |= kEdsEvfOutputDevice_PC; 
        err = EDSDK.EdsGetPropertySize(camera, EDSDK.PropID_Evf_OutputDevice, 0,out device, out size);
        MessageBox.Show("Error result:"+err.ToString());
        MessageBox.Show(device.ToString());
        MessageBox.Show(size.ToString());
        err = EDSDK.EdsGetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, size, outData);
        MessageBox.Show(outData.ToString());
        if (err == EDSDK.EDS_ERR_OK)
        {
            //type2.GetType();
            //device |= EDSDK.PropID_Evf_OutputDevice;

            // err = EDSDK.EdsSetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, sizeof(device), &device);
        }
        else
        {
            MessageBox.Show("Error result:" + err.ToString());
        }

        EDSDK.EdsCloseSession(camera);
    }
1

There are 1 answers

8
Johannes Bildstein On

EdsGetPropertyData expects the outData pointer to have a value but you are passing a zero pointer.

You need to allocate memory first and then call EdsGetPropertyData, i.e. something like this:

outData = System.Runtime.InteropServices.Marshal.AllocHGlobal(size);
err = EDSDK.EdsGetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, size, outData);

Once you are done, you must release that allocated memory or you'll have a memory leak:

System.Runtime.InteropServices.Marshal.FreeHGlobal(outData);

In the C# examples of the Canon SDK (since version 13.x, I believe) you should find methods that already implement EdsGetPropertyData methods for several data types. Why not use those instead of writing it yourself?