Note that there are some explanatory texts on larger screens.

plurals
  1. POGetFileAttributesExW() or FileTimeToSystemTime() doesn't work in Release, when works in Debug
    primarykey
    data
    text
    <p>I use <code>GetFileAttributesExW()</code> to get the date for file. In <strong>DEBUG</strong> mode (Visual Studio 2012), everything works fine, I get e.g. <em>"2013-05-10"</em>. But when I change target to <strong>RELEASE</strong>, the date is <strong>corrupted</strong> (I get at the end of my function the string e.g. <em>"1678-09-08"</em>).</p> <p>The full code:</p> <pre><code>bool Registry::fileDate(std::wstring pathString, std::string &amp;dateOut) { if (pathString.size() == 0) return false; if (pathString[0] == '\"') { pathString = pathString.erase(0, 1); } if (pathString[pathString.size()-1] == '\"') { pathString = pathString.erase(pathString.size()-1, 1); } size_t pos = 0; size_t found = pathString.find('\"', pos); if (found &gt; 0 &amp;&amp; found != std::string::npos) { pathString = pathString.substr(0, found); } std::wstring filePath = pathString; WIN32_FILE_ATTRIBUTE_DATA fileData; GetFileAttributesExW(filePath.c_str(), GetFileExInfoStandard, &amp;fileData); SYSTEMTIME systemTime; bool res = FileTimeToSystemTime(&amp;fileData.ftCreationTime, &amp;systemTime); if (res) { char buf[40] = {0}; for(int i=0; i&lt;40; i++) //to be even more certain that no trash will get here buf[i] = ' '; sprintf(buf,"%04d-%02d-%02d", systemTime.wYear, systemTime.wMonth, systemTime.wDay); dateOut = buf+'\0'; } else { //show error's window, i'm sure it DOESN'T occur, both in DEBUG and RELEASE } } </code></pre> <p>I'm aware that in <strong>RELEASE</strong> some optimizations have to be done. That optimizations and my mistake (which I cannot see) together must result in corrupted date.</p> <p>To the function go strings like:</p> <pre><code>L"\"C:\\Program Files\\File\\setup.exe\" /uninstall PROPLUS /dll OSETUP.DLL" </code></pre> <p>Which in <strong>DEBUG</strong>, are converted in first lines of my function to:</p> <pre><code>L"C:\\Program Files\\File\\setup.exe" </code></pre> <p><strong>Edit:</strong> (Thx to Raymond Chen's comment)</p> <p>Now I know that in RELEASE, <code>GetFileAttributesExW()</code> returns <strong>FALSE</strong>, so maybe somehow that part works in <strong>DEBUG</strong> and doesn't work in <strong>RELEASE</strong> (it should get rid of extra <em>"</em> and <em>/params</em> from path):</p> <pre><code>if(pathString.size() == 0) return false; if(pathString[0] == '\"'){ pathString = pathString.erase(0, 1); } if(pathString[pathString.size()-1] == '\"'){ pathString = pathString.erase(pathString.size()-1, 1); } size_t pos = 0; size_t found = pathString.find('\"', pos); if (found &gt; 0 &amp;&amp; found != std::string::npos) { pathString = pathString.substr(0, found); } std::wstring filePath = pathString; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload