473,385 Members | 1,396 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.

Passing delegates in a structure

I am a starter in C# ...

I will present my problem :
I am wrapping a C dll in C#. The C dll exports a function which takes a

structure MYSTRUCT holding 2 function pointers(callback functions).
struct MYSTRUCT
{
ontest1 t1;
ontest2 t2
};
where ontest1 and ontest2 are two function pointers.

In C# dll, I have declared this structure as
[StructLayout(LayoutKind.Sequential)]
public struct MYSTRUCT
{
[MarshalAs(UnmanagedType.FunctionPtr)]
ontest1 t1;
[MarshalAs(UnmanagedType.FunctionPtr)]
ontest2 t2

}
where ontest1 and ontest2 are two delegates.

//Importing the C dll function "MyFunctions"
[DllImport("mydll.dll")]
IntPtr MyFunctions(IntPtr myStruct);
//The .NET function wrapping the above function :
IntPtr MyFunctions1(ref MYSTRUCT mystruct)
{
//Converts MYSTRUCT to pointer
GCHandle callbackHandle = GCHandle.Alloc
(mystruct ,GCHandleType.Pinned);
IntPtr mystructptr = callbackHandle.AddrOfPinnedObject();
//Calls the imported C dll function
IntPtr handle = MyFunctions(mystructptr);
return handle;

}
The address in the delegates in MYSTRUCT are stored inside the C dll..
and the same functions are invoked whenever an event occurs. That is
the unmanaged code calls the managed code asynchronously.

The call to the C dll is working fine.. but whenever an event occurs
the registered function is not getting involked..
Do I have to add/remove anything more to the code?
Any help will be appreciated...
regards
Renjini

Jul 1 '06 #1
0 1026

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

Similar topics

3
by: Sam | last post by:
I’m just starting to learn delegates. I’m at the very beginning. If I understand correctly, delegates are for when you want to pass a function as a parameter. For example the client provides a...
1
by: Kalyan | last post by:
Hello, The following posting was made on this newsgroup some 2 yrs ago. Is this still true with the present release of .net. Because I get the exact same exception thrown "Function pointer not...
2
by: Marcos Stefanakopolus | last post by:
In C# is there any way to use the concept of delegates to have multiple implementations of a particular block of code, so that you can choose between them without the overhead of possibly expensive...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
5
by: renjini | last post by:
I am a starter in C# ... I will present my problem : I am wrapping a C dll in C#. The C dll exports a function which takes a structure MYSTRUCT holding 2 function pointers(callback functions)....
3
by: james | last post by:
Hi guys, I create a delegate and pass in a local variable. When the variable is a reference type everything works fine, but when it is a valuetype the delegate uses the value of the last...
2
by: Israel | last post by:
It seems like there should be a way to pass events around like delegates but on the other hand they’re sort of special delegates because the only one allowed to invoke them is the owner of the...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
10
by: vcquestions | last post by:
Hi. Is there way to have a function pointer to a delegate in c++/cli that would allow me to pass delegates with the same signatures as parameters to a method? I'm working with managed code. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.