Click here to Skip to main content
15,392,679 members
Articles / Programming Languages / C#
Posted 26 Jan 2007


84 bookmarked

A wrapper for the canon CDSDK and PRSDK for remote capture

Rate me:
Please Sign up or sign in to vote.
4.94/5 (31 votes)
18 May 20075 min read
A wrapper to allow remote capture of images with Canon cameras in C#

The Canon capture sample app


Both Benjamin and I have been working with digital cameras for some time now. Of the few manufacturers that support remote capture, Canon has the best feature set. Unfortunately, the Canon SDK does not contain examples in C#, it is C++ only. Elias Torres is well known for his CDSDK wrapper, which I've used with much success. However, newer cameras are not supported by the CDSDK. Most new Canon cameras use the PRSDK. Our C# library (based on the C++ SDK samples and the Elias Torres wrapper) encapsulates Canon's CDSDK and PRSDK.


Having written a number of CP articles, I know that we'll be asked this no matter what, but here goes. This is a wrapper of an existing SDK. It won't work without the SDK, or at least the DLLs that come with the SDK. In fact, there are two SDKs involved, although I hope to add a PRSDK-only mode at some point, given that no cameras on sale today work with the CDSDK. We can't give you the DLLs - Canon requires that you register with them to obtain a license. Elias' forum is full of 'please send me the SDK' requests. Please don't ask. We'd love to help you, but we will not disrespect software copyrights.

Sample program

The sample program simply attempts to connect to a Canon camera, enumerate some settings and allows you to show a preview and take pictures. More than the Canon sample does, and more in line with the feature set I'd imagine most people would be looking for. If you work through the sample, you'll see how to query the camera for it's settings, how to take pictures, etc.


The PRSDK and the CDSDK each define their own enums for settings, but these settings often overlap. In order to make things strongly typed, where the PRSDK contains all the values in the CDSDK, I've used the PRSDK enum as the property to get available settings, and to set a value. I did this as the CDSDK will not change, but the PRSDK may add new values. Where there are values in the CDSDK and not the PRSDK, you can use the enums, but the actual properties just take int, so as to not offer properties that are not available.

PRSDK and shooting modes

One thing I've discovered, neither my A620 or my A640 will change shooting mode with the PRSDK, it accepts the setting and ignores it. I think this is a bug in the SDK, I've written to Canon about it and will update the wrapper if I get a fix. In the meantime, I added an IsPRSDK property on the camera, so if the camera connects via the PRSDK and you need an effect such as grayscale, you can post process the images.

I have got a reply from Canon - the sequence went something like this:

Me: I don't think setting the PhotoEffect works in the PRSDK

Canon: Try reading the manual

Me: Thanks, I did, and I've done what it says, but I can't set grayscale. Does it work for you?

Canon: You can set the camera to grayscale manually, then connect. We've tested, and that works here.

Me: Will the camera remember this setting when powered off?

Canon: No. Thank you for developing software for Canon cameras.

I assume that this means the SDK is definately broken in this regard. I also found that trying to set the PhotoMode meant that when I set ExposureCompensation afterwards, I'd get an AccessDenied error, so I use the IsPRSDK method to make sure I don't try to set this property on a newer camera.


The background to this wrapper is an interesting story. I wrote a wrapper for the PRSDK only, mainly in C++/CLI (so, no pinvoke, pretty much the opposite of how this wrapper works). I coded it for my specific application, not as broadly as this one is written. I wrote a test app and it worked fine. I integrated the DLL into my app, and it kept throwing a WMI error. It was at this point that I met Benjamin, who had also written a wrapper based on Elias' work.

Benjamin's wrapper used pinvoke and was C# only. Building on his code, I made several improvements - added some properties, fixed a few bugs and made some of the existing properties strongly typed. I wrote the included sample app while improving on the wrapper - everything worked. To my surprise, when I added the wrapper to my program, I immediately got WMI errors! After wrestling with the problem, I found that the SDK doesn't like being run from a thread, but a thread inside the DLL appears to work fine. Due to this limitation, I added the ability to do time-intensive things like camera enumeration, camera connection and image acquisition in another thread within the library. Events provide hooks for tracking when these threads end. This leads to code like this:

