--- In [email protected], "Workshop Alex" <[EMAIL PROTECTED]> wrote: > > function GetModuleName: string; > var > NameBuffer: array[ 0..MAX_PATH ] of char; > begin > ZeroMemory( @NameBuffer, SizeOf( NameBuffer ) ); > GetModuleFileName( HInstance, NameBuffer, Pred( SizeOf( NameBuffer ) ) ); > Result := NameBuffer; > end; > That function works ok if the DLL itself wants to know what its name and path is. But if the calling program want the DLL to report back where it is located it would best be done like this:
procedure GetModuleName(szModuleName: PChar); stdcall; begin GetModuleFileName(hInstance, szModuleName) end; The caller is responsible for allocating the buffer and freeing after its no longer needed. But that's fairly standard procedure when calling functions in DLLs. Although Borland has provided a DLL to get around the problem of passing and returning strings to/from DLL functions, I reckon it's easiest just to avoid the problem by using PChar instead of strings in exportable function or procedure calls.

