Thread View: borland.public.delphi.teamsource
1 messages
1 total messages
Started by roygbiv
Tue, 23 Mar 2004 11:14
Interfacing with a VB .dll
Author: roygbiv
Date: Tue, 23 Mar 2004 11:14
Date: Tue, 23 Mar 2004 11:14
108 lines
3710 bytes
3710 bytes
I am trying to interface with a .dll written in vb.
The instructions are as follows :
SHA1_StringHexHash
SHA1_StringHexHash creates a SHA-1 message digest in hexadecimal format from a message of String type.
Syntax
Public Declare Function SHA1_StringHexHash Lib "diCrHash.dll" (ByVal sDigest As String, ByVal sMessage As String) As Long
iRet = SHA1_StringHexHash(sDigest, sMessage)
Parameters
sDigest String to receive message digest.
sMessage String containing the message to be hashed.
Returns
Long: If successful, the return value is 0; otherwise it returns a non-zero error code.
Remarks
sDigest must be at least 40 characters long (41 characters in a C program).
Example
Dim iRet As Long
Dim sDigest As String
' Set sDigest to be 40 chars
sDigest = String(40, " ")
iRet = SHA1_StringHexHash(sDigest, "abc")
Debug.Print sDigest
iRet = SHA1_StringHexHash(sDigest, _
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
Debug.Print sDigest
This should result in output as follows:
a9993e364706816aba3e25717850c26c9cd0d89d
84983e441c3bd26ebaae4aa1f95129e5e54670f1
How do I translate this into a Delphi form?
My current example below does not return a result :
unit main_Frm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
// encryption parameters
// TSHA1_StringHexHash = function ( s : string; t : string ): string;
TSHA1_StringHexHash = procedure(s : string; t : string); stdcall; // VERY NB! Stdcall must be used here, not cdecl
TMainFrm = class(TForm)
BitBtn1: TBitBtn;
Edit1: TEdit;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
// variables to used for encryption below
hndDLLHandle: THandle;
// hash_res: TACBencfile;
// param_ptr : string;
SHA1_StringHexHash : TSHA1_StringHexHash;
// SHA1_StringHexHashfunc : TSHA1_StringHexHashfunc;
end;
var
MainFrm: TMainFrm;
implementation
{$R *.dfm}
procedure TMainFrm.BitBtn1Click(Sender: TObject);
var
sdigest : string[41];
result : string[41];
begin
// load dll in dynamic type(mode)
hndDLLHandle := loadLibrary ( 'diCrHash.dll' );
if hndDLLHandle <> 0 then
begin
// get function address
@SHA1_StringHexHash := getProcAddress ( hndDLLHandle, 'SHA1_StringHexHash' );
if addr(SHA1_StringHexHash) <> nil then
begin
// Procedure called
@SHA1_StringHexHash := getProcAddress ( hndDLLHandle, 'SHA1_StringHexHash' );
SHA1_StringHexHash(sDigest, 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq');
result := sDigest;
end
else
begin
MessageDlg('procudure not able to be called', mtInformation,[mbOk], 0);
end;
end
else
begin
MessageDlg('function not able to be called', mtInformation,[mbOk], 0);
end;
edit1.Text := result;
end;
end.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads