2

I have copied a newer version of GdiPlus.dll to my projects directory. However windows always loads it form

"C:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.6002.23084_x-ww_f3f35550\GdiPlus.dll"

I'm on XP.

LU RD
  • 34,438
  • 5
  • 88
  • 296
zig
  • 4,524
  • 1
  • 24
  • 68
  • The [`search order`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx) picks a library from your project's binary folder first, so put that library to your exe and it should be loaded from there. – TLama Oct 23 '14 at 12:51
  • @TLama, It is there, in my project directory with my EXE. – zig Oct 23 '14 at 13:16

2 Answers2

0

To exert complete control over DLL loading, pass the full path of the DLL to LoadLibrary.

This is viable if you use runtime linking. For load time linking you are reliant on the DLL search order. The first thing searched is the directory from where the exe loaded. That said, it is plausible that for an OS component like GDI+ it is plausible that the system will use the SxS DLL no matter what.

Your question title says "current directory" but you never want to rely on the value of the current directory when linking DLLs. The current directory's value is unpredictable.

Finally, GDI+ is a system component and I think it doubtful that providing your own GDI+ DLL is a wise move. It is quite possibly illegal too since redistribution of GDI+ is not permitted. Perhaps you are choosing the wrong solution to your problem.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • GDI+ is statically linked to the exe. there is no `LoadLibrary`. I have tried to `LoadLibrary(path_to_my_dll)` in the initialization section, but that just load 2 gdiplus dlls. regarding your "Finally" I have seen a lot of programs distributed with "gdiplus.dll". you might be right about choosing this solution, but I only want to test something for now. i.e. why same GDI+ function works ok on Vista but not on XP. – zig Oct 23 '14 at 13:33
  • And sorry, I meant current project directory containing my EXE. – zig Oct 23 '14 at 13:34
  • It is against the EULA to redistribute a Vista or later GDI+ DLL to XP. I think you'll need to find a different way around your problem. – David Heffernan Oct 23 '14 at 13:37
  • "That said, it is plausible that for an OS component like GDI+ it is plausible that the system will use the SxS DLL no matter what." It seems this is the case. can you confirm that please? I manually changed `const WINGDIPDLL = 'D:\Projects\Foo\GdiPlus.dll';` and now it loads the correct DLL (I will undo this finally). – zig Oct 23 '14 at 13:44
  • I think it's highly likely that SxS wins every time. Don't have XP here. – David Heffernan Oct 23 '14 at 13:47
  • I guess, you are trying to use the bitmap effect functions. They are part of the GDI+ 1.1 extensions. Unfortunately, WinXP doesn't ship with GDI+ 1.1. Its available on Windows Vista and higher, but if I remember, there was a certain Microsoft Office 2003 version (Plus, extended or something), providing it too. – Peter Kostov Oct 23 '14 at 13:51
  • @PeterKostov, I simply need to load an icon with GDI+ and preserve it's alpha channel which works fine on Vista but not on XP. http://stackoverflow.com/q/26486504/3906993 – zig Oct 23 '14 at 15:16
  • @DavidHeffernan, What I meant by "can you confirm that" was, is it somewhere documented that the system might choose to load a specific dll regardless of Search Order and the fact that GdiPlus.dll is not listed in KnownDLLs?: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx – zig Oct 23 '14 at 15:42
  • I expect that it is documented, but I have never been able to understand SxS or its documentation. Sorry. – David Heffernan Oct 23 '14 at 15:51
  • Are you looking for more help here? – David Heffernan Oct 24 '14 at 10:50
  • I could accept this answer if that's what you mean. but your answer still not conclusive IMHO. if SxS is "winning" a DLL which is not listed in KnownDLLs, I want to know why it does. wouldn't you? – zig Oct 24 '14 at 11:13
  • Well, the question asks how to force the loading of a specific version of a DLL. I think the paragraph deals with that. – David Heffernan Oct 24 '14 at 11:16
0

you can use this declaration to set the directory of dll to a defined path.

function SetDllDirectory(lpPathName:PWideChar): Bool; stdcall; external 'kernel32.dll' name 'SetDllDirectoryW';

remember to change the path after working with your dll.

Xor-el
  • 242
  • 4
  • 11
  • 2
    This function does not do what you seem to claim it does. It is documented here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686203.aspx – David Heffernan Oct 23 '14 at 13:28