digitalmars.D.learn - A DLL to modify a variable?
- Gilles G. <schaouette free.fr> Jun 26 2007
- Daniel Keep <daniel.keep.lists gmail.com> Jun 26 2007
- Gilles G. <schaouette free.fr> Jun 26 2007
- Chris Nicholson-Sauls <ibisbasenji gmail.com> Jun 26 2007
Hello,
maybe I am obviously missing something, but it seems that my dll doesn't modify
the value of the variables.
It looks like this:
=== File from the DLL (with the corresponding def file)
extern(Windows) void modifyThis(int* val){*val=0;}
=== call to the DLL function in the test program
alias void function(int*) modifyThis_t;
modifyThis_t modifyThis;
HMODULE h;
h = LoadLibraryA("test.dll");
int value=1;
modifyThis = cast(modifyThis_t) GetProcAddress(h,"modifyThis");
writefln("Value before call: %d",value);
(*modifyThis)(&value);
writefln("Value after call: %d",value);
But then I get the output:
Value before call: 1
Value after call: 1
I guess this is a beginner's question...
Thanks a lot!
Jun 26 2007
Gilles G. wrote:Hello, maybe I am obviously missing something, but it seems that my dll doesn't modify the value of the variables. It looks like this: === File from the DLL (with the corresponding def file) extern(Windows) void modifyThis(int* val){*val=0;} === call to the DLL function in the test program alias void function(int*) modifyThis_t;
I *could* be wrong, but this looks to be incorrect. It should be (if I remember correctly): extern(Windows) { alias void function(int*) modifyThis_t; } Otherwise, the function type will use the D calling convention, which is probably incompatible with stdcall. Give it a shot, anyway. -- Daniel
Jun 26 2007
Thanks a lot, I would never find this one. -- Gilles Daniel Keep Wrote:Gilles G. wrote:Hello, maybe I am obviously missing something, but it seems that my dll doesn't modify the value of the variables. It looks like this: === File from the DLL (with the corresponding def file) extern(Windows) void modifyThis(int* val){*val=0;} === call to the DLL function in the test program alias void function(int*) modifyThis_t;
I *could* be wrong, but this looks to be incorrect. It should be (if I remember correctly): extern(Windows) { alias void function(int*) modifyThis_t; } Otherwise, the function type will use the D calling convention, which is probably incompatible with stdcall. Give it a shot, anyway. -- Daniel
Jun 26 2007
Gilles G. wrote:Thanks a lot, I would never find this one. -- Gilles
Additionally, you don't have to explicitly dereference the function pointer. Just calling 'modifyThis(&value)' will suffice. Not part of your problem, but I thought it worth mentioning for readability sake. -- Chris Nicholson-Sauls
Jun 26 2007








Chris Nicholson-Sauls <ibisbasenji gmail.com>