// JP opened flex table

Click to See Complete Forum and Search --> : Can't retrieve error string from resource duing COM error?


danny77uk
September 11th, 2007, 07:51 AM
I've got a try-catch block around some vanilla ADO code. If there is an error, the code in the catch block gets an error string from the resource file and puts in in a dialog. But for reasons I can't explain, the resource-load always fails during an actual error.


static CString errorStr; // global

...

errorStr.LoadString(IDS_ERR_QRY_EXECUTE_NONPROC_STR); // works fine

try
{
m_pCmd->CommandText = (_bstr_t)strQry;

if (m_bRecordSet)
{
m_pRs.CreateInstance(__uuidof(Recordset));
m_pRs = m_pCmd->Execute(NULL,NULL,adCmdText);
}
else {
m_pCmd->Execute(NULL,NULL,adCmdText|adExecuteNoRecords);
}

}
catch(_com_error &e)
{

errorStr.LoadString(IDS_ERR_QRY_EXECUTE_NONPROC_STR); // empty?!

ErrUtils::errMsg(errorStr, e.ErrorMessage(); // just calls MessageBox
}


The resource exists and the call to loadstring works fine outside the block. Any ideas why this could be happening? I've also tried creating a temporary string in the block (static and non-static). Hard-coded text works fine.

Any help appreciated!

danny77uk
September 11th, 2007, 08:55 AM
Update: LoadString is returning FALSE and GetLastError returns 1814 (Resource not found) which makes no sense. A collegue has suggested that the resource context is wrong? I think the code is attempting to use the calling exe's resources rather than those in the DLL.

But if I call AFX_MANAGE_STATE() before this code, I get a 'multiple symbols defined' linker error.

:(

Paul McKenzie
September 11th, 2007, 11:53 AM
But if I call AFX_MANAGE_STATE() before this code,That is MFC, not WinAPI, as this forum is for Windows API programming. To get a resource using the Windows API, use LoadResource.

The LoadResource function requires you to specify the handle of the module where the resources are found. This will guarantee you get the correct resources.

Regards,

Paul McKenzie

//JP added flex table