digitalmars.D.learn - A DLL to modify a variable?
- Gilles G. (20/20) Jun 26 2007 Hello,
- Daniel Keep (11/19) Jun 26 2007 I *could* be wrong, but this looks to be incorrect. It should be (if I
- Gilles G. (4/30) Jun 26 2007 Thanks a lot, I would never find this one.
- Chris Nicholson-Sauls (5/9) Jun 26 2007 Additionally, you don't have to explicitly dereference the function
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. -- GillesAdditionally, 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>