【发布时间】:2015-08-24 22:42:53
【问题描述】:
我使用 Delphi 2010 中的资源 DLL 向导为我的程序生成仅资源 dll。当我使用 Notepad++ 查看它们时,它们似乎使用的是 ANSI 编码。我错过了一些设置吗? unicode 程序似乎不应该将其资源存储在 ANSI 中,尤其是对于亚洲语言。
我专门查看了 TABOUTBOX RT_RCDATA 记录。我尝试使用以下代码加载它,
procedure LoadFromResFile(const FileName: string);
var
LibHandle: THandle;
ResourceLocation: HRSRC;
ResourceSize: dword;
ResourceHandle: THandle;
ResourcePointer: pointer;
ResStr: string;
begin
LibHandle := LoadLibraryEx(PWideChar(FileName), 0, LOAD_LIBRARY_AS_DATAFILE or LOAD_LIBRARY_AS_IMAGE_RESOURCE);
if LibHandle > 0 then
begin
ResourceLocation := FindResource(LibHandle, 'TABOUTBOX', RT_RCDATA);
ResourceSize := SizeofResource(LibHandle, ResourceLocation);
ResourceHandle := LoadResource(LibHandle, ResourceLocation);
ResourcePointer := LockResource(ResourceHandle);
if ResourcePointer <> nil then
begin
SetLength(ResStr, ResourceSize);
CopyMemory(@ResStr[1], ResourcePointer, ResourceSize);
FreeResource(ResourceHandle);
end;
FreeLibrary(LibHandle);
end else
begin
ResStr := SysErrorMessage(GetLastError);
ShowMessage(ResStr);
end;
我得到了垃圾,但是当我将 ResStr 的类型更改为 AnsiString 时,它显示正确。在 Notepad++ 中打开文件我可以看到对话框资源似乎是 ansi,包括标签标题。
【问题讨论】:
-
字符串资源总是以 Unicode 格式存储(参见The format of string resources)。这是规范的一部分。是什么让您认为它们是 ANSI?
-
@Remy - Old New Thing 文章专门针对 RT_STRING 资源。在这种情况下,资源是一个 RT_RCDATA(应用程序定义)。
-
相关资源是二进制 DFM 资源,而不是字符串资源。
标签: delphi localization translation delphi-2010