Project Analysis (plug)

Source: Internet
Author: User
Tags define function
Plug process 1. init_plug # define init_plug plug: initplug g_initplug (true); // shared memory data structure struct plugsharememory {void * pfirsthand; // The first handle to open the file * pbuffer; // shared memory}; inline void createsharememory (I _plugmodulemanage * PMM) {char id_name [64] = {0}; getsharememoryname (id_name); void * memhand = plugcreatefilemapping (id_name, 8); If (! Memhand) return; void * pbuf = plugmapviewoffile (memhand); // The ing file is mapped to the process space. pbuf is the pointer after the ing. // it is opened for the first time, save the data plugsharememory * PSM = new plugsharememory; memcpy (pbuf, & PSM, sizeof (PSM); // copy the pointer value of the PSM to the ing address, we can see that the value of the pointer to the MSPs is plugunmapviewoffile (pbuf); MSPS-> pfirsthand = memhand; // you can save the handle of the ing file. MSPS-> pbuffer = PMM; // copy the PMM value to the shared memory. PMM can operate the shared memory. The design is still clever.} inline bool _ stdcall dllloadcontorl: loaddll (STD :: wstring fil Ename) // The DLL {void * hinst = xloadlibraryw (wchar_t *) filename. c_str (); // load the DLL in the directory and return the pointer if (hinst = NULL) {STD :: wstring mess = l "can't load the DLL file:"; mess ++ = filename; plugmessagebox (mess. c_str (); Return false;} // keep it in the memory. m_ahdllhandle [m_dwdllcount] = hinst is automatically released when this class exits; // Save the DLL in m_ahdllhandle + + m_dwdllcount; return true;} call return loadlibraryw (lplibfilename); plug_compon will be automatically called Ent_auto_reg why does it automatically call? I don't understand plug_component_auto_reg (DEMO) // DO NOT edit this # define plug_component_auto_reg (projectname) \ I _ # projectname * _ stdcall new # projectname () {return New projectname ();} void _ stdcall Delete # projectname (void * P) {projectname * PP = static_cast <projectname *> (I _ # projectname *) P); Delete pp;} plug: autoreg projectname # autoreg (# projectname, (void *) New # projectname, (void *) de Lete # projectname); void _ stdcall Reg # projectname () {projectname # autoreg;} view this macro to define function pointers for creating and deleting instances, then call autoreginline void _ stdcall plugmodulemanage: Push (const char * ID, void * pnewinstance, void * pdeleteinstance) {# ifdef _ debug find_overlap (ID ); // If debug is used, duplicate components are detected. # endif if (ID) {plugmodule module; module. id = ID; // ID is the name module. pnewinstance = pnewinstance; // create an instance function module. pdeleteinstance = pdelete Instance; // Delete instance function m_modules.push_back (module); // save instance information to m_modules // STD: Sort (m_modules.begin (), m_modules.end ());}} plug: setapp (New appex (); // Save the value of an app. I don't quite understand what to use. 2.new# define new (projectname) (struct I _ # projectname *) (plug: plugcreeateinstance (# projectname) Search for try {createinstancefun cifun = (createinstancefun) (pnewinstance) in the container of the storage module based on projectname ); void * pinstance = (void *) cifun (); // call the instance creation Function Constructor PMM-> addinstance (pinstance, pdeleteinstance); // save m_instances [* (int *) & P] = instance; return pinstance in m_instances as the key based on the pointer; // returns the instance pointer, which is equivalent to returning the new pointer} 3.del# define del (Instance) Plug: plugdeletdeleteinstance (Instance). Similarly, you can find the instance pointer in m_instances, find the pointer to delete fun (p); // call the deletion function of the instance, that is, call the destructor of the instance. Therefore, the component may be released in this function, in this case, the lock must be released ??? The above Simple plug Workflow

This plug has been tried several times and is half done. Now I have finished reading it.

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.