Line 4 could be the problem. You are casting the refference of a string object to a cstring, what you probably want is something like GetDlgItemText(hWnd, IDC_DIFF, (char*)&str[0], len+1);
Without knowing what GetDlgItemText and MessageBox do it's hard (impossible) to know what might be happening. But here's my best guess.
GetDlgItemText looks like it should take a c-string buffer to fill as its third argument. You're passing it a pointer to str's internal representation as a c-string. You're not meant to fill std::strings that way (if that's what's going on).
Try changing string str; to char buf[128];. Just pass buf to GetDlgItemText without all that subscripting/addressing/casting nonsense.
str fills fine, it's teststr that returns -1, and that's because stringstream gets broken somehow
also I noticed that no matter what I can't store more than 2^32-1 to the uint64_t, even when I compile for 64bit (the 64bit support isn't default for express so I followed this guide on msdn: http://msdn.microsoft.com/en-us/library/9yb4317s.aspx)
Undefined behavior. str is empty and does not have [0] element at all.
If you would initialize to have enoug characters to store written data it will work fine, but is still mess up string internals big time. Example:
I just dont quite understand, as
/*...*/
worked correctly all the time before
It just seems to work. YOu write to some random memory. Which can be overwritten again by owner or cause problems for said owner. It is like scratching messages on random car in parking lot: it works. Maybe.
edit: is there function similar to GetDlgItemText that uses strings instead of char arrays?
All WinAPI (and external API in general) uses most simple types.
is there 64bit double/float ?
IEEE doubles are 64 bit long. floats are 32 bit long.
1 2 3 4
stringstream ss;
ss << tmp;
//Is better written as
std::istringstream ss(tmp);
Also wsprintf is Microsoft extension and is unportable (And unsupported. Even MSDN writes: "Note Do not use." ). Use sprintf or, better, snprintf. Or even better, store information in strings and use std::to_string
"%I64d" is another extension. (and it expects signed numbers AFAIK). USe %llu instead. All supported format specifiers can be found here: http://en.cppreference.com/w/cpp/io/c/fprintf
2. sadly, with "%llu" i'm getting "lu", looks like it's not supported by wsprintf, sprintf is obsolete, so I can't compile and I somehow can't get snprintf from any header, tried stdio.h and cstdio ... http://www.cplusplus.com/reference/cstdio/snprintf/
What do you actually mean by 64-bit double? An floating point variable which takes 64 bit in memory? Then yes. A floating point variable which can exactly represent any 64bit unsigned integer? Then no. Floating points stores only several significant digits precisely. 40007470271 should fit into double exactly thought.
sprintf is obsolete
Who said that? If something is obsolete it is wsprintf, as stated by Microsoft itself.
I somehow can't get snprintf from any header
Looks like your compiler is not supporting latest standard fully. I suggest updating it. (It looks that snprintf will be supported only in VS2014. Well, it took them longer than to release Duke Nukem Forever)
You can keep those function if you have no intention to let other users to compile your code, But in this case change uint64_t i; to std::int_64_t: %I64d expects signed integer.
_s functions are not really safer and in some cases can lead to more problems because of false sence of security. Not to mention nonexisting portability.
You can get 64 bits of precision with an 80bit float. Try printing sizeof(longdouble) to see if your system/compiler supports 80bit floats, if the size is 10 (10 bytes, 8 bits per byte) then you can use long double to exactly store any 64 bit (signed or unsigned) integer. 1 bit sign, 15 bit exponent, 64 bit significand.