【发布时间】:2011-09-23 21:40:51
【问题描述】:
德尔福 Xe,Win7x64
请求已知编号的字符串资源:
Function GuGetStrRes(Fn:string;Nom:integer):string;
var
h:THandle;
buffer:array [0..255] of Char;
begin
Result:='';
if fileexists(Fn)=false then
exit;
Try
h:=LoadLibraryEx(pchar(Fn),0,LOAD_LIBRARY_AS_DATAFILE);
if h=0 then
exit;
if LoadString(h, Nom, buffer, SizeOf(buffer)) > 0 then
Result:=string(buffer);
FreeLibrary(h);
Except
Try
if h<>0 then
FreeLibrary(h);
except
end;
End;
End;
// Use
Showmessage(GuGetStrRes('c:\windows\system32\shell32.dll',4200));
问题:如何在 DLL 中学习所有数量的“字符串”资源?比如接收一个数组:11,22,23,24,40000等等(不能一个接一个)
试过了:
...
var
dllname, str:string;
begin
dllname: ='c:\windows\system32\shell32.dll';
str: = ";
For i: = 0 to 10000 do
begin
str: = GuGetStrRes (dllname, i);
if str <> " then
memo1.lines.add (inttostr (i) + ' - ' +str);
end;
end;
但由于某种原因,当i: = 4201 :(
当i=0..4200 和>4210 时,一切正常。
【问题讨论】:
-
“它会导致错误”在不知道确切错误和错误消息的内容的情况下意味着什么。请编辑您的帖子并提供该信息;如果有的话,我们可以更轻松(更快)地提供帮助。
-
如果那是您尝试过的代码,那么它不起作用也就不足为奇了。它甚至没有编译!
-
"如果 fileexists(Fn)=false then",真的吗?
-
旁白。不要使用 try/except 来管理生命周期。使用 try/finally。
标签: delphi