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. TextOut a BSTR

TextOut a BSTR

Scheduled Pinned Locked Moved ATL / WTL / STL
c++sysadmintutorialquestion
8 Posts 4 Posters 0 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.
  • S Offline
    S Offline
    SiddharthAtw
    wrote on last edited by
    #1

    My interface member is a BSTR Sum. { // TODO: Add your implementation code here BSTR bBuff = 0; SysAllocStringLen(bBuff,20); m_Sum = _itow((Num1 + Num2),bBuff,10); return S_OK; } It's cilent is a WIn32 Application. I just want to TextOut this BSTR.How to do it? One more thing if I want to pass data from ATL server to Client, how to do it using methods. I am straightaway using Interface data member for it.

    S B 2 Replies Last reply
    0
    • S SiddharthAtw

      My interface member is a BSTR Sum. { // TODO: Add your implementation code here BSTR bBuff = 0; SysAllocStringLen(bBuff,20); m_Sum = _itow((Num1 + Num2),bBuff,10); return S_OK; } It's cilent is a WIn32 Application. I just want to TextOut this BSTR.How to do it? One more thing if I want to pass data from ATL server to Client, how to do it using methods. I am straightaway using Interface data member for it.

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      I'm guessing this is not a UNICODE build ;) If this isn't an option, then you can use various methods to convert the BSTR to a regular char 'string'. There's an atlconv.h which you can include, then have code like this; { USES_CONVERSION; TCHAR* p = W2T( bBuff ); TextOut(....); } Alternatively if your client uses MFC you can use CString tmp( yourBSTR ); since CString has a conversion method. Another alternative is to use WideCharToMultiByte to do the conversion. (It's what the conversion macros in atlconv.h use, I believe...) Steve S

      S A 2 Replies Last reply
      0
      • S Steve S

        I'm guessing this is not a UNICODE build ;) If this isn't an option, then you can use various methods to convert the BSTR to a regular char 'string'. There's an atlconv.h which you can include, then have code like this; { USES_CONVERSION; TCHAR* p = W2T( bBuff ); TextOut(....); } Alternatively if your client uses MFC you can use CString tmp( yourBSTR ); since CString has a conversion method. Another alternative is to use WideCharToMultiByte to do the conversion. (It's what the conversion macros in atlconv.h use, I believe...) Steve S

        S Offline
        S Offline
        SiddharthAtw
        wrote on last edited by
        #3

        Thanx. that was a great help to me. I am using Win32 SDK. Is development in Win32SDK has more overhead then that of MFC? I use WIn32SDK because I am able to understand the flow, while I tried MFC at times and it seems to be overwhelming.

        S 1 Reply Last reply
        0
        • S SiddharthAtw

          Thanx. that was a great help to me. I am using Win32 SDK. Is development in Win32SDK has more overhead then that of MFC? I use WIn32SDK because I am able to understand the flow, while I tried MFC at times and it seems to be overwhelming.

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          Development can take longer using raw SDK. Depends how well you 'grok' the framework. I tend to use WTL rather than MFC, unless I have a particular need for MFC specific features, such as support for OLE compound documents. In many cases, the framework obscures your view of what's happening, until you understand it, and then it accelerates development; class = code you don't have to write. Lots of my test apps though are pure SDK, but short. Steve S

          1 Reply Last reply
          0
          • S Steve S

            I'm guessing this is not a UNICODE build ;) If this isn't an option, then you can use various methods to convert the BSTR to a regular char 'string'. There's an atlconv.h which you can include, then have code like this; { USES_CONVERSION; TCHAR* p = W2T( bBuff ); TextOut(....); } Alternatively if your client uses MFC you can use CString tmp( yourBSTR ); since CString has a conversion method. Another alternative is to use WideCharToMultiByte to do the conversion. (It's what the conversion macros in atlconv.h use, I believe...) Steve S

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Even eaiser: ::TextOutW(...) No need for conversion at all Edward

            S 1 Reply Last reply
            0
            • A Anonymous

              Even eaiser: ::TextOutW(...) No need for conversion at all Edward

              S Offline
              S Offline
              SiddharthAtw
              wrote on last edited by
              #6

              Continuing same discussion. What I want to do is to pass a BSTR from a ATL DLL to a Client? Now since Interface method can return only HRESULT. I will store the values in a Global Variable and use it in the client. Is there in Flaw on Design? I need feedback. By the way I didn't see anything like TextOutW in MSDN. Please help

              S 1 Reply Last reply
              0
              • S SiddharthAtw

                Continuing same discussion. What I want to do is to pass a BSTR from a ATL DLL to a Client? Now since Interface method can return only HRESULT. I will store the values in a Global Variable and use it in the client. Is there in Flaw on Design? I need feedback. By the way I didn't see anything like TextOutW in MSDN. Please help

                S Offline
                S Offline
                Steve S
                wrote on last edited by
                #7

                My fellow poster with no name is correct that you can use TextOutW. But unfortunately, if you run your client app on Win9x or WinME, then it won't work, as that doesn't implement TextOutW, which is why I didn't suggest it (you didn't say it was NT/2K/XP/03, so I assumed it could be any. Many API calls that take strings or characters as parameters have two versions, an ANSI version, and a UNICODE (or wide character) version. Although you use TextOut, in reality you're using either TextOutA or TextOutW, depending on whether you're compiling with _UNICODE and UNICODE defined. If you examine some of the Windows header files, you'll see definitions for both A and W functions, and then a macro which defines the base name (without A or W) as one or the other. If you've unintentionally screwed up a parameter list to CWnd::SetWindowText, for example, the compiler will often complain about 'SetWindowTextA' or 'SetWindowTextW', rather than SetWindowText, because it's getting the definition of what the word 'SetWindowText' should be from a windows header. Any time you see a reference to a function that ends with W or A, try looking in MSDN for the name without that trailing letter. MEANWHILE, back to your original question; There is a BIG flaw in your design. In the case of an in-proc ATL DLL, the global would be addressable, but that sure isn't how it's supposed to be done. Although the method can only return an HRESULT, you can pass pointers to things in, and have the method assign values indirectly (equivalent to VB's ByRef, rather than ByVal). An example would be: IDL Definition: HRESULT GetMyName( [out, retval] BSTR* pName ); HRESULT CMyObj::GetMyName( BSTR* pName) { if (pName == NULL) { return E_POINTER; // Bad address passed in... } *pName = SysAllocString(L"Steve Spencer"); return S_OK; } Client code: BSTR t = NULL; // Empty BSTR if (SUCCEEDED(pObj->GetMyName( &t ))) { // woohoo! We got a result... } else { // Handle your error gracefully... } This works because a BSTR is a pointer; you pass in the address of the pointer, and the server (your ATL DLL) fills in the value for the pointer (hence '*pName' instead of 'pName'). You also have to mark the parameter as [out] so that the marshalling code knows how to transfer data. It's marked as [retval] so that VB programmers can use your object and treat that interface method as returning a string. (BSTR means 'BASIC String') Hope this helps S<

                1 Reply Last reply
                0
                • S SiddharthAtw

                  My interface member is a BSTR Sum. { // TODO: Add your implementation code here BSTR bBuff = 0; SysAllocStringLen(bBuff,20); m_Sum = _itow((Num1 + Num2),bBuff,10); return S_OK; } It's cilent is a WIn32 Application. I just want to TextOut this BSTR.How to do it? One more thing if I want to pass data from ATL server to Client, how to do it using methods. I am straightaway using Interface data member for it.

                  B Offline
                  B Offline
                  Brigsoft
                  wrote on last edited by
                  #8

                  :wtf:I have found the best way!!! CComBSTR some(CString("some")); CString some1= some; CComBSTR and CString are exellent together!!! ================================ My Home is here!

                  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