TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sindhu maheswari
NA
6
0
calling a DLL function using function pointers
May 12 2010 1:46 AM
hi all,
i am trying to export my C++ functions to C#. and i have succeeded in exporting them. while importing the functions. now to one of such functions, i want to pass two newly defined functions in C# as arguments, how should i achieve this. kindly help me.i am very badly in need of the solution to complete my project.
this is how i have implemented:
1. function exporting from C++:
<b>extern __declspec(dllexport) bool Callregistercallback(CRTSPWrapper* pObject,funccallback fptr_video,funccallback fptr_audio,void* ptr);</b>
where funccallback is a function pointer
2. function call in C++ test application
m_oSarixrtsp->registercallback(GetVideoPacket,GetAudioPacket,NULL);
where GetVideoPacket and GetAudioPackets are functions that are defined in the main of C++
3.function importing in C#
[DllImport("sampleclient_dll.dll", CharSet = CharSet.Ansi)]
static private extern bool Callregistercallback(IntPtr pTestClassObject,IntPtr fptr_video,IntPtr fptr_audio,IntPtr ptr);
4.function defintion in C#:
here i have defined two delegates to the functions namely Getvideopacket and getaudiopacket as follows:
public delegate void getadelegate(char[] pBuffer, int nSize);
public delegate void getvdelegate(char[] pBuffer, int nSize);
public bool registercallback([MarshalAs(UnmanagedType.FunctionPtr)]IntPtr fptr_video, [MarshalAs(UnmanagedType.FunctionPtr)] IntPtr fptr_audio, IntPtr ptr)
{
getvdelegate objv = new getvdelegate(Getvideopacket);
getadelegate obja = new getadelegate(Getaudiopacket);
return Callregistercallback(this.m_pNativeObject, fptr_video, fptr_audio, ptr);
}
5.function call from test application in C#:
testclass.registercallback(Getvideopacket,Getaudiopacket,null);
this is resulting in a compile time error stating: cannot convert a System method to System IntPtr.
Kinldy help me out please. thanks in advance.
Reply
Answers (
0
)
LINQ to SQL performance info needed
The data types text and nvarchar are incompatible in the equal to operator+sql exception