Discussion:
TIdHashMessageDigest5 and BCB 6
(too old to reply)
Lapo Guidi
2006-06-27 11:57:53 UTC
Permalink
Hi all,
I got problems getting the MD5 value of a simple String with Borland C++
Builder 6 and Indy v9, can somebody help me?
I wrote:

T4x4LongWordRecord Hash;
AnsiString Hex;
TIdHashMessageDigest5 *MD5=new TIdHashMessageDigest5();
Hash=MD5->HashValue("testmessage");
Hex=MD5->AsHex(NULL, Hash);

delete MD5;

I received an error: E2277 Lvalue required on the
"Hash=MD5->HashValue("testmessage"); row

Thanks!

Lapo
Andrue Cope [TeamB]
2006-06-27 12:36:40 UTC
Permalink
Lapo Guidi wrote:

That error message means that the compiler was expecting to assign a
value into something and the something you gave it isn't something that
can be assigned to.
Post by Lapo Guidi
T4x4LongWordRecord Hash;
AnsiString Hex;
TIdHashMessageDigest5 *MD5=new TIdHashMessageDigest5();
Hash=MD5->HashValue("testmessage");
I haven't used Indy but looking at the online docs it appears that
HashValue() returns an array of 32 bit values. That means you're trying
to assign to an array which is not allowed in C++ eg;

typedef DWORD array[ 4 ] Tbaddy;

Tbaddy someFunction();

Tbaddy array=someFunction();
// An array cannot be assigned to hence is not a valid Left Hand Side
// of an expression

Then again why call it 'T4x4LongWord/Record/' if it is an array?

Presumably there is some C++ specific workaround implemented - what
does the C++ specific documentation say for HashValue() and
T4x4LongWord?
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Lapo Guidi
2006-06-27 13:05:14 UTC
Permalink
Post by Andrue Cope [TeamB]
Presumably there is some C++ specific workaround implemented - what
does the C++ specific documentation say for HashValue() and
T4x4LongWord?
Thanks for the fast reply.
Unfortunately I'm not able to find C++ specific documentation.
I found many people asking for a C++ example, but I can see just Delphi
examples.
Anyway, I'll try to find another MD5 library.

Thank you very much

Lapo
Andrue Cope [TeamB]
2006-06-27 13:53:13 UTC
Permalink
Post by Lapo Guidi
Thanks for the fast reply.
Unfortunately I'm not able to find C++ specific documentation.
I found many people asking for a C++ example, but I can see just
Delphi examples. Anyway, I'll try to find another MD5 library.
Well you can use Goto declaration to find out how T4x4LongWordRecord is
declared. That might give an indication of how they get around it.
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Lapo Guidi
2006-06-27 16:33:30 UTC
Permalink
Post by Andrue Cope [TeamB]
Well you can use Goto declaration to find out how T4x4LongWordRecord is
declared. That might give an indication of how they get around it.
This is the T4x4LongWordRecord declaration:
T4x4LongWordRecord = array [0..3] of LongWord;
Remy Lebeau (TeamB)
2006-06-27 17:35:09 UTC
Permalink
Post by Lapo Guidi
T4x4LongWordRecord = array [0..3] of LongWord;
In C++, it comes out as the following:

typedef unsigned T4x4LongWordRecord[4];

The declaration for T4x4x4LongWordRecord in C++ comes out as follows:

typedef unsigned T4x4x4LongWordRecord[4][4];

Functions in C++ can't return array values. However, if you look at the
declaration for HashValue() itself in C++, it does not return an array at
all:

unsigned __fastcall HashValue(const AnsiString ASrc);

What you can try doing is to add a Delphi .pas file to your C++ project, and
have that file call HashValue() and return the array in a manner that C++
can handle. For example (untested):

--- HashValueUnit.pas ---

unit HashValueUnit;

uses
IdHashMessageDigest5;

interface

procedure MD5HashValue(MD5: TIdHashMessageDigest5; const S: String; var
Hash: PLongWord);

implementation

procedure MD5HashValue(MD5: TIdHashMessageDigest5; const S: String;
Hash: PLongWord);
var
Tmp: T4x4LongWordRecord;
begin
Tmp := MD5.HashValue(S);
Move(Tmp[0], Hash, SizeOf(LongWord)*4);
end;

end.


--- MyForm.cpp ---

#include "HashValueUnit.hpp"

{
//...
TIdHashMessageDigest5 *MD5 = new TIdHashMessageDigest5;

T4x4LongWordRecord Hash;
MD5HashValue(MD5, "testmessage", Hash);

AnsiString Hex = MD5->AsHex(__classid(TIdHashMessageDigest5), Hash);
//...
}


Gambit

Loading...