473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pass a C# function to a COM interface that wants a function pointe

I have a Directshow filter I wrote in C++. I've created an interface to set
a callback function. The app I want to use the filter in is in C#. How do I
pass a function pointer from C# to a COM interface?

I have not been able to find much in the way of examples but I have tried
this:

//COM Object
typdef HRESULT (*MYCALLBACK) (IMediaSample * pSample);
DECLARE_INTERFACE_(IMyFilter, IUknown)
{
STDMETHOD(SetCallbackPointer)(LPVOID FnAddress);
}
MYCALLBACK m_callback;
STDMETHODIMP SetCallbackPointer(LPVOID FnAddress)
{
m_callback = (MYCALLBACK)FnAddress;
}
void InvokeCallback(IMediaSample * pSample)
{
(m_callback)(pSample);
}
HRESULT Transform(IMediaSample *pSample)
{
InvokeCallback(pSample);
}

//C#
public delegate int CallBackDelegate(ref IMediaSample mediaSample);
public class MyClass
{
public CallBackDelegate myDelegate;
public MyClass()
{
myDelegate = new CallBackDelegate(CallbackFunction);

//all the stuff to create the COM object and get the interface
myInterface.SetCallbackPointer(myDelegate);
}
public int CallbackFunction(ref IMediaSample mediaSample)
{
//my intention is get a copy of the mediaSample
MessageBox.Show("Here");
return 0;
}
}

Jul 21 '05 #1
0 764

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
0
by: Travis | last post by:
I have a Directshow filter I wrote in C++. I've created an interface to set a callback function. The app I want to use the filter in is in C#. How do I pass a function pointer from C# to a COM...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.