Delete this, DLL export class and How to Write plugins (Part III)

Source: Internet
Author: User
Tags export class
3. Implement plugins.
With the foundation of the first two chapters, this is easier.
First, let's look at some basic concepts:
Q: What is plugins
A: Load different DLL files to implement different functions or additional functions, such as the various plug-ins of the simulator (display, input ...).
Q: Why we use plugins
A: mainly to make the program modular and easy to expand. You do not need to re-release the entire product when upgrading components.
Q: How to do it?
A: Use loadlibrary to load different DLL with the same interface (generally a function, but here we will use C ++ class implementation) to implement/(expand) the function.
Example:
D:/epsxe/plugins> dumpbin spuseal. dll/exports
Microsoft (r) COFF binary file dumper version 6.00.8447
Copyright (c) Microsoft Corp 1992-1998. All rights reserved.

Dump of file spuseal. dll
File Type: DLL
Section contains the following exports for spuseal. dll
0 Characteristics
36a22a22 time date stamp sun Jan 17 10:21:22 1999
0.00 version
2 ordinal Base
22 number of functions
22 number of names
Ordinal hint RVA name
3 0 00001700 response getlibname
2 1 00001710 bytes getlibtype
4 2 00001720 unzip getlibversion
6 3 00001800 spuabout
11 4 release 1ee0 spuclose
5 5 00001730 spuconfigure
18 6 00002090 spugetone
7 7 00001910 spuinit
10 8 bytes 1b90 spuopen
23, 9, 00002270 spuplayadpcmchannel
12 A 00002250 spuplaysample
17B 00002050 spuputone
19 C 201720b0 spusetaddr
20 d running 20e0 spusetpitch
21 E 00002110 spusetvolumel
22 f 00002150 spusetvolumer
8 10 bytes 1b80 spushudown
11 11 00002190 spustartchannels1
14 12 listen 21c0 spustartchannels2
15 13 listen 21f0 spustopchannels1
16 14 00002220 spustopchannels2
9 15 00001880 sputest
Summary
1000. rsrc
96000 upx0
5000 upx1
D:/epsxe/plugins>

This is an output table of the sound plug-in of epsxe. We can see that epsxe communicates with DLL through these functions.
Enter the subject:
It is really annoying to output so many functions from a DLL, and it is also troublesome to go to getprocaddr one by one,
Can I use some simple methods?
Of course you can. Use the DLL output Technology 2 we introduced earlier.
Let's look at the code. Let's make an input plugins class.
; // Input. h
Class input {
Virtual int addref () = 0;
Virtual int release () = 0;
Virtual DWORD queryclsid () = 0; // identify this is a input plugins;
Virtual DWORD issupport (DWORD flags) = 0;
Virtual bool getxy (Int & X, Int & Y) = 0;
Virtual DWORD getbuttonstat () = 0;
Virtual bool addeffect (dword id, DWORD level) = 0;
Virtual bool QueryInterface (dword clsid, lpvoid * ppvoid); // reserved for expansion. More and more like Com.
Virtual bool doconfig ();
Protected:
Input ();
Virtual ~ Input ();
};
--------------------------------------------------------
; // Mouseinput. h
Class mouseinput
: Public input
{
Protected:
Friend input * createinput (lpvoid pvoid );
;//...............
};
--------------------------------------------------------
; // Mouseinput. cpp
Input * createinput (lpvoid pvoid) {return New mouseinput ;};
 
--------------------------------------------------------
; // Keyinput. h
Class keyinput
: Public input
{
Protected:
Friend input * createinput (lpvoid pvoid );
;//...............
};
--------------------------------------------------------
; // Keyinput. cpp
Input * createinput (lpvoid pvoid) {return New keyinput ;};
 
After compilation, mouseinput. dll and keyinput. dll are obtained.
They output the mouseinput class and the keyinput class respectively, while the external program calls them through the input interface, thus implementing the Plugins function.
 
 
I don't know what else is missing. Please kindly advise ......
 
More comments :)

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.