[Mono-list] C function pointer in C# ?

Lloyd Dupont lloyd@galador.net
Fri, 16 Nov 2001 15:29:11 +0100


still interop problem...
i try to get OpenGL 1.2 function through function pointer.
but i do not manage to export from C to C# function pointer, if anyone 
has idea ?

to ease you this process i join you my tiny test project

#-- makefile
test run: all
	a

all: a.dll a.exe

a.dll: a.c
	gcc -shared -o a.dll a.c

a.exe: a.cs
	csc /unsafe a.cs

dist zip: a.tgz

a.tgz: a.c a.cs makefile
	tar czf $@ $^

clean:
	-rm -rf a.exe a.dll
#-- a.c
#include <stdlib.h>
#include <stdio.h>
#define DLLOBJ __declspec(dllexport)
#define CALLTYPE _stdcall

static int coucou(char * s)
{
     if(s)
     	return printf("coucou %s !\n", s);
     return printf("coucou toi !\n");
}

DLLOBJ int (* LoadFct())(char *)
{
     return &coucou;
}
#-- a.cs
// csc /unsafe a.cs && a
using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;

public class Test
{
	delegate int PCoucou(string s);

	[DllImport("a")]
	static extern PCoucou LoadFct();

     static void Main(string[] arg) {
         PCoucou p = LoadFct();

         if(arg.Length != 0)
         	p(arg[0]);
         else
         	p(null);
	}
}
#-- End Of Code