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. Fire Event BSTR with NULL character

Fire Event BSTR with NULL character

Scheduled Pinned Locked Moved COM
c++com
6 Posts 5 Posters 3 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
    chetanjoshi9
    wrote on last edited by
    #1

    Hello sir, I have created the COM component in VC6.0 using ATL 3.0 I am using it in VB6.0 I have added the BSTR Event. I want to pass the string with NULL character in between the string from VC to VB e.g. I want to fire a event with string "ABC\0XYZ" So I can get the complete string in VB as ABC[]XYZ [] - indicates box as unicode character. But I am getting only "ABC" string. Please tell me the way to pass the string with NULL character from vc to vb. It's very urgent. Please do the needful. Thanks.

    S J L 3 Replies Last reply
    0
    • C chetanjoshi9

      Hello sir, I have created the COM component in VC6.0 using ATL 3.0 I am using it in VB6.0 I have added the BSTR Event. I want to pass the string with NULL character in between the string from VC to VB e.g. I want to fire a event with string "ABC\0XYZ" So I can get the complete string in VB as ABC[]XYZ [] - indicates box as unicode character. But I am getting only "ABC" string. Please tell me the way to pass the string with NULL character from vc to vb. It's very urgent. Please do the needful. Thanks.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Note: Without seeing any of your code, I'm just guessing... It's probably because when you create the BSTR, you let it count characters to determine its length, rather than telling it what the length actually is. Any string length function in C/C++ will see a NULL as the end of string. So, create your BSTR like this, telling it what its length is:

      BST b = SysAllocStringLen(L"ABC\0XYZ", 7);

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

      C 1 Reply Last reply
      0
      • S Stuart Dootson

        Note: Without seeing any of your code, I'm just guessing... It's probably because when you create the BSTR, you let it count characters to determine its length, rather than telling it what the length actually is. Any string length function in C/C++ will see a NULL as the end of string. So, create your BSTR like this, telling it what its length is:

        BST b = SysAllocStringLen(L"ABC\0XYZ", 7);

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

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

        Still I am getting only ABC in VB So please tell me how to send full string. I am getting what you have told me. but I want to transfer this full string from vc to vb. So please tell me the solution It's very urgent Thanks for help.

        S 1 Reply Last reply
        0
        • C chetanjoshi9

          Hello sir, I have created the COM component in VC6.0 using ATL 3.0 I am using it in VB6.0 I have added the BSTR Event. I want to pass the string with NULL character in between the string from VC to VB e.g. I want to fire a event with string "ABC\0XYZ" So I can get the complete string in VB as ABC[]XYZ [] - indicates box as unicode character. But I am getting only "ABC" string. Please tell me the way to pass the string with NULL character from vc to vb. It's very urgent. Please do the needful. Thanks.

          J Offline
          J Offline
          Jonathan Davies
          wrote on last edited by
          #4

          As I recall you won't be able to do as you want, either the ATL Event Wizard generated code sees the internal NULL and loses the rest (even with the BSTR length set) or VB will see a a NULL terminated string. I'm pretty sure You'll have do do more one way or the other. Maybe pass an array of characters?

          1 Reply Last reply
          0
          • C chetanjoshi9

            Still I am getting only ABC in VB So please tell me how to send full string. I am getting what you have told me. but I want to transfer this full string from vc to vb. So please tell me the solution It's very urgent Thanks for help.

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            This begs an obvious question: can VB handle strings with embedded NULLs? Many of C's CRT functions such as wcscmp can't for example.

            Steve

            1 Reply Last reply
            0
            • C chetanjoshi9

              Hello sir, I have created the COM component in VC6.0 using ATL 3.0 I am using it in VB6.0 I have added the BSTR Event. I want to pass the string with NULL character in between the string from VC to VB e.g. I want to fire a event with string "ABC\0XYZ" So I can get the complete string in VB as ABC[]XYZ [] - indicates box as unicode character. But I am getting only "ABC" string. Please tell me the way to pass the string with NULL character from vc to vb. It's very urgent. Please do the needful. Thanks.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              The NULL character is your problem. Try replacing it with some other unique Unicode character which both parts of your application can recognise. Alternatively put the box character in your source string in the first place.

              It's time for a new signature.

              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