How to add plug-ins to your own programs-using DLLs as Plug-ins

Source: Internet
Author: User
Tags class definition

Many programs now support plug-in Plug-ins, Plug-ins can make the program easy to expand. Plug-ins are generally required to have a standard interface. We are here to make the simplest plug-ins. The structure of the plug-in is defined as follows:

This is the output function of the plug-in DLL, which is used to create plug-ins.

BOOL Plug_CreateObject(void ** pobj){
*pobj = new CMyPlug;
return *pobj != NULL;
}

base class definition for Plug-ins

class CPlugBase {
public:
CPlugBase(){};
public:
virtual HICON GetIcon() = 0; //用于显示插件的图标
virtual void Hello(int k) = 0; //插件的功能函数。
virtual void Release() = 0; //释放插件。
};

The plug-in's class must be based on cplugbase, to implement the above three functions, others can be arbitrarily extended.

This example includes a main program and two plugins.

Main Program Interface:

This is not a plugin when the interface, we can click on plug-in-〉 added to add Plug-ins, program pop-up

We enter the category and plug-in files, press OK to add a plugin, add after the program automatically add an icon:

This icon represents just that plugin, again we can add a plugin

We test click on the icon 1,

We test click on the icon 2

The above two message is displayed by the Hello function that runs the plug-in.

The next time the program starts, the plugin has been automatically added, without registering again.

The above procedures are compiled and run through Win2000 Professional + VC6 + SP5 + Platform SDK 2001.11.

General installation of VC can be, before I have done similar in vc5+win98.

This article supporting source code

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.