CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Managed C++ and C++/CLI
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Managed C++ and C++/CLI Discuss Managed C++ and .NET-specific questions related to C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old July 11th, 2005, 06:14 AM
    alptek alptek is offline
    Junior Member
     
    Join Date: Jul 2005
    Posts: 9
    alptek is an unknown quantity at this point (<10)
    string to bstr

    hi, i get an input from user with "cin" command and i need to convert this to a "bstr". in fact i did it with "_bstr_" object but it gave error when buildinbg the project. does anyone have other alternatives?
    Reply With Quote
      #2    
    Old July 11th, 2005, 06:41 AM
    humptydumpty humptydumpty is offline
    Elite Member
     
    Join Date: May 2005
    Location: Minnesota
    Posts: 3,665
    humptydumpty has disabled reputation
    Lightbulb Re: string to bstr

    A BSTR, known as basic string or binary string, is a pointer to a wide character string used by Automation data manipulation functions.

    typedef OLECHAR FAR* BSTR;


    Code:
    #include "stdafx.h"
    #include "afxwin.h"
    #include "iostream.h"
    #include "string.h"
    
    
    
    int main(int argc, char* argv[])
    {
    	BSTR bstr1 = NULL;
    	char *str = new char[255];
    	cin>>str;
    	bstr1 = (BSTR)str;
    	char *ptr =(char*) bstr1;
    	cout<<ptr;
    	return 0;
    // and delete the pointer here
    }
    do you want this or something else.
    if else
    let me know
    Reply With Quote
      #3    
    Old July 11th, 2005, 07:04 AM
    pranavsharma pranavsharma is offline
    Member
     
    Join Date: Apr 2005
    Location: INDIA
    Posts: 35
    pranavsharma is on a distinguished road (10+)
    Thumbs up Re: string to bstr

    Put that data into CString and then use AllovSysString to put it into BSTR.

    Isn't that simple .................
    Reply With Quote
      #4    
    Old July 11th, 2005, 09:46 AM
    alptek alptek is offline
    Junior Member
     
    Join Date: Jul 2005
    Posts: 9
    alptek is an unknown quantity at this point (<10)
    Re: string to bstr

    thanks, both are true. additionally i have forgatton to add MFC and ATL support to my project
    have a nice day
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Managed C++ and C++/CLI


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 11:43 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009