I've been having problems with call a method in a DLL that outputs 3 parameters when taking a photo from a CF-Camera.
Basically, I know the types that are to be returned from the method schematic at the bottom of this post, but am having a hard time figuring when to use out, ref, or nothing before the attributes.
When ever I put an out, or ref before the byte below, the application will crash, but if I don't I have a 0 byte array. Also, regardless of what I put before the UInt32 I still get nothing back. If I do not put out or ref before the byte I get a bool returned as successful.
public static extern bool Capture_A_Frame(byte pretBuff, ref UInt32 pdSize);
Obviously I have initialised the Cam properly, and set the settings prior to trying to capture, but don't know what I am doing wrong.
Below is directly from the sparse doco. about the Method.
BOOL Capture_A_Frame(LPBYTE pretBuff, DWORD *pdSize);
pretBuff [out] long pointer to preview data.
[out] long pointer to the size of pretBuff.
TRUE indicates success. FALSE indicates failure.
###Reply to Davey###
Close, but no cigar, although you have helped a fella out with the code to Marshal the bytes from memory to a byte.
The problem is that when I use the out keyword on the first param, pretBuff, the application will crash out completely with no way to catch any exception. Kinda like an ejector seat from my code. I've attached the screen grab below, though uncertain it will be of any use.
I've also tried using [Out] rather than out on the PInvoke itself, but to no avail. This way, I get a return of true from the method, but no pointer to the memory address, nor length. What is the difference between [Out] and out.
###Response to Davey's post at approx 19:15 25/11/09 (GMT)###
Thanx again Davey, for another swift response.
Unfortunately, this gives me a result of true, but the IntPtr and int are both set to '0'. I've attached a grab of the QuickWatch listing for the IntPtr below. The Marshal.Copy then, obviously, returns an ArgumentNullException. Any ideas further?
Thanx again for persevering on this one, I'm almost inclined to give you high ratings for that alone. =]