1

Topic: How to cause function in DLL

Is DLL.
[spoiler a source code on With ++]

#ifndef _ICiFbEncActivator_H_
#define _ICiFbEncActivator_H_
#if (defined (WIN32) || defined (_WIN32) || defined (__ WIN32 __)) &&! defined (__ MINGW32 __)
#define CALL_CONV __ stdcall
#define CI_LIB_EXP __ declspec (dllexport)
#define NO_VTBL __ declspec (novtable)
#else
#define CALL_CONV
#define CI_LIB_EXP
#define NO_VTBL
#endif
#define CI_LIB_API extern "C" CI_LIB_EXP
enum CIErrors
{
Err_OK = 0;
Err_IncorrectCall =-1;
Err_IncorrectSize =-2;
Err_CantAllocMemory =-3;
Err_AlreadyInSameState =-4;
Err_FirebirdState =-5;
Err_IncorrectParam =-6;
Err_NullPointer =-7
};
namespace CI {
#pragma pack (push, 1)
struct DBEncInf
{
size_t PageSize;
size_t PagesCount;
size_t ProcessedPage;
bool isEncrypted;
bool inProcess;
};
#pragma pack (pop)
class CI_LIB_EXP NO_VTBL ICiFbEncActivator
{
public:
virtual int32_t CALL_CONV SetKey (const void *pKey, size_t nKeyLen) = 0;
virtual int32_t CALL_CONV SetDBAccess (const char* pDBAlias, const char* pDBLogin, const char* pDBPass) = 0;
virtual int32_t CALL_CONV Activate (void) = 0;
virtual int32_t CALL_CONV Encrypt (void) = 0;
virtual int32_t CALL_CONV Decrypt (void) = 0;
virtual int32_t CALL_CONV GetState (DBEncInf& inf) = 0;
virtual int32_t CALL_CONV GetStateSVC (char* pBuf, size_t& nBuf) = 0;
virtual int32_t CALL_CONV GetFBStat (char* pBuf, size_t& nBuf) = 0;
virtual void CALL_CONV Destroy (void) = 0;
};
}
#endif

[/spoiler]
[spoiler a source code on Delfi]

