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? 5 1712
On 15 Jun, 15:07, "k.sahici" <k.sah...@gmail.comwrote:
__declspec(dllexport)
void Pos(MyStruc &r)
{
r.var = true;}
HINSTANCE hGetProcIDDLL = LoadLibrary("MYDLL.dll");
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL),
"Pos");
i think that HMODULE is just an alias
for HINSTANCE, no need to cast
>
if (lpfnGetProcessID == NULL)
{
return;}
typedef void(*pICFUNC) (lpfnGetProcessID);
so pICFUNC is a pointer to a function returning void
with one argument of type FARPROC. like:
void weird_fun(FARPROC);
pICFUNC pfunc = pICFUNC(lpfnGetProcessID);
typedef void (*pICFUNC)(MyStruc &);
pICFUNC pfunc = (pICFUNC)(lpfnGetProcessID);
MyStruc r;
pfunc(r);
I don't believe this should compile in the first place.
you can't convert MyStruc to FARPROC
Do you have any idea about this weird behavior?
it is called 'undefined behaviour'
regards
DS
On 15 Jun, 16:06, dasjotre <dasjo...@googlemail.comwrote:
typedef void(*pICFUNC) (lpfnGetProcessID);
ups almost missed this one!
surely that won't compile, lpfnGetProcessID is not a type
VC6 is very old and not even supported by MS any more.
you can download free community edition of VC8 from
MS. also, using lib files in conjunction with DLLs makes
it much easier than LoadLibrary/GetProcAddress and
you can't make the kind of the errors you made.
regards
DS
k.sahici wrote:
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?
This is really a C++ newsgroup, but maybe someday C++ will have
standard features for shareable and dynamic link libraries.
Check that you're also exporting the entire MyStruc class. If
you're merely defining it in a header the Microsoft DLL and the
application that loads the DLL will have their own copies rather
than a common copy.
On Jun 15, 6:16 pm, dasjotre <dasjo...@googlemail.comwrote:
On 15 Jun, 16:06, dasjotre <dasjo...@googlemail.comwrote:
typedef void(*pICFUNC) (lpfnGetProcessID);
ups almost missed this one!
surely that won't compile, lpfnGetProcessID is not a type
VC6 is very old and not even supported by MS any more.
you can download free community edition of VC8 from
MS. also, using lib files in conjunction with DLLs makes
it much easier than LoadLibrary/GetProcAddress and
you can't make the kind of the errors you made.
regards
DS
First of all, I'd like to thank all of you for your replies.
I've just realized that I've mistyped my question.
typedef void(*pICFUNC) (lpfnGetProcessID); //I know this is wrong and
actually I wrote
typedef void(*pICFUNC) (MyStruc &); in my source file
However, last time I checked it, I saw it was working. But I'm sure it
was not working when I posted this question a few days ago. Is it
possible that there is undefined behavior about using bool parameter
type in a dll function?
On 18 Jun, 07:52, "k.sahici" <k.sah...@gmail.comwrote:
On Jun 15, 6:16 pm, dasjotre <dasjo...@googlemail.comwrote:
On 15 Jun, 16:06, dasjotre <dasjo...@googlemail.comwrote:
typedef void(*pICFUNC) (lpfnGetProcessID);
ups almost missed this one!
surely that won't compile, lpfnGetProcessID is not a type
VC6 is very old and not even supported by MS any more.
you can download free community edition of VC8 from
MS. also, using lib files in conjunction with DLLs makes
it much easier than LoadLibrary/GetProcAddress and
you can't make the kind of the errors you made.
regards
DS
First of all, I'd like to thank all of you for your replies.
I've just realized that I've mistyped my question.
typedef void(*pICFUNC) (lpfnGetProcessID); //I know this is wrong and
actually I wrote
typedef void(*pICFUNC) (MyStruc &); in my source file
However, last time I checked it, I saw it was working. But I'm sure it
was not working when I posted this question a few days ago. Is it
possible that there is undefined behavior about using bool parameter
type in a dll function?
It is possible that there is a bug in your compiler causing this. My
experience is that whenever I try to blame the compiler it turns out
that the mistake was mine :)
regards.
DS This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nomak |
last post by:
Hello,
With this code:
$ cat -n ifs.cc
1 #include <vector>
2 #include <iostream>
3
4 using std::vector;
5 using std::cin;
|
by: ORC |
last post by:
Is the bool type actually an Int32 with 0 as false and non zero as true? The
reason for my question is that I've seen a lot of API calls that return a
Int32 implemented in C# as an bool like:
...
|
by: Mochuelo |
last post by:
Hi,
In the constructor of a class, I am taking as a parameter the
reference to a "bool", as in this code:
-----------------------
public class TCP_synch_client
{
public string address...
|
by: tim |
last post by:
We've started to use a coding standards checker at work. The following
code results in a warning:
38: CPlainText::CPlainText(const char *szPath,bool bTimeStamp,bool
bSaveLast)
39: ...
|
by: markb |
last post by:
Hi
My C# app is being called from a callback from an unmanaged DLL. One of
the parameters of the callback is of type BOOL. I am using PInvoke to
marshal this to a (managed) bool. The problem is...
| |
by: =?Utf-8?B?UGF1bA==?= |
last post by:
Hi I have the method below that returns a bool, true or false depending
on if the conversion to date tiem works. It takes a string input. I am
only returning the bool but would also like to...
|
by: rbrowning1958 |
last post by:
Hello,
I am confused by dispose etc. and hope someone can set me right.
1. The Dispose(Bool) the IDE generates for a form has nothing to do
with IDisposable, right?
2. So when is this called?...
|
by: ssylee |
last post by:
I am using mikroC to program some microcontroller code in C. However I
have come across of potential problem of bool type not being supported
from the compiler complaint on how I declared type bool...
|
by: Thorsten Dittmar |
last post by:
Hi there,
we have this C++ DLL we wrote some time ago to do some Win32 native
stuff for us.
The function we're calling in the DLL returns a boolean value (type
bool) indicating success of the...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |