function pointer from DLL

DNewbie run3 at myopera.com
Fri Jan 13 19:58:30 PST 2012


I've been trying to translate the following from http://www.scintilla.org/Steps.html

int (*fn)(void*,int,int,int);
void * ptr;
int canundo;

fn = (int (__cdecl *)(void *,int,int,int))SendMessage(
	hwndScintilla,SCI_GETDIRECTFUNCTION,0,0);
ptr = (void *)SendMessage(hwndScintilla,SCI_GETDIRECTPOINTER,0,0);
canundo = fn(ptr,SCI_CANUNDO,0,0);


And I got a run time error while running 'fn(ptr, SCI_CANUNDO, 0, 0);':

int function (void*,int,int,int) fn;	
fn = cast(int function(void*,int,int,int)) SendMessage(
	hwndScintilla, SCI_GETDIRECTFUNCTION, 0, 0);

void *ptr = cast(void *)SendMessage(hwndScintilla, SCI_GETDIRECTPOINTER, 0, 0);

fn(ptr, SCI_CANUNDO, 0, 0);
Run time error: object.Error: Access Violation


Then I've tried
extern (C) int function (void*,int,int,int) fn;	
fn = cast(extern (C) int function(void*,int,int,int))SendMessage(
	hwndScintilla, SCI_GETDIRECTFUNCTION, 0, 0);
Compilation error: basic type expected, not extern

Could someone point me in the right direction.



More information about the Digitalmars-d-learn mailing list