<div dir="ltr"><div><div><div><div><div><br></div>Hi, here is my code that actually enables the delay loading to function.<br></div>First I modify the PATH environment variable to actually contain the folders where the DLLs are expected to be found.<br><br></div>Then using __HrLoadAllImportsForDll() I get all the import symbols from the delay loaded DLLS (which have to be given explicitly, file by file) which allows OSG to run successfully.<br><br></div>Without that second step, no graphics context could be initialized.<br><br></div>The only remaining issue is that in case a delay-loaded DLL isn't found at runtime, the function __HrLoadAllImportsForDll() crashes internally somewhere, and not even the try{} catch {} block can prevent this. I wish I could somehow catch this.<br><div><div><div><div><div><div><br>#include <regex><br>#include <string><br><br>#include <Windows.h><br>#include <LibLoaderAPI.h><br>#include <DelayImp.h><br><br><br>        // the DLL search paths to prepend to PATH<br>        std::vector<std::wstring> path_list = { L"%CD%\\..\\deps_v2\\OSG-3.4\\bin", L"%CD%\\..\\deps_v2\\OSG-3.4\\3rdParty\\bin" };<br><br>        // prepend the PATH environment variable with the folders specified above<br>        wchar_t pwd[512];<br>        _wgetcwd(pwd, sizeof(pwd) / sizeof(wchar_t));<br>        std::wstringstream ss;<br>        for (auto path : path_list)<br>        {<br>            // replace %CD% with the actual current working directory<br>            path = std::regex_replace(path, std::basic_regex<wchar_t>(L"\\%CD\\%"), pwd);<br>            ss << path << ";";<br>        }<br>        ss << _wgetenv(L"PATH");<br>        ss << '\0';<br>        const std::wstring env = ss.str();<br>        SetEnvironmentVariable(L"PATH", env.c_str());<br><br>        //<br>        // Delay-load all import symbols from the OSG DLLs now.<br>        //<br><br>#if _DEBUG<br>        std::vector<std::string> dll_list =<br>        { "osg130-osgd.dll", "osg130-osgDBd.dll", "osg130-osgViewerd.dll", "ot20-OpenThreadsd.dll" };<br>#else<br>        std::vector<std::string> dll_list =<br>        { "osg130-osg.dll", "osg130-osgDB.dll", "osg130-osgViewer.dll", "ot20-OpenThreads.dll" };<br>#endif<br><br>        for (auto dllname : dll_list)<br>        {<br>            fprintf(stderr, "Delay-loading imports from %s\n", dllname.c_str());<br>            bool failed = true;<br>            try {<br>                failed = FAILED(__HrLoadAllImportsForDll(dllname.c_str()));<br>            }<br>            catch (...)<br>            {<br>            }<br>            if (failed) {<br>               fprintf(stderr, "Delay-loading imports from %s failed!\n", dllname.c_str());<br>                exit(1);<br>            }<br>        }<br><br>        init = true;<br>    }<br><br><br><br></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-10-25 19:24 GMT+02:00 Christian Buchner <span dir="ltr"><<a href="mailto:christian.buchner@gmail.com" target="_blank">christian.buchner@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi,<br><br></div>I was wondering if anyone of you has successfully used the /DELAYLOAD linker option with the OSG DLLs on Windows.<br></div><div><br></div>For me, attempting this causes the creation of the graphics context to fail, because<br>windowingSystemInterfaceRef() called by createGraphicsContext() returns an invalid reference.<br><br></div><div>Any clues about how to fix this possibly? It seems that maybe constructors for static objects inside the OSG DLLs aren't getting called as required.<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div>Christian<br><br></font></span></div>
</blockquote></div><br></div>