473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Marshalling a function pointer to a delegate without .NET 2.0

I know this functionality already exists in .NET 2.0 via
Marshal.GetDele gateForFunction Pointer, but I'd rather not force my users to
use a beta framework (not to mention the fact that I'm still using good old
vs .net 2002, that refuses to use the 2.0 framework).

Specifically, I'm using an external declaration of the Simple Directmedia
Library function SDL_GL_GetProcA ddress to acquire the procedure addresses
of OpenGL extensions. Unfortunately, you can't make simple external
declarations for them. In other languages you simply acquire function
pointers to them.

This is the external declaration for SDL_GL_GetProcA ddress:

[DllImport("sdl. dll", EntryPoint = "SDL_GL_GetProc Address")]
public static extern IntPtr GetProcAddress( string funcname);

You provide the name of the extension function, and the return value is a
pointer to that function.

I'm willing to use the unsafe version as well, I'll just wrap it in a safe
wrapper to make sure it's CLS compliant.

[DllImport("sdl. dll", EntryPoint = "SDL_GL_GetProc Address")]
private unsafe static extern void * GetProcAddress( string funcname);

So how would one go about marshaling the function pointer to a delegate in
1.0 or 1.1? Surely there's some roundabout way of doing it.
Nov 17 '05 #1
2 1932
>So how would one go about marshaling the function pointer to a delegate in
1.0 or 1.1?


The simple answer is that you can't do it. The easiest solution is to
write a wrapper in a language that supports calling functions by
function pointer (such as C++).

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2
Yeh I figured I'd wind up writing an unmanaged library, at least until 2.0
is the standard. I had just hoped there was some circuitous route in .NET
that allowed you to call an unmanaged function pointer.

Thanks for the help.

Mattias Sjögren <ma************ ********@mvps.o rg> wrote in
news:uQ******** ******@TK2MSFTN GP14.phx.gbl:
So how would one go about marshaling the function pointer to a
delegate in 1.0 or 1.1?


The simple answer is that you can't do it. The easiest solution is to
write a wrapper in a language that supports calling functions by
function pointer (such as C++).

Mattias


Nov 17 '05 #3

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

Similar topics

4
2119
by: Ole | last post by:
hello, Little problem: struct operatable { char * operatable_id; int ( * delegate ) ( ... ); somedatatype data; };
3
11881
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example, how do I make my user control call a to-be-developed-function cmdOkay_Click() function as described below. 1. Create an user control that contains an OK button as below Public Class MyButton:System.Windows.Form.UserControl
3
2173
by: Jerry Houston | last post by:
In a winform application, I use worker threads to perform asynchronous tasks (e.g., mail merge with Word). The thread procs need to gather some user options from controls in the UI, and I know that must be done using a delegate that's running on the main UI thread. (Can't safely access a window from a thread different than the one that created the window.) Rather than write and execute 7 separate methods to get things like checkbox and...
4
10683
by: TT (Tom Tempelaere) | last post by:
Hi people I am wrapping a C dll using PInvoke from C#. I need to wrap the following signature in C int dma_start( const UCHAR* data, UINT data_length ) The function should start with a DMA operation, and I have to use it from my C# program. I am really unsure what type of marshalling I should use. The data parameter is a pointer to an array of byte data. This data must not be copied when calling the function. Plus, the .NET...
6
1240
by: Peter Oliphant | last post by:
Here is a simplification of my code. Basically, I have a class (A) that can be constructed using a function pointer to a function that returns a bool with no parameters. I then want to create an instance of this class (A) in another class (B) which uses one of its own methods of the 'proper form' to initialize the instance. But I get an error: __gc class ClassA { public: ClassA( bool (*func)(void) ) {//---some code---//} // constructor
2
3409
by: sg71.cherub | last post by:
Here I am meeting a problem. I am transfering unmanaged C/C++ codes to managed C# codes. For the general C/C++ function pointer, it is easy to implement its function by C# delegate. e.g. Declare (C/C++): double (* f) (double * x, void * parms); Declare (C#): public delegate double f (double x, object parms); And the ways to use them are logically similiar.
4
3840
by: Abra | last post by:
I have an application where I need to send a inter-process message (a data stream) that contains among other the address of a function (member of a class). For that, I need to serialize it, so I tried to cast it to an IntPtr, but without success. And of course, on the receiever side, I need to cast it back from IntPtr to the function pointer, in order to be able to perform the callback function call, but this doesn't work either. How...
0
2020
by: Haxan | last post by:
Hi, I have an unmanaged application that converts a function pointer to a delegate and then pass this as a parameter(delegate) to a managed function which then invokes it. Currently Im able to jump to this unmanaged function, but the values of the parameters inside this function Im seeing are not correct(they have some garbage values). //unmanaged class (C++ application)
3
1733
by: kumarabhijit | last post by:
Hi, Can anyone help me about how to write Marshalling code for Function pointer in cpp? Thanks Abhijit
0
10353
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10099
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.