delphi - Using C++ DLL in D10 -
i use c++ dll in app.
type tcl_bla = function(filename: pchar): integer; cdecl; var cl_bla: tcl_bla; function calllibraryproc(proc: string): pointer; begin result := getprocaddress(handle, pchar(proc)); if not assigned(result) loaded := false; if not loaded messagebox(0, pchar('error => ' + proc), 'alert', mb_ok or mb_topmost); end; ... handle := safeloadlibrary( pchar(currentpath + dll), sem_failcriticalerrors or sem_nogpfaulterrorbox or sem_noopenfileerrorbox ); if (handle < hinstance_error) raise exception.create( dll + ' library can not loaded or not found.' + syserrormessage(getlasterror) ); if handle <> 0 begin // blabla cl_bla := calllibraryproc('cl_bla'); end; ... freelibrary(handle);
the codes aboves works fine d6. i'm trying port code can run in delphi unicode support have trouble.
i've read documentation embarcadero getprocaddress
procedure calllibraryproc(const libraryname, procname: string); var handle: thandle; registerproc: function: hresult stdcall; begin handle := loadolecontrollibrary(libraryname, true); @registerproc := getprocaddress(handle, pansichar(ansistring(procname))); end;
i can't try because don't know how declare loadolecontrollibrary!
my calllibraryproc can load dll somehow cl_bla works incorrectly.
i think problem code because of getprocaddress's parameter or.. maybe ported header wrong.
i may post this answer, because seems answer!
the code d6 code work fine unmodified in d2010, , have same meaning. there 2 getprocaddress
overloads in windows.pas. 1 of them converts unicode ansi. can call getprocaddress(handle, pchar(proc))
did.
the magic 1 looks this:
function getprocaddress(hmodule: hmodule; lpprocname: lpcwstr): farproc; begin if ulong_ptr(lpprocname) shr 16 = 0 // is_intresource result := getprocaddress(hmodule, lpcstr(lpprocname)) else result := getprocaddress(hmodule, lpcstr(ansistring(lpprocname))); end;
Comments
Post a Comment