Entries tagged Visual Studio

How to convert BSTR to LPCTSTR

Posted on May 31, 2009

I’ve had to deal with a pointer of a BSTR string returned to an event handler of an ActiveX control. I wanted to convert it to LPCTSTR, and a simple implicit type-casting worked seamlessly when I tried in a test project.

void put_UseServer(LPCTSTR newValue);

void ServerChanged(BSTR* NewServer)
{
	put_UseServer(*NewServer); // This conversion works only in Unicode Character Set
}

However, when I copied the same code into my actual project, it caused an error. The reason was that my project used the Multi-byte Character Set whereas I tested the code in the Unicode Character Set. The simplest solution I found which also works in the Multi-byte Character set is like the following.

void put_UseServer(LPCTSTR newValue);

void ServerChanged(BSTR* NewServer)
{
	put_UseServer(COLE2CT(*NewServer)); // Use ATL String Conversion Class
}

More information about ATL and MFC String Conversion is on the MSDN website.

Some VS2005 and VS2008 wizards pop up script error after installing IE8

Posted on May 30, 2009

I experienced this trouble when I tried to add a variable with a wizard in Visual Studio 2008. I never suspected IE8, but MS disappointed me again. Anyway, here is a workaround posted in Visual C++ Team Blog and it seems to work. For the details, click HERE

Please follow the following steps:

– Open regedit (on a 64-bit OS, open the 32-bit regedit)

– Under “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones“, create a new key called 1000 (if it isn’t already there)

– Under 1000, create a DWORD entry with:
o Name = 1207
o Type = REG_DWORD
o Data = 0x000000

For the workaround to work on VS2005, however, the VS2005 SP1 (and VS2005 SP1 Update for Windows Vista) has to be installed.