On 17-09-2011 09:56, Francois PIETTE wrote:
I see. The idea is the usage of the widestring just as a easy way to
call the, behind the scene, SysAllocString and SysFreeString, that we
need in this case. But we can always treat it as a buffer, setting
its length, and moving data, explicitly, without casting.
In my opinion, it is ALWAYS a bad idea to use a string variable
(whatever string flavour it is) to store anything else than actual
text data.
Yep, but without a better data type, with the same, behind the scenes,
allocation/reallocation/deallocation/... magic, make it handy, even if
potentially problematic, if not used correctly.
Another method that should work for this problem, and that maintain some
of the magic of the WideString method.
DLL
______________________________________________________________________
iRawData = interface(IInterface)
function getData: string;
procedure setData(data:string);
property data:string read getData write setData;
end;
function ReadMessage(msg:iRawData):boolean; stdcall;
begin
EnterCriticalSection(CritSectn);
if (NotesList.Count> 0) then
begin
msg.data := NotesList.Strings[0];
NotesList.Delete(0);
Result := true;
end
else
Result := false;
LeaveCriticalSection(CritSectn);
end;
APP
______________________________________________________________________
iRawData = interface(IInterface)
function getData: string;
procedure setData(data:string);
property data:string read getData write setData;
end;
TRawData = class(TInterfacedObject, iRawData)
fdata: string;
function getData: string;
procedure setData(data:string);
end;
function ReadMessage(msg:iRawData):boolean; stdcall; external
"MyDll.dll"
...
...
var
msg:iRawData;
begin
msg:=TRawData .create; //this initialization need is the only
annoying thing
if ReadMessage(msg) then
something:=msg.data;
end;
I'm using a string as data older because in this specif case the data
source is a string too.
I'm excluding the TRawData implementation here, but there is nothing
special about it.
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be