|
|
От: |
Nuald
|
http://nuald.blogspot.com |
| Дата: | 09.10.06 02:11 | ||
| Оценка: | |||
АТ>function Test(const TestStr : string) : string;
АТ>АТ>lh := LoadLibrary("Plugin1.dll");
АТ>GetProcAddress(lh, "Test");
АТ>There is no way to specify where you would like DLLImport to look for a file at runtime. There is, however, a trick that you can use to get this to work.
DllImport calls LoadLibrary() to do its work. If a specific DLL has already been loaded into a process, LoadLibrary() will succeed, even if the specified path for the load is different.
This means that if you call LoadLibrary() directly, you can load your DLL from wherever you want, and then the DllImport LoadLibrary() will use that version.
Because of this behavior, it's possible that LoadLibrary() can be called ahead of time to forward your calls to a different DLL. If you're writing a library, you can prevent this by calling GetModuleHandle() to make sure that the library hasn't been loaded previously before you make your first P/Invoke call.