Showing posts from August, 2010

Conversion between 'CString' and 'BSTR'

A BSTR (Basic string or binary string) is a string data type that is used by COM, Automation, and Interop functions. A BSTR is a composite data type that consists of a length prefix, a data string, and a terminator.
Use the AllocSysString member function of the CString to convert from CString to BSTR:
Code:         CString cs("Hello");         BSTR bstr = cs.AllocSysString();
Note: If you use the 'BSTR' by yourself, dont forget to call '::SysFreeString()' when you're done with it.

fatal error C1010 - unexpected end of file while looking for precompiled header directive

There are two ways to resolve the error:
1. Type following line at start of your code file 
   #include "stdafx.h"

2. Select 'Not Using Precompiled Headers' options under the precompiler headers option in project propertied.

 Main reason behind this error is MFC Programs use many libraries, requiring the use of many header files. To save time, the compiler tries to precompile most of these header files, and use the predigested data instead of reading through all of these header files on every compilation. The standard method for MFC programs is to lump all of these common header file references into one header file ("stdafx.h"). If you just have to ask what "stdafx" means, it comes from the early name of MFC, which was AFX (application framework). 

When compiling each source (.cpp) file, the compiler skips through the source code, looking for the directive: 
#include "stdafx.h"Once it finds this directive, it substitutes the precompiled heade…