Why CString MakeUpper inconsistent performance in DEBUG and Release? - c++

I am facing a strange problem in VC++6.0.
CString m_strData = "W" + CString(char(165));
m_strData.MakeUpper();
MessageBox(m_strData, "Alert from C++",MB_ICONEXCLAMATION|MB_OK);
If I build the project with Win32 Debug, the alert value is correct. But if I build with Win32 Release MinDependency. The value is different with Win32 Debug. Why? Is their any article show me the reason? I have tried setlocale(LC_ALL,"English_United States.1250") front of the code, but it didn't work.
the value of Win32 Debug
the value of Win32 Release MinDepency
I've take a look into the CString MakeUpper function. It will call _tcsupr() function. But from the MSDN page, it only shows me this function will depends on the locale. But not the project Build mode...?

The output of char(165) depends on the codepage you are using. It could be the Yen-symbol or an N with a ~ above it. I assume that the code generated in debugging either uses different codepage or replaces the character with a question mark to tell you, that it is a non-printable character.

Related

Visual Studio 2013 Floating Point Support fix?

I have a DLL, which is commercial software, so therefore I cannot show the code here...
I get the error "6002" -floating point support not loaded, but only on some applications.
This dll is hooked to several applications, without problems.
I tried everything that I found on Google, like reinstalling VC++, clean PC, registry, everything.
So my conclusion is that either there is another dll compiled in another version of Visual Studio (2010) and it`s somehow conflicting with my dll ?!
Or, I have some memory leak, which I cannot find.
I use the following functions in my DLL which (I think) is the issue:
sscanf(); // DISABLED IT FOR TEST, BUT STILL GET ERROR
fprintf_s();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DisableThreadLibraryCalls(hModule);
DetourRestoreAfterWith();
_beginthreadex();
strtoul();
Example function I use for logging:
void ##SOFTWARE-CLASS##::write_log(char *text)
{
FILE *write_log;
char dateStr [9];
char timeStr [9];
_strdate( dateStr);
_strtime( timeStr );
write_log = fopen("##SOFTWARE-FILE##","a+");
fprintf_s(write_log,"[%s %s] %s \n", dateStr, timeStr, text);
fclose(write_log);
}
Nothing else is used that may cause floating errors...
The dll is hooked properly, I have no warnings, and no errors.
I must mention, that I have created an empty DLL, with a MessageBox, at the first run, I was getting the same error, but after switching to /fp:strict, the error disappeared. So I did the same thing to my project, but the error is still there. I even recoded the whole project, just to see if it fixes the problem, but no.
Please give me advice on how can I solve this problem, as this is the third day that I am testing...
From MSDN : R6002 the document says that a program will only load floating point support if needed. What this means, is that the detoured code is being injected into binaries which did not initialize the floating point subsystem. The solution would be to relink your commercial product without requiring the floating point code, or to relink with an alternative floating point library.
You could try and detect the missing initialization and perform it yourself, but that would have a larger impact on the injected system, and possibly create instabilities.
Use a debugger with the failing executable, and you should be able to get a call stack which identifies where the failure occurs.

Why MSVC compiler converts "??-" sequence to "~" in string literals?

I have a hard coded string in my code (which should be used as a file mask), but compiler always changes the "??-" sequence to "~", for example:
const wchar_t textW[] = L"test-??-??-??.txt";
The testW will be "test-~~??.txt" (without quotes).
The same happens for non-unicode strings as well:
const char textA[] = "test-????-??-??.txt";
textA will be "test-??~~??.txt" (without quotes).
My compiler is Microsoft Visual C++ 2008.
I have just tried this with Visual Studio 2013, the string in runtime is correct and intellisense displays the correct value on the tooltip when I'm tracing the app, but... But in the writing mode (when app isn't running) intellisense displays incorrect value with tildas on the tooltip.
That's a trigraph, a way to express characters that are not always available on keyboards.
This behavior is controlled by the /Zc:trigraphs option, which is off by default. It appears it is enabled for your project, I would suggest you disable it.
It's called a trigraph. They are replaced by the preprocessor.

Win32 C++ getting text from elements

While this question has probably been asked a thousand times before (pretty sure of it I have read a thousand answers). I still don't get it.
Lets say I have a function that creates a ComboBox like this:
scopeComboSelector=CreateCombobox(hwnd,
GetModuleHandle(0),
CBS_DROPDOWNLIST,
re,
IDCC_DROPDOWNLIST_SCOPE_SELECTOR,
_T("Scopes"));
Where "re" is a positioning rectangle. And IDCC_DROPDOWNLIST_SCOPE_SELECTOR (pretty long name) is the id of the combobox. Now the point is, I can actually fill this "drop down select list" but I have no clue as how I can simply get the currently selected value as a string.
I have seen about 10 ways to do it, which all give errors straight away (need to Convert to LPWSTR -> fixing results in more terror).
Maybe I'm just to used to Java where one can simply say:
textfield.getText();
How would one achieve this in Win32 C++ (microsoft visual studio)?
Edit
Code I've used:
char userName[_MAX_PATH+1];
GetDlgItemTextW(scopeComboSelector,
IDCC_DROPDOWNLIST_SCOPE_SELECTOR,
(LPWSTR)userName,
200);
Returns: userName == empty
Update
Now using: GetDlgItemText(). Debugger tells me the value of userName = ""
The documentation has a C style Windows 9x code example.
You need simply to replace C with C++ and Windows 9x silly T macros with wchar_t and friends.
It's always a good idea to read the documentation.

Issue with GetDlgItem

I am trying to do the following:
CComboBox *pComboBox;
CString newString;
int iNewSelection = -1;
pComboBox = (CComboBox*)(this->GetDlgItem(IDC_METHOD));
NewMethod = pComboBox->GetCurSel();
if(NewMethod != CB_ERR)
{
pComboBox->GetLBText(NewMethod, newString);
}
In the above NewMethod is an integer.
It works fine (kind of). The issue is following:
When I debug through the above code, stop at the IF condition and put the mouse cursor on NewMethod, I get some random value, but then it does go through the IF condition and I can see correct value in newString.
My question is: why I do not see correct integer value in NewMethod?
Many thanks.
Best Regards
Chintan
It looks like you're source code and binary are out of sync, ie. you're debugging a DLL/EXE that has been compiled with different version of the source code.
During debug activate the Debug->Windows->Modules window and check that the DLL/EXE you're debugging is the same as the one you've been compiling with your source code (check date/times, symbol files etc.).

Value not assigned to handle when build using Release Configuration in VS2010

I use VS2010 and I have encountered following problem:
HWND handle = NULL;
handle = pPlatform->getWindowHandle();
When I debug this code in debug configuration a correct value is assigned to "handle", but when I debug this in release build "handle" stays NULL.
getWindowHandle() is just a simple accessor:
HWND PlatformManager::getWindowHandle()
{
return windowHandle;
}
"windowHandle" has a non-NULL value both when debugging in debug/release build.
Thanks for the help.
The Release build includes optimizations, and sometimes the debugger might see the wrong value for variables that get optimized. It makes Release builds harder to debug, but that's exactly why they're not called Debug builds. :)
In short, if you just have to debug a release build but your debugger is playing tricks on you, you can always resort to good-old printf debugging. Add a few trace functions, e.g. with OutputDebugString, and see if handle really stays NULL at that point.
char buf[256];
HWND handle = NULL;
handle = pPlatform->getWindowHandle();
OutputDebugStringA(_itoa((int)handle, buf, 10));