|
Hello everyone,
If we define global variable and static variable of a class, which are implemented in a DLL. My questions are,
1. All instances of class share the single copy of global variable and static variable of class? If yes, I need to have some synchronization approach on them.
2. Is it safe to use global variable and static (public) variable after DLL unloads?
thanks in advance,
George
|
|
|
|
|
George_George wrote: All instances of class share the single copy of global variable and static variable of class? If yes, I need to have some synchronization approach on them.
This is true inside a process. Different processes have their own copies of such variables. synchronization is needed for different thread of the same process (i.e. no special rule for DLL s.
George_George wrote: 2. Is it safe to use global variable and static (public) variable after DLL unloads?
It is a mistake.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks CPallini,
1.
CPallini wrote: This is true inside a process. Different processes have their own copies of such variables. synchronization is needed for different thread of the same process (i.e. no special rule for DLLs.
So, for different processes, if they load the same DLL separately, they have different copy of global and static variable inside a class?
2.
Whether it is possible to load a DLL twice inside a process? If yes, whether in this case, there is multiple copies of global variable and static variable of a class?
regards,
George
|
|
|
|
|
George_George wrote: So, for different processes, if they load the same DLL separately, they have different copy of global and static variable inside a class?
Yes. Unless you use special techniques (see for instance [^]), DLL's aren't a media for interprocess communication (sharing a variable is, basical IPC).
George_George wrote: Whether it is possible to load a DLL twice inside a process? If yes, whether in this case, there is multiple copies of global variable and static variable of a class?
Really I don't know. If it is possible then probably there are multiple copies, since you have multiple handles to loaded DLL s. Anyway it is just a guess.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks CPallini,
If the DLL is a COM in-proc server, I think there should not be any changes to load the DLL multiple times? If we follow the guideline of COM, and just use CoCreateInstance/Addref/QueryInterface/...
If I watched a COM in-proc server DLL is loaded multiple copies inside a process, it should be a bug of the COM in-proc server?
regards,
George
|
|
|
|
|
I don't fully understand what you're asking. Anyway, COM DLL 's never expose variables.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks CPallini,
Here is my scenario. You have a COM component, which contains a class and in the class you wrap static member variable. When you create multiple instance of the COM object, by multiple calls to CoCreateInstance or something, all instances of COM objects will share the single copy of static member variables, and if the COM objects can be executed by multiple threads, we have to do synchronization on them, right?
regards,
George
|
|
|
|
|
Well, I'm not an expert of COM threading. Anyway, I think that if your COM object threading model is STA then you don't need synchronization because COM makes on your behalf. In all other circumstances you need to synchonyze.
But, again, since I'm not an expert about, this is going on my arrogant assumptions...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
|
Yes. It seems I was wrong. Good to know.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I will doubt whether there are multiple copies of data inside DLL (e.g. static member variable of a class) if we call LoadLibrary multiple times inside one process? Any ideas?
regards,
George
|
|
|
|
|
Well, I made a little test, getting the same HINSTANCE value when calling two times LoadLibrary using the same DLL file as argument, hence no multiple copies (at least on empirical grounds...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks CPallini!
Seems Windows protects from loading the same DLL twice inside the same process?
regards,
George
|
|
|
|
|
Or maybe it gives out sparingly system resources.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks CPallini.
regards,
George
|
|
|
|
|
In my programm a barcode is needed. This barcode is scanned with a barcode scanner on a serial COM port (COM1 or COM2).
How do I programm this serial communication?
Please keep in mind that I am less than a juvenile in the C++ programming business and I am learning it the hard way (no training).
|
|
|
|
|
You need to have some documentation about the protocol which is used by the barcode device.
|
|
|
|
|
The Barcode scanner works on a serial protocol with a known baudrate, databits, stopbits and so on. If I monitor the scanner with Hyperterminal I see the scanned code as a plain text (ASCII).
|
|
|
|
|
Yeah ok but you need to know what to exchange with the scanner. Don't you have some documentation somewhere ? Can you communicate with the scanner using Hyperterminal ? Do you know which commands to send ?
|
|
|
|
|
The scanner sends me an ascii code (bar code consists of 7 numbers). This code is send when the operator presses the scan button on the scanner (hand held). Programming of the scanner is done with bar codes (available in the manual of the scanner). Here is also an explanation on how this is done with a serial port in combination with a terminal emulation programm (eg like hyperterminal).
The used scanner is a HandHeld IT3800G (supplied in the Netherlands by Sick)
|
|
|
|
|
From your conversation with Cedric, you just need to know how to read from the COM port using a prgram you've written.
This is not a two line process, as it is inherently asynchronous. Luckily, there are a few classes here on codeproject that will help you. Just search for serial communications.
Also, this website may help: http://www.flounder.com/serial.htm[^]
Iain.
Iain Clarke appears because CPallini still cares.
|
|
|
|
|
I want to thank you all for your help and information about this problem..
Iain: your link to flounders.com did the trick in combination with the next aticles:
Creating a Serial communication on WIN32 by Konchat
Serial Communication in Windows by Ashish Dhar
and a MSDN article about the same issue: Serial communication in Win32.
Thanks to you all...
Frank.
|
|
|
|
|
I have created some bitmaps and want to add button control to it.
For example, I want the bitmap to have control such that when it is clicked on,
another dialog form can pop up.
I am working on Visual C++ environment, MFC .
Ema
|
|
|
|
|
If you just want to open another dialog by clicking on bitmap, you can do following:
1. Use picture control to display bitmap.
2. Add OnClick event of PictureControl.
3. Write code to call another Dialog inside OnClick method.
Mukesh Kumar
Software Engineer
|
|
|
|
|
Thanks for the prompt reply.Appreciate it.
I use picture control to display the bitmap.
But then ,the problem I am facing now, is that, there is no OnClick event that I can add.
So what do I do?
Ema
|
|
|
|