In ProgramSeveral instances with the same control are used. Now we want to uniquely identify these control instances in some way to provide a correct configuration file for each control, this is easy, but the problem is that you do not want to add attributes such as ID and name to the control, but you want to add your own flag inside the control. This is what a friend of mine asked me.
After reading it, I thought it was unlikely. Later, I thought there was an ambientdisplayname in the colecontrol, so I suggest you give it to this friend. It should be said that this function is useful in containers such as VB or Delphi, but it always feels that ambientdisplayname does not require all containers to provide it, and it is not very reliable, so I tried to find the information.
So I suddenly thought of global variables. As a special DLL, the global variables in ActiveX controls can be used in the whole process, including all ActiveX instances, therefore, global variables can easily perform coordination among Multiple ActiveX instances without the intervention of the control client program.
I made an ActiveX Test Control for MFC and tried it.
1. Define global variables in control. cpp
Uint gl_ncount = 0;
2. Define control member variables
Uint m_nid;
In the control Constructor
M_nid = gl_ncount;
Gl_ncount ++;
3. Add the read-only property ID in
In the long GETID () function
Return m_nid;
4. I have implemented a vbprogram and added several controls in form_load.
Dim I as integer
For I = 0 to 3
Msgbox tfire1 (I). ID
Next
The test showed that it can be distinguished, but it is interesting that VB seems to be the control added later in the design, and the earliest it loads at the runtime is really surprising.