By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

Delegates - have I got it right?

P: n/a
Hello,

I'm trying to make a user control which acts as a frame grabber, and I'm
using the functionality in avicap32.dll to do this. I need to setup a
callback function which gets called whenever a new frame of video fills
the buffer.

My problem is that the breakpoint in the video callback is never
reached. I realise it's likely to be a problem with the way I'm using
avicap, but just wondered if I'm using the delegates correctly as this
is a completely new area to me, and I've been a little confused about them?

Thanks,

Gary

In my namespace I declare:

public delegate bool CallBack();
In my class I have the following for API calls:

[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam,
int lParam);
// A version of SendMessage where the lparam is a delegate/callback
function
[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessageWithLparamDelegate(int hWnd, uint
Msg, int wParam, CallBack lpFunc);
To set up my callback function (after successfully creating a capture
window, mCapHwnd) in one of my methods (return values indicate success):

CallBack vidCallBack = new CallBack(VideoStreamCallBack);
ret = SendMessageWithLparamDelegate(mCapHwnd,
WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, vidCallBack);
CallBack errCallBack = new CallBack(ErrorCallBack);
ret = SendMessageWithLparamDelegate(mCapHwnd,
WM_CAP_SET_CALLBACK_ERROR, 0, errCallBack);
And my callbacks (just got breakpoints on the return lines at the moment)

// Should be called everytime the video buffer is filled
public bool VideoStreamCallBack()
{
// Do something

return true;
}
// Error handling callback for avicap
public bool ErrorCallBack()
{
// Do something

return true;
}
Mar 1 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a


Well, I've discovered it seems to work - managed to force an error and
ErrorCallBack() got called as it should.

Still no luck with my VideoStreamCallBack() so if anyone can shed any
light on using avicap I'd be grateful - plenty of examples on the web
that use the clipboard, but I want to avoid that method.
beaker wrote:
Hello,

I'm trying to make a user control which acts as a frame grabber, and I'm
using the functionality in avicap32.dll to do this. I need to setup a
callback function which gets called whenever a new frame of video fills
the buffer.

My problem is that the breakpoint in the video callback is never
reached. I realise it's likely to be a problem with the way I'm using
avicap, but just wondered if I'm using the delegates correctly as this
is a completely new area to me, and I've been a little confused about them?

Thanks,

Gary

In my namespace I declare:

public delegate bool CallBack();
In my class I have the following for API calls:

[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam,
int lParam);
// A version of SendMessage where the lparam is a delegate/callback
function
[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessageWithLparamDelegate(int hWnd, uint
Msg, int wParam, CallBack lpFunc);
To set up my callback function (after successfully creating a capture
window, mCapHwnd) in one of my methods (return values indicate success):

CallBack vidCallBack = new CallBack(VideoStreamCallBack);
ret = SendMessageWithLparamDelegate(mCapHwnd,
WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, vidCallBack);
CallBack errCallBack = new CallBack(ErrorCallBack);
ret = SendMessageWithLparamDelegate(mCapHwnd,
WM_CAP_SET_CALLBACK_ERROR, 0, errCallBack);
And my callbacks (just got breakpoints on the return lines at the moment)

// Should be called everytime the video buffer is filled
public bool VideoStreamCallBack()
{
// Do something

return true;
}
// Error handling callback for avicap
public bool ErrorCallBack()
{
// Do something

return true;
}

Mar 1 '06 #2

P: n/a
Hi Beaker,
I do not have experience using avicap to capture video but I have used a
project that wraps DirectShow into a managed component to capture video,
maybe this will be useful for you. There is an article at the following link:

http://www.codeproject.com/cs/media/..._Detection.asp

Mark Dawson
http://www.markdawson.org
"beaker" wrote:


Well, I've discovered it seems to work - managed to force an error and
ErrorCallBack() got called as it should.

Still no luck with my VideoStreamCallBack() so if anyone can shed any
light on using avicap I'd be grateful - plenty of examples on the web
that use the clipboard, but I want to avoid that method.
beaker wrote:
Hello,

I'm trying to make a user control which acts as a frame grabber, and I'm
using the functionality in avicap32.dll to do this. I need to setup a
callback function which gets called whenever a new frame of video fills
the buffer.

My problem is that the breakpoint in the video callback is never
reached. I realise it's likely to be a problem with the way I'm using
avicap, but just wondered if I'm using the delegates correctly as this
is a completely new area to me, and I've been a little confused about them?

Thanks,

Gary

In my namespace I declare:

public delegate bool CallBack();
In my class I have the following for API calls:

[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam,
int lParam);
// A version of SendMessage where the lparam is a delegate/callback
function
[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessageWithLparamDelegate(int hWnd, uint
Msg, int wParam, CallBack lpFunc);
To set up my callback function (after successfully creating a capture
window, mCapHwnd) in one of my methods (return values indicate success):

CallBack vidCallBack = new CallBack(VideoStreamCallBack);
ret = SendMessageWithLparamDelegate(mCapHwnd,
WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, vidCallBack);
CallBack errCallBack = new CallBack(ErrorCallBack);
ret = SendMessageWithLparamDelegate(mCapHwnd,
WM_CAP_SET_CALLBACK_ERROR, 0, errCallBack);
And my callbacks (just got breakpoints on the return lines at the moment)

// Should be called everytime the video buffer is filled
public bool VideoStreamCallBack()
{
// Do something

return true;
}
// Error handling callback for avicap
public bool ErrorCallBack()
{
// Do something

return true;
}

Mar 1 '06 #3

P: n/a
I think your problem is that you have delegate instances as local fields in
the method body, and they may (and will) get collected, so there is no
chance to invoke the callbacks from the unmanaged code.
What you need to do is have static references to these instances, so they
will not get collected.
This is just my thought based on what I've read somewhere some time ago,
maybe it will help you.

"beaker" <ra**************@rhubarbblahblah.net> wrote in message
news:Op******************@fe1.news.blueyonder.co.u k...


Well, I've discovered it seems to work - managed to force an error and
ErrorCallBack() got called as it should.

Still no luck with my VideoStreamCallBack() so if anyone can shed any
light on using avicap I'd be grateful - plenty of examples on the web that
use the clipboard, but I want to avoid that method.
beaker wrote:
Hello,

I'm trying to make a user control which acts as a frame grabber, and I'm
using the functionality in avicap32.dll to do this. I need to setup a
callback function which gets called whenever a new frame of video fills
the buffer.

My problem is that the breakpoint in the video callback is never reached.
I realise it's likely to be a problem with the way I'm using avicap, but
just wondered if I'm using the delegates correctly as this is a
completely new area to me, and I've been a little confused about them?

Thanks,

Gary

In my namespace I declare:

public delegate bool CallBack();
In my class I have the following for API calls:

[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam,
int lParam);
// A version of SendMessage where the lparam is a delegate/callback
function
[DllImport("user32", EntryPoint = "SendMessage")]
public static extern int SendMessageWithLparamDelegate(int hWnd, uint
Msg, int wParam, CallBack lpFunc);
To set up my callback function (after successfully creating a capture
window, mCapHwnd) in one of my methods (return values indicate success):

CallBack vidCallBack = new CallBack(VideoStreamCallBack);
ret = SendMessageWithLparamDelegate(mCapHwnd,
WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, vidCallBack);
CallBack errCallBack = new CallBack(ErrorCallBack);
ret = SendMessageWithLparamDelegate(mCapHwnd,
WM_CAP_SET_CALLBACK_ERROR, 0, errCallBack);
And my callbacks (just got breakpoints on the return lines at the moment)

// Should be called everytime the video buffer is filled
public bool VideoStreamCallBack()
{
// Do something

return true;
}
// Error handling callback for avicap
public bool ErrorCallBack()
{
// Do something

return true;
}

Mar 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.