I'm trying to pass the address of a vector of strings to a function so I can fill the vector from a SQL server query. The data will be used in the calling function. In the following code segment, the MessageBoxA() call displays the correct data in a message box, but when I try to fill the vector with the same data with a call to push_back(), I get an error of a type mismatch. How can I cast "Lesson_Name" so that it will be loaded properly into the vector?
BOOL SQL_FillLessonInfo(HWND hWndCB, HWND hWndTB, std::vector<std::wstring>& LNpointer)
{
.
.
SQLCHAR* Lesson_Name = new SQLCHAR[SQL_RESULT_LEN];
.
.
while (SQLFetch(sqlStmtHandle) == SQL_SUCCESS)
{
.
.
SQLGetData(sqlStmtHandle, 2, SQL_C_CHAR, Lesson_Name, SQL_RESULT_LEN, ptrSqlDataLength);
.
.
MessageBoxA(NULL, (LPCSTR)Lesson_Name, NULL, MB_OK);
LNpointer.push_back(Lesson_Name);
.
.
CodePudding user response:
Okay. That comment by IInspectable gave me a lead. Here is the modified code that worked.
BOOL SQL_FillLessonInfo(HWND hWndCB, HWND hWndTB, std::vector<std::wstring>& LNpointer)
{
.
.
SQLWCHAR* Lesson_Name = new SQLWCHAR[SQL_RESULT_LEN];
.
.
while (SQLFetch(sqlStmtHandle) == SQL_SUCCESS)
{
.
.
SQLGetData(sqlStmtHandle, 2, SQL_C_WCHAR, Lesson_Name, SQL_RESULT_LEN, ptrSqlDataLength);
.
.
MessageBoxW(NULL, Lesson_Name, NULL, MB_OK);
LNpointer.push_back(Lesson_Name);
.
.
'MessageBoxW' was just used as a troubleshooting message so is unnecessary to the finished code. Changing 'Lesson_Name' to 'SQLWCHAR*' fixed the issue with the type mismatch on the argument sent to the 'push_back()' function.