-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallDLLInterfaceFunction.h
More file actions
89 lines (68 loc) · 2.79 KB
/
CallDLLInterfaceFunction.h
File metadata and controls
89 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//---------------------------------------------------------------------------
#ifndef CallDLLInterfaceFunctionH
#define CallDLLInterfaceFunctionH
#include <vcl.h>
#include <map>
#include <string>
#include <list>
using namespace std;
#include "HighLevelDLLFunction.h"
#include "LowLevelDLLFunction.h"
namespace CallDLLInterface
{
//std class
class HashedLibraries
{
public:
map <std::string, HANDLE> loaded_libs;
HANDLE LoadHashedLibrary(std::string DLL);
bool FreeHashedLibrary(std::string DLL);
void FreeHashedLibraries();
~HashedLibraries(){ FreeHashedLibraries(); }
};
class HighLevelDLLFunction;
class LowLevelDLLFunction;
struct FullDLLFunction
{
std::string path;
std::string function;
HANDLE handle;
FARPROC farproc;
};
/**
* This class holds a bunch of loaded DLL functions (using LoadLibrary() GetProcAddress())
* and can be called if casted correctly. the order of the vector can seriously matter
*/
class HashedProcAdddresses
{
public:
//function name to to dll list -- useful for calling all functions of same name to different dlls
map < std::string, std::list<LowLevelDLLFunction> > loaded_func_to_dlls;
//DLL name to function list -- needs to be populated (can use ListDLLFunctions below)
//ie if (loaded_dll_to_funcs["mylib.dll"].find("_MyLib_DoStuff")){
// (((void*)())loaded_dll_to_funcs["mylib.dll"]["_MyLib_DoStuff"].farproc();
map < std::string, std::map<std::string, LowLevelDLLFunction> > loaded_dll_to_funcs;
};
//VCL class
class CallDLL
{
public:
HashedLibraries HashedLibs;
HashedProcAdddresses HashedDLLFuncs;
FARPROC GetFunction(const char* DLL, const char* Function, LowLevelDLLFunction* lowDLLfunc = NULL);
public:
//for loading a dll and calling a function accepting and returning a char*
AnsiString __fastcall Str_Function_Str(char* DLL, char* Function, char* arg1);
AnsiString __fastcall Str_Function_Int(char* DLL, char* Function, int arg1);
int __fastcall Int_Function(char* DLL, char* Function);
//for just calling a function which returns a string (char*)
AnsiString __fastcall Str_Function(char* DLL, char* Function);
};
bool ListDLLFunctions(AnsiString sADllName, TStringList *slListOfDllFunctions);
bool AddIfDLLFunctionExists(HANDLE DLLHandle, char* Function, TStringList* slListOfDllFunctions);
void PopulateHashedProcs(AnsiString sADllName, TStringList* slListOfDllFunctions, HashedProcAdddresses& HashedDLLFuncsToPopulate);
}
//a global CallDLL instance
extern CallDLLInterface::CallDLL GlobalAppCallDLL;
//---------------------------------------------------------------------------
#endif