即使有很多這樣的情況,並且我搜索了它們,但它們都沒有以任何方式幫助我。下面的代碼在調試中完美工作,但是在發佈模式下它會崩潰,或者如果沒有則返回損壞的字符串。所有針對發佈模式的優化都將關閉,而不會導致結果。使用Visual Studio的代碼分析沒有發現任何東西。如果它是某種內存/緩衝區的東西,那麼它現在高於我的頭。代碼在調試中起作用但在版本中不起作用
case LBN_SELCHANGE:
//===========================================================================
//Trying to fill the edit boxes with data fetched from DB
//===========================================================================
{
string s;
wstring str;
int y;
int ind = SendMessage(GetDlgItem(hwnd, IDC_lbList), LB_GETCURSEL, 0, 0);
int index = SendMessage(GetDlgItem(hwnd, IDC_lbList), LB_GETITEMDATA, (WPARAM)ind, 0);
string sint = boost::lexical_cast<std::string>(index);
string smt = "SELECT `ID`, `client`, `telnr`, `atnrem`, `papatn`, `gedapr` FROM `tremreg` WHERE `ID` = ";
string query = smt + sint;
res = stmt->executeQuery(query.c_str());
while (res->next())
{
for (int i = 1; i <= g_iFieldCount + 1; i++)
{
if (i == 1)
{
y = res->getInt(i);
SetDlgItemInt(hwnd, IDC_eRemID, y, FALSE);
}
else
{
s = res->getString(i);
str = s2ws(s);
SetDlgItemText(hwnd, 1000 + (i - 1), str.c_str());
}
}
}
delete res;
}
break;
在釋放模式下獲取字符串時看起來有些可怕的錯誤。他們充滿,有......某事。由於字符串中的前4個點用奇數字符和空終止符填充。這是一個截圖。
當我將其轉換爲wstring的str
,這一切仍然是char[0]
。
你應該從你的問題你的代碼工作完美的部分省略。如果問題出在記錄集上,那麼就從'string smt ='SELECT ...行開始吧' – KonstantinL