DELETE THIS, DLL Export Class and How to Write Plugins (Part III)

zhaozj2021-02-08  224

3. Implement Plugins.

With the foundation of the first two chapters, this is better.

First understand a little basic concept:

Q: What is plugins

A: This is a different functionality, or an additional function, typical, such as a simulator, is typically a variety of plug-ins (display, input ...).

Q: why we use plugins

A: In order to make the program modular, it is easy to expand. You don't need to re-issue the entire product when upgrading the component.

Q: How to do it?

A: Different DLLs, implementation / (expansion) functions that use LoadLibrary to load with the same interface (usually functions, but we will use the C class implementation).

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 psegetlibname

2 1 00001710 PSegetLibType

4 2 00001720 PsegetLibversion

6 3 00001800 SPUAbout

11 4 00001EE0 spuClose

5 5 00001730 SpuConfigure

18 6 00002090 SPUGETONE

77 00001910 Spuinit

10 8 00001B90 SPUOpen

23 9 00002270 SpuPlayAdpcmchannel

12 a 0000250 SpuplaySample

17 B 00002050 Spuputone

19 c 000020b0 spusetaddr

20 d 000020E0 spusetpitch

21 E 00002110 SpusetVolumel

22 f 00002150 spusetvolumer

8 10 00001B80 SPUSHUSHUTDOWN

13 11 00002190 SPUSTARTCHANNELS1

14 12 000021C0 SPUSTARTCHANNELS2

15 13 000021F0 SPUSTOPCHANNELS1

16 14 0000220 SPUSTOPCHANNELS2

9 15 00001880 SPUTEST

Summary

1000.RSRC

96000 UPX0

5000 UPX1

D: / EPSXE / PLUGINS>

This is an output table of an Sound plugin of EPSXE. You can see that EPSXE is communicated with DLL through these functions.

Into the title:

It is a very annoying thing to output so many functions from a DLL, and one by one is very troublesome.

Can you use simple ways?

Of course, it is ok, you can use the DLL output class technology that we described above.

Still look at the code, we are doing an Input's 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 Adeffect (DWORD ID, DWORD Level) = 0;

Virtual Bool QueryInterface (DWORD CLSID, LPVOID * PPVOID); // Remodes the expansion. More and more like CoM.

Virtual bool doconfig ();

protected:

INPUT ();

Virtual ~ infut ();

}

-------------------------------------------------- --------

; // 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 compiling, I got MouseInput.dll and Keyinput.dll.

They output the MouseInput class and the KeyInput class, and the external program calls them through the interface of the input, thereby implementing the Plugins functionality.

I don't know if there is anything I miss, please advise. . . . . .

More comments :)

转载请注明原文地址:https://www.9cbs.com/read-1947.html

New Post(0)