Usage of global variables in ActiveX Controls

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.