473,396 Members | 1,722 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,396 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;
}
}

Nov 22 '05 #1
0 859

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

Similar topics

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...
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. ...
8
by: Brian F | last post by:
Exactly what the subject says. I have an ASP page that I want my C# windows application to open in Internet Explorer, and if possible have it send along a list of values from a list box. Thank you.
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
3
by: Brett | last post by:
We have an application completely written in C++ under visual studio v6. One of our customers wants to use some of our existing components in his project but doesn't know C++ and isn't interested...
6
by: Minfu Lu | last post by:
I have a problem dealing with passing a function address to a COM callback. I use this COM function for communicating to a hardware. My original project was written in VB. I have converted it to...
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: ...
9
by: mps | last post by:
I want to define a class that has a generic parameter that is itself a generic class. For example, if I have a generic IQueue<Tinterface, and class A wants to make use of a generic class that...
6
by: Rick | last post by:
Hi, Can anyone explain to me why the below fails to compile - seeing otherA->f(); as a call to a inaccessible function, while otherB->f(); is ok? It seems you can happily access protected...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.