Microsoft KB Archive/251344

= BUG: CComBSTR::LoadString May Give an Access Violation without ATL Support =

Article ID: 251344

Article Last Modified on 10/17/2003

-

APPLIES TO


 * Microsoft ActiveX Template Library 3.0, when used with:
 * Microsoft Visual C++ 6.0 Enterprise Edition

-



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.



Steps to Reproduce Behavior
 Generate a new MFC AppWizard SDI application. Go to ResourceView and add a new string entry to the String Table resource and call it IDS_TESTSTRING.  Go to CYourApp::InitInstance and add the following code: CComBSTR bstrTemp; bstrTemp.LoadString(IDS_TESTSTRING);  Also add #include AtlBase.h to the .cpp file containing the above code for InitInstance. Build and run it. You receive the access violation.</li></ol>

<div class="references_section">