EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SendNote D2010

Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.
Posted: 09/28/2011 08:10:46
by Henrik Lyder (Standard support level)
Joined: 02/02/2010
Posts: 8

I'm in the process of moving some older code from a D5 implementation to D2010. The D5 code was essentially built on the SendNote demo. When I compile the SendNote demo in D2010 the result is in error. The strings sent from one instance of SendNote to another is garbled on the way. I tried to redefine the strings as ansistring no change. I have attached a screenshot of the test harness right after the "send". Th expected text is "Test Message" but it appears to be arriving in some foreign language.

My end product consist of 2 programs running over a network communicating using the socket transport. I need to have the old D5 project be able to communicate to the part of the project that is being upgraded - is there a problem I need to know about when attempting this?

Posted: 09/28/2011 08:21:23
by Eugene Mayevski (EldoS Corp.)

1) There's a typo bug in CreateMessageFromText() method in Pascal code package. There's an overloaded method there for Unicode, and this overloaded method sets message length as

Result.DataSize := Length(Text) + 2;

but it should be

Result.DataSize := Length(Text) * 2;

We've noticed and fixed the problem only recently, after build 72, so you would need to either replace call to this method with your own similar code or change the method itself and recompile it.

2) There exist two CreateMessageFromText methods - one with String parameter and another one with AnsiString parameter. None of them performs ANSI <-> Unicode conversion (this is by design), so you need to pay attention to such conversions yourself.

To summarize:

Migrating to Unicode requires some work on your side (in your code). If you need interoperability with old versions of your software, you would need to decide what to do - either send both ANSI and Unicode variants of text (in this case you will have to replace a call to CreateMessageFromText with your own code) or just keep ANSI text.

I debugged Android code package recently and tested it with Delphi code and it worked fine other than this Unicode conversion which is not done.

Sincerely yours
Eugene Mayevski
Posted: 09/28/2011 11:21:04
by Henrik Lyder (Standard support level)
Joined: 02/02/2010
Posts: 8

I am going to stay with ansistring so I have compatibility with the older code. When I receive a message in the OnMessage handler I have the code

S: ansistring;
S := Messenger.GetMessageSource(Message);
if (Message.Data <> nil) and (Message.DataSize > 0) then
SetString(S, PChar(Message.Data), Message.DataSize);
Handled := true;

but I do not get the expected result when the sender is using the ansistring.. The datasize is correct but I do not get the data.

Posted: 09/28/2011 11:43:29
by Eugene Mayevski (EldoS Corp.)

PChar is PUnicodeChar in Unicode Delphi . You need to use PAnsiChar instead.

Sincerely yours
Eugene Mayevski



Topic viewed 3174 times

Number of guests: 2, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!