ianhinson wrote: > --- 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;
Of course, any function that receives a pointer to a buffer should also receive a number indicating the size of that buffer. > begin > GetModuleFileName(hInstance, szModuleName) > end; I think if the program wanted to know the path of the DLL, it should just call GetModuleFileName itself. No need for the DLL to export a function for that. The EXE will already have the DLL module handle if it loaded the DLL with LoadLibrary. If the OS loaded the DLL automatically, then the EXE can find out the module handle by calling GetModuleHandle. -- Rob

