怎样用程序将一个unicode big endian格式的文件转换为ansi格式?

zzh26 2006-08-15 11:17:35
如题
...全文
383 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lrq_123 2006-09-08
  • 打赏
  • 举报
回复
没看完,回去继续看
zzh26 2006-08-16
  • 打赏
  • 举报
回复
好吧,还是我自己解决了,调用的时候少写了个stdcall;

调用这么写就可以了

procedure saveaswstr(f1:string);stdcall;external 'wstr.dll';

procedure saveastxt(f2:string);stdcall;external 'wstr.dll';

斑竹帮我结束吧。
zzh26 2006-08-15
  • 打赏
  • 举报
回复
自己顶一下
wudi_1982 2006-08-15
  • 打赏
  • 举报
回复
做个记号,晚上回来看看。
zzh26 2006-08-15
  • 打赏
  • 举报
回复
我是这么写的

library wstr;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
ShareMem,
SysUtils,
Classes;


{$R *.res}


procedure saveaswstr(f1:string);stdcall; //将文件f1转换为unicode编码
var
t1:TStringList; FileStream: TFileStream;
P: pchar;
W: WideString;
begin
t1:=TStringList.Create;
t1.LoadFromFile(f1);

w := widestring(t1.Text);
p := pchar(w);
FileStream := TFileStream.Create(f1, fmCreate);
FileStream.Position := 0;
FileStream.Write(l, 2);
FileStream.Write(p^, Length(w) * 2); //Length(w)<>Length(t1.Text) ;
FileStream.Free;

t1.Clear;
t1.Free;


end;



procedure WordLoHiExchange(var w:Word);
var
b:Byte;
begin
b:=WordRec(w).Lo;
WordRec(w).Lo:=WordRec(w).Hi;
WordRec(w).Hi:=b;
end;

procedure saveastxt(f2:string);stdcall; //将unicode big endian转换为ansi格式存储
var
buffer: WideChar;
f: file of WideChar;
str: string;
w:word;
t1:TstringList;
begin
t1:=TstringList.Create;

assignfile(f, f2);
reset(f);
read(f, buffer); // 跳过unicode开头的标记
while not eof(f) do
begin
read(f, buffer);
w:=word(buffer);
WordLoHiExchange(w);
buffer:=widechar(w);

str:= str+buffer;
end;
closefile(f);

t1.Text:=str;
t1.SaveToFile(f2);
t1.Clear;
t1.Free;

end;


exports
saveaswstr,
saveastxt;

begin
end.


仍然会出错
调用是这么写的

procedure saveaswstr(f1:string);external 'wstr.dll';

procedure saveastxt(f2:string);external 'wstr.dll';
wudi_1982 2006-08-15
  • 打赏
  • 举报
回复
那咬看你DLL是如何调用了得??如果你传递了字符串,那么要uses sharemem
zzh26 2006-08-15
  • 打赏
  • 举报
回复
我自己解决了

procedure WordLoHiExchange(var w:Word);
var
b:Byte;
begin
b:=WordRec(w).Lo;
WordRec(w).Lo:=WordRec(w).Hi;
WordRec(w).Hi:=b;
end;

procedure saveastxt(f2:string);stdcall; //将unicode big endian转换为ansi格式存储
var
buffer: WideChar;
f: file of WideChar;
str: string;
w:word;
t1:TstringList;
begin
t1:=TstringList.Create;

assignfile(f, f2);
reset(f);
read(f, buffer); // 跳过unicode开头的标记

while not eof(f) do
begin
read(f, buffer);
w:=word(buffer);
WordLoHiExchange(w);
buffer:=widechar(w);
str:= str+buffer;
end;
closefile(f);

t1.Text:=str;
t1.SaveToFile(f2);
t1.Clear;
t1.Free;

end;

但是在应用程序中执行没有问题,写到dll中用其他程序调用的时候就会出问题,这是为什么啊
内容概要:本文系统研究了构网型变流器的正负序阻抗解耦特性及其在弱电网环境下的稳定性表现,重点依托Matlab/Simulink仿真平台,构建了详细的阻抗数学模型,设计了解耦控制策略,并采用小信号扫频法进行频域辨识与稳定性验证。研究深入探讨了构网型变流器与传统跟网型逆变器在正负序阻抗特性上的本质差异,结合虚拟同步发电机(VSG)等先进控制技术,分析其在抑制宽频带振荡、削弱锁相环动态耦合等方面的优越性。文中不仅提供了完整的仿真模型与MATLAB代码实现,还整合了光伏、风电、储能、微电网等多类新能源系统的阻抗建模与稳定性分析资源,形成了一套面向新型电力系统稳定性的综合性技术资料体系,具有较强的科研复现与工程参考价值。; 适合人群:面向具备电力电子、电力系统自动化、新能源并网等专业背景的研究生、高校教师及工程技术人员,特别适用于从事阻抗建模、小干扰稳定性分析、宽频振荡机理研究以及撰写高水平学术论文的科研工作者。; 使用场景及目标:①掌握构网型变流器正负序阻抗建模与扫频辨识的仿真方法;②深入理解VSG等构网型控制在弱电网中提升稳定性的内在机理;③复现顶刊论文中的阻抗分析流程与稳定性判据应用;④利用提供的成熟模型与代码加速科研进程,支撑课题研究与学术成果产出。; 阅读建议:建议结合文中提供的Simulink模型与MATLAB代码,按照“理论建模—仿真搭建—扫频激励—频响提取—Nyquist判据分析”的完整流程进行实践操作,重点关注扫频信号的注入方式、频率范围设置及阻抗曲线的物理意义解读,并参考博士论文复现案例深化对复杂动态耦合问题的理解。

830

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