BUG: CComBSTR::LoadString May Give an Access Violation without ATL Support (251344)



The information in this article applies to:

  • The Microsoft Active Template Library (ATL) 3.0, when used with:
    • Microsoft Visual C++, 32-bit Enterprise Edition 6.0

This article was previously published under Q251344

SYMPTOMS

If you have used the CComBSTR class in a non-ATL application and used the bool CComBSTR::LoadString(UINT nID) function, it might give an access violation.

CAUSE

The global _pModule variable representing an instance of CComModule expected by ATL, is not declared and initialized.

RESOLUTION

Use the other overloaded version of LoadString that takes HINSTANCE as a parameter
bool CComBSTR::LoadString(HINSTANCE hInst, UINT nID)
				
and pass the HINSTANCE of the current module or the module wherever the string resource is defined.

Or, add ATL support to this project. In order to add ATL support, from the Insert menu, click New ATL Object. You are then asked if you want to add ATL support to this project; click Yes. As a result, the ATL Object Wizard is opened. Cancel that option if you do not want to add an ATL object to your project.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Generate a new MFC AppWizard SDI application.
  2. Go to ResourceView and add a new string entry to the String Table resource and call it IDS_TESTSTRING.
  3. Go to CYourApp::InitInstance and add the following code:
    CComBSTR bstrTemp;
    bstrTemp.LoadString(IDS_TESTSTRING);
    						
  4. Also add #include AtlBase.h to the .cpp file containing the above code for InitInstance.
  5. Build and run it. You receive the access violation.

REFERENCES


Modification Type:MajorLast Reviewed:10/17/2003
Keywords:kbArchitecture kbbug kbpending kbString KB251344