Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Need help--> BSTR in ATL

Need help--> BSTR in ATL

Scheduled Pinned Locked Moved ATL / WTL / STL
c++helpquestiondebugging
9 Posts 3 Posters 96 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leonwoo
    wrote on last edited by
    #1

    Hi, I am a newbie in ATL and have a question that hope you can answer it. The question is that I am trying to convert a BSTR type variable into a LPCTSTR type. I used the _com_util to do it but when i compiled the program, errors appear. I created the ATL project using the ATL wizard and the error message i received was -------------------------------------------------------------------------- The original source code: STDMETHODIMP CIniLoader::GetPrivateProfileString(BSTR bsSection, BSTR bsEntry, BSTR *bsOutput) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) LPCTSTR lpSection = _com_util::ConvertBSTRToString(bsSection); return S_OK; } The Error message {C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2653: '_com_util' : is not a class or namespace name C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2065: 'ConvertBSTRToString' : undeclared identifier} ---------------------------------------------------------------------- I tried to include the header file 'comutil.h' into the project and added an extra line 'using namespace _com_util' into the implementation but another different errors appeared. -------------------------------------------------------------------------- Creating library Debug/PlatformManager.lib and object Debug/PlatformManager.exp IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Debug/PlatformManager.dll : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I have no idea which portion of the code went wrong...please help... thanks in advance. leonwoo

    N M 2 Replies Last reply
    0
    • L leonwoo

      Hi, I am a newbie in ATL and have a question that hope you can answer it. The question is that I am trying to convert a BSTR type variable into a LPCTSTR type. I used the _com_util to do it but when i compiled the program, errors appear. I created the ATL project using the ATL wizard and the error message i received was -------------------------------------------------------------------------- The original source code: STDMETHODIMP CIniLoader::GetPrivateProfileString(BSTR bsSection, BSTR bsEntry, BSTR *bsOutput) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) LPCTSTR lpSection = _com_util::ConvertBSTRToString(bsSection); return S_OK; } The Error message {C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2653: '_com_util' : is not a class or namespace name C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2065: 'ConvertBSTRToString' : undeclared identifier} ---------------------------------------------------------------------- I tried to include the header file 'comutil.h' into the project and added an extra line 'using namespace _com_util' into the implementation but another different errors appeared. -------------------------------------------------------------------------- Creating library Debug/PlatformManager.lib and object Debug/PlatformManager.exp IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Debug/PlatformManager.dll : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I have no idea which portion of the code went wrong...please help... thanks in advance. leonwoo

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      leonwoo wrote: IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Are you possibly passing it the string literal where it may need a pointer to it? :confused: Have you looked at this MSDN page[^] Nick Parker
      **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


      **

      L 1 Reply Last reply
      0
      • L leonwoo

        Hi, I am a newbie in ATL and have a question that hope you can answer it. The question is that I am trying to convert a BSTR type variable into a LPCTSTR type. I used the _com_util to do it but when i compiled the program, errors appear. I created the ATL project using the ATL wizard and the error message i received was -------------------------------------------------------------------------- The original source code: STDMETHODIMP CIniLoader::GetPrivateProfileString(BSTR bsSection, BSTR bsEntry, BSTR *bsOutput) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) LPCTSTR lpSection = _com_util::ConvertBSTRToString(bsSection); return S_OK; } The Error message {C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2653: '_com_util' : is not a class or namespace name C:\temp\Project\PlatformManager\IniLoader.cpp(45) : error C2065: 'ConvertBSTRToString' : undeclared identifier} ---------------------------------------------------------------------- I tried to include the header file 'comutil.h' into the project and added an extra line 'using namespace _com_util' into the implementation but another different errors appeared. -------------------------------------------------------------------------- Creating library Debug/PlatformManager.lib and object Debug/PlatformManager.exp IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Debug/PlatformManager.dll : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I have no idea which portion of the code went wrong...please help... thanks in advance. leonwoo

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        The quickest way is to use a _bstr_t, which provides the character set conversion:

        BSTR bs1 = ...; // this is filled in already
        _bstr_t bs2 ( bs1, true ); // bs2 has a copy of the string now
        LPCTSTR psz = (LPCTSTR) bs2; // invoke _bstr_t conversion function

        --Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

        N 1 Reply Last reply
        0
        • M Michael Dunn

          The quickest way is to use a _bstr_t, which provides the character set conversion:

          BSTR bs1 = ...; // this is filled in already
          _bstr_t bs2 ( bs1, true ); // bs2 has a copy of the string now
          LPCTSTR psz = (LPCTSTR) bs2; // invoke _bstr_t conversion function

          --Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          Michael Dunn wrote: The quickest way is to use a _bstr_t, which provides the character set conversion: Ok Mike, maybe you can clear this up for me, maybe (please): What is the purpose (for example) of having all these different types/names for string like data types? After reviewing the MSDN article[^] here I see things like, LPCSTR, LPCTSTR, LPCWSTR, LPTSTR, LPWSTR, PCSTR, PCTSTR, etc.... I think you get the point. I understand these are names, but why in the hell are there so many, they seem to be so closely related to each other. Nick Parker
          **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


          **

          M 1 Reply Last reply
          0
          • N Nick Parker

            Michael Dunn wrote: The quickest way is to use a _bstr_t, which provides the character set conversion: Ok Mike, maybe you can clear this up for me, maybe (please): What is the purpose (for example) of having all these different types/names for string like data types? After reviewing the MSDN article[^] here I see things like, LPCSTR, LPCTSTR, LPCWSTR, LPTSTR, LPWSTR, PCSTR, PCTSTR, etc.... I think you get the point. I understand these are names, but why in the hell are there so many, they seem to be so closely related to each other. Nick Parker
            **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


            **

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            The LP and P prefixes mean the same thing these days. The difference is a leftover from the days when there were near and far pointers (L = long, indicating a far pointer). I just posted an article about strings[^], and I have part 2 almost done which covers the various wrapper classes and how to convert among them. :) --Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

            N L 2 Replies Last reply
            0
            • M Michael Dunn

              The LP and P prefixes mean the same thing these days. The difference is a leftover from the days when there were near and far pointers (L = long, indicating a far pointer). I just posted an article about strings[^], and I have part 2 almost done which covers the various wrapper classes and how to convert among them. :) --Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

              N Offline
              N Offline
              Nick Parker
              wrote on last edited by
              #6

              Michael Dunn wrote: I just posted an article about strings[^], and I have part 2 almost done which covers the various wrapper classes and how to convert among them. Thanks Mike, that's exactly what I was looking for, C++ keeps becoming more and more inviting every day. :) Nick Parker
              **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


              **

              1 Reply Last reply
              0
              • M Michael Dunn

                The LP and P prefixes mean the same thing these days. The difference is a leftover from the days when there were near and far pointers (L = long, indicating a far pointer). I just posted an article about strings[^], and I have part 2 almost done which covers the various wrapper classes and how to convert among them. :) --Mike-- Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

                L Offline
                L Offline
                leonwoo
                wrote on last edited by
                #7

                thanks for the valuable knowledge sharing........ cheers:-D leonwoo

                1 Reply Last reply
                0
                • N Nick Parker

                  leonwoo wrote: IniLoader.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z) Are you possibly passing it the string literal where it may need a pointer to it? :confused: Have you looked at this MSDN page[^] Nick Parker
                  **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


                  **

                  L Offline
                  L Offline
                  leonwoo
                  wrote on last edited by
                  #8

                  thanks for the link Nick. I have doubt in what this line is doing. Can you explain it. thanks. #pragma comment(lib, "comsupp.lib") leonwoo

                  N 1 Reply Last reply
                  0
                  • L leonwoo

                    thanks for the link Nick. I have doubt in what this line is doing. Can you explain it. thanks. #pragma comment(lib, "comsupp.lib") leonwoo

                    N Offline
                    N Offline
                    Nick Parker
                    wrote on last edited by
                    #9

                    leonwoo wrote: I have doubt in what this line is doing. Can you explain it. It is telling the compiler to search the comsupp.lib while linking. :) Nick Parker
                    **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


                    **

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups