views:

157

answers:

1

Hi, thanks for reading.

At the moment im making an application to capture video from a webcam, and at the same time click various buttons that write to a text file to make notes on the video. I'v pretty much got everything down now apart from that the WM_CAP_SEQUENCE takes away control of the application by default during capture... so no button pressing. I need to pass in a capture parameters structure to tell it clicking is allowed, done through the bool yField being set to true. This is where i have a bit of trouble, im not used to structures and also not quite getting the grip of how to use WM_CAP_SET_SEQUENCE_SETUP, il post the relevant code below and hopefully someone might be able to offer me some insight or pointers?

[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA", SetLastError = true)]
    public static extern int SendMessage2(IntPtr webcam1, int Msg, IntPtr wParam, ref CAPTUREPARMS lParam);


CAPTUREPARMS CaptureParams = new CAPTUREPARMS();
        CaptureParams.fYield = 1;
        CaptureParams.fAbortLeftMouse = 0;
        CaptureParams.fAbortRightMouse = 0;
        CaptureParams.dwRequestMicroSecPerFrame = 66667;
        CaptureParams.fMakeUserHitOKToCapture = 0;
        CaptureParams.wPercentDropForError = 10;
        CaptureParams.wChunkGranularity = 0;
        CaptureParams.dwIndexSize = 0;
        CaptureParams.wNumVideoRequested = 10;
        CaptureParams.fCaptureAudio = 0;
        CaptureParams.fLimitEnabled = 0;
        CaptureParams.fMCIControl = 0;
        CaptureParams.fStepMCIDevice = 0;
        CaptureParams.dwMCIStartTime = 0;
        CaptureParams.dwMCIStopTime = 0;
        CaptureParams.fStepCaptureAt2x = 0;
        CaptureParams.wStepCaptureAverageFrames = 5;
        CaptureParams.dwAudioBufferSize = 0;


SendMessage2(webcam1, WM_CAP_SET_SEQUENCE_SETUP, new IntPtr(Marshal.SizeOf(CaptureParams)), ref CaptureParams);

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
    public struct CAPTUREPARMS
    {
        public System.UInt32 dwRequestMicroSecPerFrame;
        public System.Int32 fMakeUserHitOKToCapture;
        public System.UInt32 wPercentDropForError;
        public System.Int32 fYield;
        public System.UInt32 dwIndexSize;
        public System.UInt32 wChunkGranularity;
        public System.Int32 fCaptureAudio;
        public System.UInt32 wNumVideoRequested;
        public System.UInt32 wNumAudioRequested;
        public System.Int32 fAbortLeftMouse;
        public System.Int32 fAbortRightMouse;
        public System.Int32 fMCIControl;
        public System.Int32 fStepMCIDevice;
        public System.UInt32 dwMCIStartTime;
        public System.UInt32 dwMCIStopTime;
        public System.Int32 fStepCaptureAt2x;
        public System.UInt32 wStepCaptureAverageFrames;
        public System.UInt32 dwAudioBufferSize;



        public void SetParams(System.Int32 fYield, System.Int32 fAbortLeftMouse, System.Int32 fAbortRightMouse, System.UInt32 dwRequestMicroSecPerFrame, System.Int32 fMakeUserHitOKToCapture,
            System.UInt32 wPercentDropForError, System.UInt32 dwIndexSize, System.UInt32 wChunkGranularity, System.UInt32 wNumVideoRequested, System.Int32 fCaptureAudio, System.Int32 fMCIControl,
            System.Int32 fStepMCIDevice, System.UInt32 dwMCIStartTime, System.UInt32 dwMCIStopTime, System.Int32 fStepCaptureAt2x, System.UInt32 wStepCaptureAverageFrames, System.UInt32 dwAudioBufferSize)
        {


            this.dwRequestMicroSecPerFrame = dwRequestMicroSecPerFrame;
            this.fMakeUserHitOKToCapture = fMakeUserHitOKToCapture;
            this.fYield = fYield;
            this.wPercentDropForError = wPercentDropForError;
            this.dwIndexSize = dwIndexSize;
            this.wChunkGranularity = wChunkGranularity;
            this.wNumVideoRequested = wNumVideoRequested;
            this.fCaptureAudio = fCaptureAudio;
            this.fAbortLeftMouse = fAbortLeftMouse;
            this.fAbortRightMouse = fAbortRightMouse;
            this.fMCIControl = fMCIControl;
            this.fStepMCIDevice = fStepMCIDevice;
            this.dwMCIStartTime = dwMCIStartTime;
            this.dwMCIStopTime = dwMCIStopTime;
            this.fStepCaptureAt2x = fStepCaptureAt2x;
            this.wStepCaptureAverageFrames = wStepCaptureAverageFrames;
            this.dwAudioBufferSize = dwAudioBufferSize;
A: 

wParam must equal the size of the structure and wParam is before lParam, so you should call it like this:

SendMessage2(webcam1, WM_CAP_SET_SEQUENCE_SETUP, new IntPtr(Marshal.SizeOf(typeof(CAPTUREPARMS))), ref CaptureParams);

And the method signature should look like this:

[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA")]
public static extern IntPtr SendMessage2(IntPtr webcam1, int Msg, IntPtr wParam, ref CAPTUREPARMS lParam);

Your structure also has the wrong layout, use the CAPTUREPARMS definition from pinvoke.net (the Pack=1 part looks suspicious there though, so you might want to try both with and without it).

Pent Ploompuu
[code] new IntPtr(Marshal.SizeOf(CAPTUREPARMS)), [/code] gave an error so i put in CaptureParams where you suggested CAPTUREPARMS. After that it ran fine, but still doesnt seem to let me click things, the same as before... its as if the structure itself just isnt telling it anything useful.(i did everything else, lparams last etc)
Verian
The layout of your `CAPTUREPARMS` struct is also wrong, try using the one from pinvoke.net.
Pent Ploompuu
Thanks for your help so far.I hate to sound like an idiot now, but iv went and got the structure from pinvoke, and changed my false/true inputs to 0/1s for the int32s to take in, and im still not having any luck
Verian
What does `SendMessage2` return? If it returns 0 then the `WM_CAP_SET_SEQUENCE_SETUP` call isn't successful and `GetLastError` should give more details if you add `SetLastError = true` to the `DllImport` attribute.
Pent Ploompuu
It returns 1, so i guess the call itself is working?
Verian
This result confuses me now, since it looks right and gives no error, yet just doesnt work hah, il update my code in the question now to show where im at with it
Verian