convert std string to bstr without ATL

This is a discussion on convert std string to bstr without ATL within the C++ Programming forums, part of the General Programming Boards category; Hi, I am trying to convert a std string to a BSTR. I am using Dev C++ with mingw on ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    1

    convert std string to bstr without ATL

    Hi,
    I am trying to convert a std string to a BSTR. I am using Dev C++ with mingw on windows. As far as I am aware I cannot use the ATL libraries with Dev C++ so i cannot use A2BSTR etc. Here is my code:

    Code:
    string  path = getImagePath(); //eg C:/T2
          
         int location = 0;
         
         while(path.find("/",0) != string::npos) //converts image path to C:\\T2
         {
             location = path.find("/",0);
             path.replace(location,1,"\\\\");
        }
    
    OpenSlide(path.c_str()); //a function in a wrapper dll which takes a LPCSTR of format C:\\T2
    The header for open slide function in the wrapper dll is:
    Code:
    // Open Slide
    EXTERN_C __declspec(dllexport) BOOL WINAPI OpenSlide(LPCSTR SlideName);
    This wrapper DLL calls a function from another DLL that has a header:

    Code:
    virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE OpenSlide( 
                /* [in] */ BSTR SlideName) = 0;
    This all compiles but crashes when OpenSlide() is called. If I hard code the correct path and pass it in it seems to work however ie path = "C:\\T2";

    Any help would be greatly appreciated,
    Alex

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 05:30 PM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 07:02 AM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 04:58 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21