K
k.sahici
I have a DLL written in C++ which has a function shown below.
/**********************************
//MYDLL.cpp
__declspec(dllexport)
void Pos(MyStruc &r)
{
r.var = true;
}
/**********************************
and I export it in Export.def
/**********************************
LIBRARY MYDLL
EXPORTS
Pos
/**********************************
MyStruc is also declared as
/**********************************
Struc MyStruc{
bool var;
MyStruc( ){
var = false;
};
/**********************************
As you see above, MyStruc has a default constructor which sets var to
false.
When I use this dll in another C++ source file as
/**********************************
HINSTANCE hGetProcIDDLL = LoadLibrary("MYDLL.dll");
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL),
"Pos");
if (lpfnGetProcessID == NULL)
{
return;
}
typedef void(*pICFUNC) (lpfnGetProcessID);
pICFUNC pfunc = pICFUNC(lpfnGetProcessID);
MyStruc r;
pfunc(r);
/**********************************
This code(in other words, Pos function in MYDLL.dll) is supposed to
change r.var to true, but somehow it doesn't and when I check its
value I see that it's still false. When I change the default
constructor to set var to true and change the Pos function to set
r.var to false, I see that var is still true.
To sum up, the default constructor overwrites what my Pos(MyStruc &r )
does. The interesting thing is, I write the DLL and the program which
uses this DLL in the same programming language and with the same IDE,
Visual C++ 6.0. I should also point out that I change none of the
project settings. I think it is mainly about using bool type in a DLL.
Do you have any idea about this weird behavior?
/**********************************
//MYDLL.cpp
__declspec(dllexport)
void Pos(MyStruc &r)
{
r.var = true;
}
/**********************************
and I export it in Export.def
/**********************************
LIBRARY MYDLL
EXPORTS
Pos
/**********************************
MyStruc is also declared as
/**********************************
Struc MyStruc{
bool var;
MyStruc( ){
var = false;
};
/**********************************
As you see above, MyStruc has a default constructor which sets var to
false.
When I use this dll in another C++ source file as
/**********************************
HINSTANCE hGetProcIDDLL = LoadLibrary("MYDLL.dll");
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL),
"Pos");
if (lpfnGetProcessID == NULL)
{
return;
}
typedef void(*pICFUNC) (lpfnGetProcessID);
pICFUNC pfunc = pICFUNC(lpfnGetProcessID);
MyStruc r;
pfunc(r);
/**********************************
This code(in other words, Pos function in MYDLL.dll) is supposed to
change r.var to true, but somehow it doesn't and when I check its
value I see that it's still false. When I change the default
constructor to set var to true and change the Pos function to set
r.var to false, I see that var is still true.
To sum up, the default constructor overwrites what my Pos(MyStruc &r )
does. The interesting thing is, I write the DLL and the program which
uses this DLL in the same programming language and with the same IDE,
Visual C++ 6.0. I should also point out that I change none of the
project settings. I think it is mainly about using bool type in a DLL.
Do you have any idea about this weird behavior?