我正在撰写一份C#应用程序,与一台硬件传感器连接起来。 不幸的是,在装置上暴露的唯一接口需要在Delphi提供一张纸张。
I am writing a Delphi executable wrapper that takes calls the necessary functions for the DLL and returns the sensor data over stout. However, the return type of this data is a PWideChar (or PChar) and I have been unable to convert it to ansi for printing on command line.
如果我直接将数据传递给书写,我就每个特点获得数据。 如果我看一看各种特性,并试图在阿尼西转换时加以打印,那么只有几种文字(这些字的确证实了数据,但往往按顺序打印。 (用指数印出的只是跳跃。) 我也试图将PWideChar改成简单分类:我相当于21321。 我可能列举所有转换,但有些数据具有多种价值。
I am unsure of what version of Delphi the dll uses, but I believe it is 4. Definately prior to 7.
任何帮助都值得赞赏。
TLDR: 需要转换UTF-16 PWide Char to AnsiString forprint.
<>Example application:
program SensorReadout;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Windows,
SysUtils,
dllFuncUnit in dllFuncUnit.pas ; //This is my dll interface.
var state: integer;
answer: PChar;
I: integer;
J: integer;
output: string;
ch: char;
begin
try
for I := 0 to 9 do
begin
answer:= GetDeviceChannelInfo_HSI(1, Ord( a ), I, state); //DLL Function, returns a PChar with the results. See example in comments.
if state = HSI_NO_ERRORCODE then
begin
output:= ;
for J := 0 to length(answer) do
begin
ch:= answer[J]; //This copies the char. Originally had an AnsiChar convert here.
output:= output + ch;
end;
WriteLn(output);
end;
except
on E: Exception do
Writeln(E.ClassName, : , E.Message);
end;
ReadLn(I);
end.`
问题是,PransiChar需要成为从DLLL公司获得的职能的返回类型。