views:

184

answers:

4

I'm using a SDK for a usb camera. The SDK specifies that for each frame grabbed, a callback function will be called. The callback function is defined inside the SDK, it gets a data pointer to the image and a structure used to interpret the data.

All of that works correctly.

To make a useful application out of that, I need to access a few variables from my application. Now because the delegate function is static, I can only access static members. I thought of making a singleton out of them because its gonna be static, but is there any "conventionnal way" of accessing other data inside a delegate function?

+1  A: 

Why not just use a non-static delegate? You'd have access to the class instance members in that case. Is there something forcing you into the static delegate instead of a delegate on an instance of one of the class where your data and logic resides?

If so, then is there a way to pass data to the callback? If you can, you could pass a reference to a class, and use that in your delegate to get your application data.

If not, then you may be forced to have some static data, or a static reference to a class holding your data. A singleton or similar construct may be the best option in this case...

Reed Copsey
A: 

Why did you make the delegate a static? If it hurts when you do it, stop doing it. :)

Rytmis
A: 

The delegate can be static (though why it would need to be, I'm not clear). The function does not need to be.

Dereferencing a delegate into a method call just doesn't care whether the function called is an instance method or a static method.

Tetsujin no Oni
A: 

Can you explain the problem in a more dissolved manner? Is the delegate (method signature) already defined in the SDK and you have to conform? Or did you declare it?

The variables you need to access are in a class of yours? Or where exactly are they?

Thanks in advance hope we can help.

lb