Click here to Skip to main content
15,893,904 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Program executes automatically Pin
Ravi Bhavnani30-May-05 15:47
professionalRavi Bhavnani30-May-05 15:47 
GeneralRe: Program executes automatically Pin
Identity Undisclosed30-May-05 21:40
Identity Undisclosed30-May-05 21:40 
GeneralRe: Program executes automatically Pin
Flit31-May-05 1:41
Flit31-May-05 1:41 
GeneralRe: Program executes automatically Pin
Identity Undisclosed31-May-05 2:29
Identity Undisclosed31-May-05 2:29 
GeneralRe: Program executes automatically Pin
Flit31-May-05 3:24
Flit31-May-05 3:24 
GeneralRe: Program executes automatically Pin
Christian Graus31-May-05 11:10
protectorChristian Graus31-May-05 11:10 
GeneralRe: Program executes automatically Pin
FlyingTinman31-May-05 14:24
FlyingTinman31-May-05 14:24 
GeneralWhy BSTR conversion not working Pin
Imtiaz Murtaza30-May-05 8:18
Imtiaz Murtaza30-May-05 8:18 
Dear friends,
I am trying to convert 3 strings to BSTRs. But the method i am using is not working. It is giving me wrong results. Please tell me the reason why this is not wrking. Please see the code:

<br />
<br />
struct Student<br />
{<br />
  BSTR firstName;<br />
<br />
  BSTR lastName;<br />
<br />
  BSTR fatherName;<br />
};<br />
<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
   std::string firstName = "Bob";<br />
<br />
   std::string lastName = "Andrew";<br />
<br />
   std::string fatherName = "Jones";<br />
<br />
   Student s;<br />
<br />
   s.firstName =	 _bstr_t(firstName.c_str());<br />
   <br />
   s.lastName  =	 _bstr_t(lastName.c_str());<br />
<br />
   s.fatherName =	 _bstr_t(fatherName.c_str());<br />
<br />
   std::wcout << s.firstName << std::endl;<br />
   <br />
   std::wcout << s.lastName << std::endl;<br />
	<br />
   std::wcout << s.fatherName << std::endl;<br />
<br />
   return 0;<br />
}<br />


The program is giving me following result:

Bob.
Jones.
Jones.

Please tell me the reason that why the second and third conversions created trouble. While debugging we can see the that the first two conversions were successful. But during third conversion, the previous one automatically changed to reflect the third.

I am using _bstr_t OR CComBSTR in order to avoid explicit call to SysFreeString()/SysAllocString(). Both _bstr_t and CComBSTR are behaving in the manner i described above.
GeneralRe: Why BSTR conversion not working Pin
Christian Graus30-May-05 12:05
protectorChristian Graus30-May-05 12:05 
GeneralRe: Why BSTR conversion not working Pin
S. Senthil Kumar30-May-05 20:33
S. Senthil Kumar30-May-05 20:33 
GeneralRe: Why BSTR conversion not working Pin
Christian Graus31-May-05 10:59
protectorChristian Graus31-May-05 10:59 
GeneralRe: Why BSTR conversion not working Pin
S. Senthil Kumar31-May-05 17:17
S. Senthil Kumar31-May-05 17:17 
GeneralRe: Why BSTR conversion not working Pin
S. Senthil Kumar30-May-05 19:57
S. Senthil Kumar30-May-05 19:57 
GeneralBode diagram Pin
alvarillo30-May-05 7:39
alvarillo30-May-05 7:39 
GeneralRe: Bode diagram Pin
Ravi Bhavnani30-May-05 7:55
professionalRavi Bhavnani30-May-05 7:55 
GeneralCComboBox & MSVS .NET 2003 Pin
oldbayray30-May-05 6:13
oldbayray30-May-05 6:13 
GeneralRe: CComboBox &amp; MSVS .NET 2003 Pin
Jack Puppy30-May-05 6:57
Jack Puppy30-May-05 6:57 
GeneralRe: CComboBox &amp; MSVS .NET 2003 Pin
oldbayray30-May-05 7:45
oldbayray30-May-05 7:45 
GeneralRe: CComboBox &amp; MSVS .NET 2003 Pin
Ravi Bhavnani30-May-05 7:56
professionalRavi Bhavnani30-May-05 7:56 
GeneralRe: CComboBox & MSVS .NET 2003 Pin
Tom Archer30-May-05 11:29
Tom Archer30-May-05 11:29 
GeneralRe: CComboBox &amp; MSVS .NET 2003 Pin
Ravi Bhavnani30-May-05 11:35
professionalRavi Bhavnani30-May-05 11:35 
GeneralRe: CComboBox &amp; MSVS .NET 2003 Pin
Jack Puppy30-May-05 12:43
Jack Puppy30-May-05 12:43 
GeneralRe: CComboBox &amp; MSVS .NET 2003 Pin
oldbayray30-May-05 12:52
oldbayray30-May-05 12:52 
GeneralRe: CComboBox &amp; MSVS .NET 2003 Pin
oldbayray30-May-05 12:51
oldbayray30-May-05 12:51 
GeneralDisplay file!!! Pin
Anonymous30-May-05 5:41
Anonymous30-May-05 5:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.