Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're mismatching ANSI (narrow) and Unicode (wide) strings.</p> <p>Unlike the <code>wcscpy</code> function, the <code>w</code> in the <code>wsprintf</code> function doesn't stand for "wide", it stands for "Windows". It is part of the Win32 API, rather than the C runtime library. All of the Win32 API functions that work with strings have two versions, one suffixed with an <code>A</code> that deals with ANSI strings and another suffixed with a <code>W</code> that deals with wide strings. The headers hide all of this from you with macros. I explain all of this in more detail <a href="https://stackoverflow.com/questions/15458312/how-do-i-properly-call-the-copyfile-function-in-visual-c/15458564#15458564">here</a>—recommended reading.</p> <p>Anyway, the simple fix here is to explicitly call the wide variant of that function, since you're correctly using wide strings everywhere else. Make all the calls to <code>wsprintf</code> look like this:</p> <pre><code>wchar_t *ptr = wcsstr(buf, L"StartHTML"); wsprintfW(ptr+10, L"%08u", wcsstr(buf, L"&lt;html&gt;") - buf); *(ptr+10+8) = L'\r'; </code></pre> <p>Alternatively, you could use the <code>swprintf</code> function provided by the C runtime library instead of the Win32 version. This one works just like the <code>wcsstr</code> and <code>wcscpy</code> functions you're using elsewhere. The <code>w</code> in the name means "wide". The documentation for this series of functions is <a href="http://msdn.microsoft.com/en-US/library/ybk95axf.aspx" rel="nofollow noreferrer">here</a>.</p> <p>Note also that when you use character or string literals, they also need to be wide characters. You accomplish that by prepending them with an <code>L</code>. You do that some places, but miss doing it others. Make sure that you do it consistently.</p> <p>The compiler should warn you about all this, though. You just need to make sure you turn your warning level up and don't ignore any of the warnings. Also make sure that both the <code>UNICODE</code> and <code>_UNICODE</code> preprocessor symbols are defined globally for your project. That will ensure that you are always calling the Unicode/wide versions of functions. Although that should be the default for all new projects.</p>
 

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