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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. COM
  4. BSTR and char*

BSTR and char*

Scheduled Pinned Locked Moved COM
questioncomjson
3 Posts 2 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.
  • C Offline
    C Offline
    cppshishu
    wrote on last edited by
    #1

    Dear friends, What is the difference between BSTR and char*. I am writing a COM dll. It has an API which accepts a string (like patient name). Which datatype should be used? BSTR or char*? Please advice me. Thanks in advance Shihab

    CPalliniC 1 Reply Last reply
    0
    • C cppshishu

      Dear friends, What is the difference between BSTR and char*. I am writing a COM dll. It has an API which accepts a string (like patient name). Which datatype should be used? BSTR or char*? Please advice me. Thanks in advance Shihab

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Loosely speaking, BSTR is a strange beast, it is zero-terminated like a standard C-string, but it is prefixed by its length like a Pascal one (dont' worry about that, there are API like SysAllocString, or even classes, like _bstr_t, that do the job for you). That stated, BSTR is used for automation, so, if you have to interact with automation clients (for instance, scripting languages) then you have to use BSTR (BTW your server also needs to implement a dual interface...). On the other hand, if your client is a standard Window application, written in C/C++, you can go also with char * (also Visual Basic code will be able to access you component, in a way similar to the one used to access Win32 API functionalities). Hope that helps. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      In testa che avete, signor di Ceprano?

      C 1 Reply Last reply
      0
      • CPalliniC CPallini

        Loosely speaking, BSTR is a strange beast, it is zero-terminated like a standard C-string, but it is prefixed by its length like a Pascal one (dont' worry about that, there are API like SysAllocString, or even classes, like _bstr_t, that do the job for you). That stated, BSTR is used for automation, so, if you have to interact with automation clients (for instance, scripting languages) then you have to use BSTR (BTW your server also needs to implement a dual interface...). On the other hand, if your client is a standard Window application, written in C/C++, you can go also with char * (also Visual Basic code will be able to access you component, in a way similar to the one used to access Win32 API functionalities). Hope that helps. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        C Offline
        C Offline
        cppshishu
        wrote on last edited by
        #3

        thank u

        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