Go Back   Steve's Digicams Forums >

LinkBack Thread Tools Search this Thread
Old Mar 2, 2005, 1:53 PM   #1
Junior Member
Join Date: Mar 2005
Posts: 2

I downloaded the Canon SDK Version 7.1 and tried to migrate the "RELCTRL" sample to C# (with PInvoke). Almost everything is working except the following callback function that should receive the image data from the camera. I´m always getting the sameerror:

An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module.

Additional information: Object reference not set to an instance of an object.

This error shows up after the callback functions has been called 6 times. Unfortunatley I don´t know why this happens and how I can solve the problem.
/* The function which receives the picture from a camera */
UInt32 ViewFinderCallBackFun(UInt32 pBuf, UInt32 Size, UInt32 Format, UInt32 Context)
 UInt32 err = cdError.cdOK;

 if ( Format == cdType.FILEFORMAT_BMP )
 IntPtr pBuffer = new IntPtr(pBuf);

 // Get the BITMAPHEADER from pBuf
 cdType.BITMAPHEADER frameHeader = new cdType.BITMAPHEADER();
 frameHeader = (cdType.BITMAPHEADER)Marshal.PtrToStructure(pBuffer, frameHeader.GetType());

 // Create byte array (BITMAPHEADER + image data) and copy from pBuf
 byte[] VideoData = new byte[frameHeader.bmfHeader.bfSize];
 Marshal.Copy(pBuffer, VideoData, 0, (int)frameHeader.bmfHeader.bfSize);

 // Get image size
 int width = frameHeader.bmiHeader.biWidth;
 int height = frameHeader.bmiHeader.biHeight;
 // Create new Bitmap
 Bitmap frame = new Bitmap(width, height);

 BitmapData bmpData = frame.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

 // Copy the image data from memory to the Scan0 property of our Bitmap
 // Start at index 54 because of BITMAPHEADER
 for (int i = 54; i < VideoData.Length; i++)
 Marshal.WriteByte(bmpData.Scan0, i-54, VideoData);


 // Create delegate
 if (this.RecievedFrame != null)
 this.RecievedFrame(this, new StreamEventArgs(frame));
 return err;

If anybody can help me ... please.


wmichael is offline   Reply With Quote
Sponsored Links
Old Mar 3, 2005, 4:07 AM   #2
Junior Member
Join Date: Mar 2005
Posts: 2


I could solve the problem. I forgot to hold the delegate alive that I was passing to the Canon API.

Now the ViewFinder is working.


wmichael is offline   Reply With Quote
Old Apr 5, 2005, 3:57 PM   #3
Junior Member
Join Date: Apr 2005
Posts: 1

Hi Michael!

I'd be very intrested in this program as I could not find a c# equivalent of the Canon sample application, and unfortunately I'm not good enough at c++. Can you please send me your program? I need it for a personal project.
Thank you in advance.

vajkt is offline   Reply With Quote
Old Jul 12, 2005, 8:11 AM   #4
Junior Member
Join Date: Jul 2005
Posts: 1

Dear Michael:

I've apply the CANON SDK,but now have no reply, would yousend me the SDK please. thanks a lot!

My email:[email protected]

Best regards!


jonathanchen is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT -5. The time now is 9:29 AM.