Delphi XE2: Invoke WinAPI EnumResourceNames cause access violation in Win64 platform -



Delphi XE2: Invoke WinAPI EnumResourceNames cause access violation in Win64 platform -

running next code in delphi xe2 win32 platform works. however, same code compile in win64 platform cause access violation in "enumrcdataproc" if run in debug mode:

procedure tform2.button1click(sender: tobject); function enumrcdataproc(hmodule: thandle; lpsztype, lpszname: pchar; lparam: nativeint): boolean; stdcall; begin tstrings(lparam).add(lpszname); result := true; end; var k: nativeint; l: tstringlist; h: thandle; begin h := loadpackage('resource.bpl'); l := tstringlist.create; seek enumresourcenames(h, rt_rcdata, @enumrcdataproc, nativeint(l)); showmessage(l.text); l.free; unloadpackage(h); end; end;

when debug code in delphi xe2 ide on win64 platform, found value of hmodule in enumrcdataproc doesn't match variable h. suspect might wrong parameters constructed enumrcdataproc. however, can't figure out how. ideas?

the problem have made enumrcdataproc local procedure. need move outside method.

function enumrcdataproc(hmodule: hmodule; lpsztype, lpszname: pchar; lparam: nativeint): bool; stdcall; begin tstrings(lparam).add(lpszname); result := true; end; procedure tform2.button1click(sender: tobject); var k: nativeint; l: tstringlist; h: hmodule; begin h := loadpackage('resource.bpl'); l := tstringlist.create; seek enumresourcenames(h, rt_rcdata, @enumrcdataproc, nativeint(l)); showmessage(l.text); l.free; unloadpackage(h); end; end;

on first inspection expected compiler emit error code:

e2094 local procedure/function 'callback' assigned procedure variable

but not so. dug little deeper , discovered callback parameter enumresourcenames declared type pointer. if header translation had declared typed callback parameter above error message indeed have been emitted. mind header translation poor in regard. there seems little gained abandoning safety of type system.

the fact code works in 32 bit code happy coincidence relies on implementation details. luck runs out on 64 bit. again, if type checking scheme had been enabled, compiler have told wrong immediately.

some other comments:

the enumrcdataproc has couple of wrong types in declaration: hmodule should of type hmodule , function result should bool. loadpackage rather heavyweight approach getting module handle. prefer see loadlibraryex load_library_as_datafile_exclusive , load_library_as_image_resource options.

delphi delphi-xe2

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -