DLL ____ - how do you specify which dll version to load?


  •      I have written a program that uses Direct2D.  It runs fine on my development computer, which is running the Windows 7 RC, however, in order for it to be usefull, it really needs to be able to run on windows XP.  The problem is that Direct2D is not supported on XP.  It seems to me though that a workaround is viable, I just cannot quite figure out how to do it.
         In order to use Direct2D, my program has to link to D2D1.dll, a \system32 dll included with windows 7, and so to make the program run on XP, I copy this dll to the application folder on the XP machine.  Unfortunately D2D1.dll is dependant upon msvcrt.dll (another \system32 dll), a dll that exists on both the XP and Windows 7 machines, but it is not compatable with the XP version (as it does not include functions like _ftol2).  I am extremely hesitant to overwrite the \system32 file for fear that it will cause problems for other programs on the XP machine.  (Is this hesitancy reasonable?  Would the later version be pretty much guarenteed to be backwards compatable?  If so, then that should solve my problem.)  Thus the preferable solution would be to copy the Windows 7 version (V 7.0.7100.0) of msvcrt.dll to my application folderon the XP machine along with D2D1.dll.  Of course, simply doing this, the loader will pick up the dll in the \system32 folder before the version in the application folder, and the program will not run. 
         I have tried using a .local file to force the loader to check the application folder first, however this approach does not work for two reasons:  1) My application uses a .manifest file to target the VC runtime library (msvcr90.dll, I believe), and so I have heard, a local file is ignored if a manifest is present.  2)  So I have heard, local files do not work to redirect certain 'known' microsoft dlls, of which msvcrt.dll is one.
         I better solution would be to use the manifest file to specify which versio of msvcrt.dll to load, however it isn't entirely clear to me how to do this.  I have fooled around with my project settings, yet cannot get it to work.  (can someone perhaps point me to exactly which field(s) I would have to modify to get it to automatically include a dependancy in the manifest?)  I have also tried manually editing the .manifest file.  From what I have read, the requsite tag would be something along the lines of...

        <assemblyIdentity type="win32" name="msvcrt.dll" version="7.0.7100.0" processorArchitecture="x86" publicKeyToken="????????????????"></assemblyIdentity>

    (is this the correct syntax/placement?)  Unfortunately, I do not know how to find the publicKeyToken for the dll.  I have searched online to no avail, and I have used SN.exe but it tells me that "msvcrt.dll does not represent a strongly named assembly."  I have also tried a null publicKeyToken, and the program does not run.  ("the program has failed to start because the side-by-side configuration is incorrect.")  What I gather from this is that msvcrt.dll is not intended to be used as a sxs assembly.  And so... Am I doing something wrong here or can this dll simply not be redirected?

         In my desparation, I have also tried renaming the Windows 7 version of msvcrt.dll and directly altering D2D1.dll so as to make it dependant on the renamed version by opening D2D1.dll in notepad and changing both occurances of msvcrt.dll in that file.  This however, seems to completely corrupt D2D1.dll.  (depends.exe was no longer able to locate the entry point, and thought it was a 16 bit file.)  It is not clear to me why this tactic does not work, especailly considering that I was careful to preserve the character count of the instances I edited, so as not to corrupt the relative address values in the bobject code.  And so lastly, if noone can propose a better solution along the lines of the manifest file, can someone confirm that it is impossible / suggest a means to manually alter D2D1's dependance on msvcrt to another (possibly differently named) version of msvcrt?

     - Thank you for your time
    Friday, August 14, 2009 10:25 PM


  • For your scenario, copying a small portion of Direct2D from Windows 7 is not going to work at all in XP. 

    Furthermore, the msvcrt.dll is not manifest enabled, so it's going to ignore anything you do relating to manifests.    And as you already mentioned, knowndlls cannot be put into an application folder, they'll just be ignored.  

    For your attempt at opening D2D1 and changing the references to a renamed runtime library, you'll need to try that in a binary editor, not notepad.  Open up the DLL in Visual Studio and choose to "open with" Binary editor.  Then search the name and replace any references.

    But unfortunately, nothing you try will get Direct2D to work on XP.  I suggest you give up on attempting this.

    Instead I suggest you write a wrapper that uses an alternative approach under XP if you detect that as the OS.  You can try WPF, GDI, GDIPlus, Direct3D, Uniscribe, or a combination of these.
    • Marked as answer by Wesley Yao Friday, August 21, 2009 2:41 AM
    Saturday, August 15, 2009 2:13 AM