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. C / C++ / MFC
  4. wprintf problem

wprintf problem

Scheduled Pinned Locked Moved C / C++ / MFC
help
13 Posts 5 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.
  • P Prakash Nadar

    roadragedave wrote: If I use printf(sz) then I get a missmatch in variable types

    printf("%s",sz); rite ???

    R Offline
    R Offline
    roadragedave
    wrote on last edited by
    #4

    Very true, I am an idiot, BUT!, when I do that I get a strange output ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠ I have never seen these characters before We have a mathematician, a different kind of mathematician, and a statistician!

    1 Reply Last reply
    0
    • R roadragedave

      Im trying to print a VARIANT value to the screen using this code TCHAR sz[MAX_PATH]; VARIANT vVal; wprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); This builds ok, but doesnt print anything to the screen If I use printf(sz) then I get a missmatch in variable types. error C2664: 'printf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const char *' Anyone got any ideas on what I can do We have a mathematician, a different kind of mathematician, and a statistician!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #5

      How about:

      wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal));

      or

      wprintf(TEXT("Load Percentage: %s\n"), V_BSTR(&vVal));


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      R 1 Reply Last reply
      0
      • D David Crow

        How about:

        wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal));

        or

        wprintf(TEXT("Load Percentage: %s\n"), V_BSTR(&vVal));


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        R Offline
        R Offline
        roadragedave
        wrote on last edited by
        #6

        No good, now I get an Unhandled Exception http://www.81x.com/Authors/roadragedave/exception.jpg We have a mathematician, a different kind of mathematician, and a statistician!

        T D 2 Replies Last reply
        0
        • R roadragedave

          No good, now I get an Unhandled Exception http://www.81x.com/Authors/roadragedave/exception.jpg We have a mathematician, a different kind of mathematician, and a statistician!

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #7

          Hmmm, this code snippet works for me:

          TCHAR sz[MAX_PATH];
          VARIANT vVal;
          vVal.vt = VT_BSTR;
          vVal.bstrVal = SysAllocString(_T("95%"));
          wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal));


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          R 2 Replies Last reply
          0
          • R roadragedave

            No good, now I get an Unhandled Exception http://www.81x.com/Authors/roadragedave/exception.jpg We have a mathematician, a different kind of mathematician, and a statistician!

            T Offline
            T Offline
            Tim Smith
            wrote on last edited by
            #8

            Your BSTR is bad. It doesn't really point to a BSTR. Tim Smith I'm going to patent thought. I have yet to see any prior art.

            1 Reply Last reply
            0
            • D David Crow

              Hmmm, this code snippet works for me:

              TCHAR sz[MAX_PATH];
              VARIANT vVal;
              vVal.vt = VT_BSTR;
              vVal.bstrVal = SysAllocString(_T("95%"));
              wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal));


              "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

              R Offline
              R Offline
              roadragedave
              wrote on last edited by
              #9

              Very nice, What my problem is, is that I am calling a function called GetProperty hRes = WmiTest.GetProperty(accClass, accProperty, accKey, &vVal); vVal, which is VARIANT, has the property value which I want to display, so how do I do this? Im sorry for being a pest on this one, thanks for your help We have a mathematician, a different kind of mathematician, and a statistician!

              1 Reply Last reply
              0
              • D David Crow

                Hmmm, this code snippet works for me:

                TCHAR sz[MAX_PATH];
                VARIANT vVal;
                vVal.vt = VT_BSTR;
                vVal.bstrVal = SysAllocString(_T("95%"));
                wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal));


                "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                R Offline
                R Offline
                roadragedave
                wrote on last edited by
                #10

                I finally got it, it was so simple in the end, I was getting an exception because I was trying to pass a uint16 to a string. For future reference if anyone has this problem wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal)); should be wsprintf(sz, _T("Load Percentage: %i\n"), V_BSTR(&vVal)); Can you spot the simple difference:doh: Thanks for all yer help everyone We have a mathematician, a different kind of mathematician.............. and a statistician!

                D 1 Reply Last reply
                0
                • R roadragedave

                  I finally got it, it was so simple in the end, I was getting an exception because I was trying to pass a uint16 to a string. For future reference if anyone has this problem wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal)); should be wsprintf(sz, _T("Load Percentage: %i\n"), V_BSTR(&vVal)); Can you spot the simple difference:doh: Thanks for all yer help everyone We have a mathematician, a different kind of mathematician.............. and a statistician!

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #11

                  roadragedave wrote: wsprintf(sz, _T("Load Percentage: %i\n"), V_BSTR(&vVal)); This is not right at all. The %i type is for signed decimal integers, which is not what V_BSTR() returns. When the V_BSTR() macro is expanded, notice that it accesses the bstrVal member of the VARIANT structure, not the intVal member. You've simply masked the problem.


                  "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                  R 1 Reply Last reply
                  0
                  • D David Crow

                    roadragedave wrote: wsprintf(sz, _T("Load Percentage: %i\n"), V_BSTR(&vVal)); This is not right at all. The %i type is for signed decimal integers, which is not what V_BSTR() returns. When the V_BSTR() macro is expanded, notice that it accesses the bstrVal member of the VARIANT structure, not the intVal member. You've simply masked the problem.


                    "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                    R Offline
                    R Offline
                    roadragedave
                    wrote on last edited by
                    #12

                    I get what you mean, however the function that gets vVal passes it back as uint16, VARIANT, I presume, is a generic data type that holds almost all simple data types and what is needed it to convert to say string, double, BSTR. Using %s threw and exception and I could not figure out using the debuging what exactly was going wrong, I took a chance and changed it to %i, and the application works.:confused: We have a mathematician, a different kind of mathematician, and a statistician!

                    D 1 Reply Last reply
                    0
                    • R roadragedave

                      I get what you mean, however the function that gets vVal passes it back as uint16, VARIANT, I presume, is a generic data type that holds almost all simple data types and what is needed it to convert to say string, double, BSTR. Using %s threw and exception and I could not figure out using the debuging what exactly was going wrong, I took a chance and changed it to %i, and the application works.:confused: We have a mathematician, a different kind of mathematician, and a statistician!

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #13

                      roadragedave wrote: ...the function that gets vVal passes it back as uint16, Which means you should be using V_INT() instead of V_BSTR().


                      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                      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