public Form1()

    lblPath.Text = Application.StartupPath;

    brightnessValues = new List<int />();
    exposureModesList = new Dictionary<string, int>();

    camera = new Camera();
    camera.Connected += new Camera.ConnectionEventHandler(camera_Connected);
    camera.ReceivedFrame += new Camera.ReceivedFrameEventHandler(
    camera.DevicesEnumerated += new Camera.DeviceNamesEnumeratedEvent(
    camera.ImageAcquired += new Camera.ImageAcquiredEventHandler(

private void btnConnect_Click(object sender, EventArgs e)

private void camera_DevicesEnumerated(object sender, DeviceListEventArgs e)
    cboDevices.DataSource = e.DeviceNames;

In this code, the GetDevices call returns right away, and the list of devices connected is passed to the camera_DevicesEnumerated delegate function. Custom event args are provided for connection, recieving of a frame (which is the preview) and acquiring an image.

Points of Interest

Getting this to work with both SDKs was interesting, mostly due to bugs in the newer SDK. I also tested under Vista, and found the PRSDK doesn't work under Vista (at least it didn't for me). The older SDK works with Vista. I have found that a lot of issues I had, were caused by calling APIs that are broken in the PRSDK, which would kill the SDK for other things. However, I couldn't get the PRSDK to connect in Vista, with either my commercial app, or the demo that comes with this sample (the demo was in general more reliable, as it does less, it never breaks the SDK ).

Community involvement

This wrapper has had input from two people (the article authors), and is to be considered a work in progress. I'd love to spend some time making more of the properties typesafe, for example. So, if you use it, and you find that you improve it, let us know so we can keep improving the wrapper for the benefit of all who use it.


  • Released version 1.0


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Authors

Christian Graus
Software Developer (Senior)
Australia Australia
Programming computers ( self taught ) since about 1984 when I bought my first Apple ][. Was working on a GUI library to interface Win32 to Python, and writing graphics filters in my spare time, and then building n-tiered apps using asp, atl and in my job at Dytech. After 4 years there, I've started working from home, at first for Code Project and now for a vet telemedicine company. I owned part of a company that sells client education software in the vet market, but we sold that and I worked for the owners for five years before leaving to get away from the travel, and spend more time with my family. I now work for a company here in Hobart, doing all sorts of Microsoft based stuff in C++ and C#, with a lot of T-SQL in the mix.

Benjamin Liedblad
Software Developer (Senior)
United States United States
No Biography provided

Comments and Discussions

QuestionPRSDK get AV and TV values Pin
Member 351717914-Mar-17 6:05
MemberMember 351717914-Mar-17 6:05 
Questionthanks a lot Pin
dreka2115-Jan-16 14:31
Memberdreka2115-Jan-16 14:31 
Questionno download? Pin
modderxp17-May-14 8:08
Membermodderxp17-May-14 8:08 
AnswerRe: no download? Pin
Christian Graus17-May-14 13:59
mveChristian Graus17-May-14 13:59 
GeneralRe: no download? Pin
modderxp19-May-14 1:10
Membermodderxp19-May-14 1:10 
GeneralRe: no download? Pin
Christian Graus19-May-14 13:03
mveChristian Graus19-May-14 13:03 
GeneralRe: no download? Pin
Christian Graus19-May-14 15:38
mveChristian Graus19-May-14 15:38 
GeneralRe: no download? Pin
modderxp20-May-14 3:20
Membermodderxp20-May-14 3:20 
QuestionCDSDK on Windows 7 Pin
jamagboo18-Dec-13 15:01
Memberjamagboo18-Dec-13 15:01 
AnswerRe: CDSDK on Windows 7 Pin
Christian Graus18-Dec-13 15:08
mveChristian Graus18-Dec-13 15:08 
GeneralRe: CDSDK on Windows 7 Pin
jamagboo18-Dec-13 15:11
Memberjamagboo18-Dec-13 15:11 
GeneralRe: CDSDK on Windows 7 Pin
Christian Graus18-Dec-13 15:15
mveChristian Graus18-Dec-13 15:15 
GeneralRe: CDSDK on Windows 7 Pin
jamagboo18-Dec-13 15:18
Memberjamagboo18-Dec-13 15:18 
AnswerRe: CDSDK on Windows 7 Pin
Christian Graus18-Dec-13 15:09
mveChristian Graus18-Dec-13 15:09 
QuestionI'm getting an erorr after adding the CDSDK.dll file error: CDStartsSDK C000060 what is that ? Pin
chocolade2-May-13 10:38
Memberchocolade2-May-13 10:38 
AnswerRe: I'm getting an erorr after adding the CDSDK.dll file error: CDStartsSDK C000060 what is that ? Pin
Christian Graus18-Dec-13 15:09
mveChristian Graus18-Dec-13 15:09 
QuestionPRSDK Focus Pin
Member 912459425-Oct-12 1:25
MemberMember 912459425-Oct-12 1:25 
AnswerRe: PRSDK Focus Pin
Christian Graus25-Oct-12 7:43
mveChristian Graus25-Oct-12 7:43 
GeneralRe: PRSDK Focus Pin
Member 912459425-Oct-12 22:13
MemberMember 912459425-Oct-12 22:13 
GeneralRe: PRSDK Focus Pin
weltklasse14-Feb-13 6:16
Memberweltklasse14-Feb-13 6:16 
GeneralRe: PRSDK Focus Pin
Christian Graus14-Feb-13 7:37
mveChristian Graus14-Feb-13 7:37 
GeneralRe: PRSDK Focus Pin
weltklasse14-Feb-13 7:53
Memberweltklasse14-Feb-13 7:53 
AnswerRe: PRSDK Focus Pin
Benjamin Liedblad12-Feb-14 6:03
MemberBenjamin Liedblad12-Feb-14 6:03 
QuestionIssue with multiple cameras Pin
Ryan Emmett20-Aug-12 8:08
MemberRyan Emmett20-Aug-12 8:08 
AnswerRe: Issue with multiple cameras Pin
Christian Graus20-Aug-12 8:17
mveChristian Graus20-Aug-12 8:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.