unit CI.ICiFbEncActivator;
interface
type
DBEncInf = record
PageSize: NativeUInt;
PagesCount: NativeUInt;
ProcessedPage: NativeUInt;
isEncrypted: Boolean;
inProcess: Boolean;
end;
ICiFbEncActivator = class
function SetKey (const pKey: Pointer; nKeyLen: NativeUInt): Integer; virtual; stdcall; abstract;
function SetDBAccess (const pDBAlias: PAnsiChar; const pDBLogin: PAnsiChar; const pDBPass:
function Activate: Integer; virtual; stdcall; abstract;
function Encrypt: Integer; virtual; stdcall; abstract;
function Decrypt: Integer; virtual; stdcall; abstract;
function GetState (var inf: DBEncInf): Integer; virtual; stdcall; abstract;
function GetStateSVC (pBuf: PAnsiChar; var nBuf: NativeUInt): Integer; virtual; stdcall; abstract;
function GetFBStat (pBuf: PAnsiChar; var nBuf: NativeUInt): Integer; virtual; stdcall; abstract;
end;
TActivatorFunction = function (out ppEncActivator: ICiFbEncActivator): Integer; stdcall;
const
Err_OK = 0;
Err_IncorrectCall =-1;
Err_IncorrectSize =-2;
Err_CantAllocMemory =-3;
Err_AlreadyInSameState =-4;
Err_FirebirdState =-5;
Err_IncorrectParam =-6;
Err_NullPointer =-7;
implementation
end.

[/spoiler]
How it is correct in  to cause these functions?

2

Re: How to cause function in DLL

I will continue.
There is an example decisions .
[spoiler a source code With ++]

//Loadable module
std:: unique_ptr <HINSTANCE __, decltype (&::FreeLibrary)> mHandle (
:: LoadLibraryEx (L "C: \\TESTAPP \\CiFbEnc_x86.dll", 0, LOAD_WITH_ALTERED_SEARCH_PATH);
&:: FreeLibrary);
if (! mHandle)
{
MessageBox (
NULL;
L "the Unit CiFbEnc_x86.dll is not found or near to it is not present fbclient.dll";
L "unit Loading";
MB_OK|MB_ICONERROR);
return;
}
//we Receive the activator
typedef CALL_CONV int (__ stdcall *CREATEFUNCPTR) (CI:: ICiFbEncActivator **);
CREATEFUNCPTR GetActivator =
(CREATEFUNCPTR):: GetProcAddress (mHandle.get (), "createCiFBEncActivator");
if (! GetActivator)
{
MessageBox (
NULL;
L "it was not possible to receive from the unit CiFbEnc_x86.dll procedure"
"createCiFBEncActivator"
"- Try to look that writes tdump.";
L "unit Loading";
MB_OK|MB_ICONERROR);
return;
}
CI:: ICiFbEncActivator* pActivator = NULL;
GetActivator (&pActivator);
if (! pActivator) {ShowMessage ("ERROR GetActivator!"); return;}
//...
//an example of reversal to object of the unit of activation
//...
pActivator-> SetDBAccess ("localhost:TESTDB", "SYSDBA", "masterkey");
char stat_buf [1024] = {0};
size_t bufsize = sizeof (stat_buf);
int res = pActivator-> GetStateSVC (stat_buf, bufsize);
String sStatMsg = (String) stat_buf;
if (Err_OK == res)
{
MessageBox (NULL, sStatMsg.c_str (), L "the DB Status", MB_OK|MB_ICONINFORMATION);
}
else
{
String sErrMsg = L "ERROR GetStateSVC:" + sStatMsg;
MessageBox (
NULL;
sErrMsg.c_str ();
L "the DB Status";
MB_OK|MB_ICONERROR);
}
. . .
//we Destroy an activator copy
pActivator-> Destroy ();
pActivator = NULL;

[/spoiler]
[spoiler a source code of Delfi]

var
pActivator: ICiFbEncActivator;
res: Integer;
CreateActivator: TActivatorFunction;
mHandle: HINST;
. . .
begin
//Loadable module
mHandle: = LoadLibraryEx (
PChar (' C:\TESTAPP\CiFbEnc_x86.dll '), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
if mHandle = 0 then
begin
MessageBox (
Application. Handle;
' the Unit CiFbEnc_x86.dll is not found or near to it is not present fbclient.dll ';
' ' unit Loading;
MB_OK OR MB_ICONERROR);
Exit;
end;
//we Receive the activator
CreateActivator: = GetProcAddress (mHandle, ' createCiFBEncActivator ');
if not Assigned (CreateActivator) then
begin
MessageBox (
Application. Handle;
' it was not possible to receive from the unit CiFbEnc_x86.dll procedure createCiFBEncActivator'
+
' - try to look that writes tdump. ';
' ' unit Loading;
MB_OK OR MB_ICONERROR);
Exit;
end;
pActivator: = nil;
res: = CreateActivator (pActivator);
if not Assigned (pActivator) then begin ShowMessage (' ERROR CreateActivator! '); Exit; end;
//...
//an example of reversal to object of the unit of activation
//...
var
. . .
stat_buf: array [0. 1023] of AnsiChar;
bufsize: NativeUInt;
. . .
res: = pActivator. SetDBAccess (' localhost:TESTDB ', ' SYSDBA ', ' masterkey ');
bufsize: = SizeOf (stat_buf);
ZeroMemory (@stat_buf, bufsize);
res: = pActivator. GetStateSVC (stat_buf, bufsize);
if Err_OK = res then
begin
MessageBox (Application. Handle, PChar (String (stat_buf));
' the DB Status ', MB_OK OR MB_ICONINFORMATION);
end
else
begin
MessageBox (Application. Handle, PChar (String (stat_buf));
' the Error ', MB_OK OR MB_ICONERROR);
end;
//...
//we Destroy an activator copy
pActivator. Destroy;
pActivator: = nil;
FreeLibrary (mHandle);
end;

[/spoiler]
[spoiler partially translated on ]

//access obtaining to the interface of the unit of activation
long ll_handle, ll_CreateActivator
string ls_path
boolean lb_freelib
ls_path = ' C:\TESTAPP\CiFbEnc_x86.dll'
//Loadable module
ll_handle = LoadLibrary (ls_path)
if ll_handle=0 then
MessageBox ("unit Loading", and
"The unit CiFbEnc_x86.dll is not found or near to it is not present fbclient.dll", and
StopSign!)
RETURN
end if
//we Receive the activator
ll_CreateActivator = GetProcAddress (ll_handle, ' createCiFBEncActivator ')
if IsNull (ll_CreateActivator) then
MessageBox ("activator Obtaining", and
"It was not possible to receive from the unit CiFbEnc_x86.dll procedure createCiFBEncActivator" + and
"~n - try to look that writes tdump.", and
StopSign!)
GOTO str_return
end if
/*
Here complexity of transfer on  "reversal to object of the unit of activation"
*/
str_return:
//we Release the unit
lb_freelib = FreeLibrary (ll_handle)
if NOT lb_freelib then
MessageBox ("unit Clearing", and
"The unit CiFbEnc_x86.dll has not been released", and
StopSign!)
end if

[/spoiler]
Who can that prompt as a fragment "reversal to object of the unit of activation" in an example to translate on ? Or can eat other candidate solution?

3

Re: How to cause function in DLL

12/10/2017 17:37, AIS writes:
> How it is correct in  to cause these functions?
In any way. And to the one who exported from DLL a class, it is necessary to hammer in a nail into a head.

4

Re: How to cause function in DLL

Dim2000 wrote:

12/10/2017 17:37, AIS writes:
> How it is correct in  to cause these functions?
In any way. And to the one who exported from DLL a class, it is necessary to hammer in a nail into a head.

And except "nail" something else advise?))

5

Re: How to cause function in DLL

Council standard - to write "wrapper" on With ++ which can be picked up in .

6

Re: How to cause function in DLL

12/11/2017 14:03, AIS writes:
> And except "nail" something else advise?))
I not absolutely understand, why it works in Delfi (though a guess
Is available), and you want, that I knew, how it to force to work in ...

7

Re: How to cause function in DLL

Dim2000 wrote:

I not absolutely understand, why it works in Delfi (though a guess
Is available), and you want, that I knew, how it to force to work in ...

You it is exact not from Moscow, and is faster from Odessa...)))

8

Re: How to cause function in DLL

Dim2000 wrote:

I not absolutely understand, why it works in Delfi (though a guess
Is available), and you want, that I knew, how it to force to work in ...

Works because classes in  are specially made is binary compatible with COM Windows interfaces.
And COM-interfaces it also are classes With ++ with the virtual functions.

Dim2000 wrote:

In any way. And to the one who exported from DLL a class, it is necessary to hammer in a nail into a head.

))
. AIS, write wrappers on With ++.

9

Re: How to cause function in DLL

Anatoly Moskovsky;
I already and understood that variants of others are not present.