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. COM
  4. Is VariantChangeType() have problem with BSTR to VT_I4 conversion with even numbers and odd numbers

Is VariantChangeType() have problem with BSTR to VT_I4 conversion with even numbers and odd numbers

Scheduled Pinned Locked Moved COM
2 Posts 2 Posters 17 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
    Shankarcodebase
    wrote on last edited by
    #1

    Hi Guys, I am trying to round the value of long value. But i have this value in data type Variant.BSTR. I can convert to this value by changing its data type from BSTR to VT_I4 through VariantChangeType(), in this conversion this value will be get rounded to nearst integer. Again i should convert this value from VT_I4 to BSTR by VariantChangeType(). This is working fine for ODD numbers but failing for EVEN numbers. if(FAILED(VariantChangeType(&vtValue,&vtValue,VARIANT_NOVALUEPROP,VT_I4))) { ASSERT(false); } if(FAILED(VariantChangeType(&vtValue,&vtValue,VARIANT_NOVALUEPROP,VT_BSTR))) { ASSERT(false); } Ex: if vt.BSTR = "5.5" after conversion to VT_I4 its value will be 6 But if vt.BSTR = "6.5" My expected value is 7 here but after conversion to VT_I4 its value will be 6 only.....any idea please...need to set anything while using this api...

    U 1 Reply Last reply
    0
    • S Shankarcodebase

      Hi Guys, I am trying to round the value of long value. But i have this value in data type Variant.BSTR. I can convert to this value by changing its data type from BSTR to VT_I4 through VariantChangeType(), in this conversion this value will be get rounded to nearst integer. Again i should convert this value from VT_I4 to BSTR by VariantChangeType(). This is working fine for ODD numbers but failing for EVEN numbers. if(FAILED(VariantChangeType(&vtValue,&vtValue,VARIANT_NOVALUEPROP,VT_I4))) { ASSERT(false); } if(FAILED(VariantChangeType(&vtValue,&vtValue,VARIANT_NOVALUEPROP,VT_BSTR))) { ASSERT(false); } Ex: if vt.BSTR = "5.5" after conversion to VT_I4 its value will be 6 But if vt.BSTR = "6.5" My expected value is 7 here but after conversion to VT_I4 its value will be 6 only.....any idea please...need to set anything while using this api...

      U Offline
      U Offline
      Ujjwal Gangwal
      wrote on last edited by
      #2

      For me it is crashing when I am changing BSTR to VT_I4 with change type , can you please give me the solution if you found? My code looks like: varValue.ChangeType(VT_I4); //_variant_t varValue is BSTR where varValue is BSTR type and it is null, how can we change in this situation?

      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