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. How to pass string from C# to C++ (COM)

How to pass string from C# to C++ (COM)

Scheduled Pinned Locked Moved COM
questioncsharpc++comtutorial
5 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.
  • S Offline
    S Offline
    Stevo Z
    wrote on last edited by
    #1

    hi, I've a COM object created in C++ , used in C# . I need to pass a string to that COM method, but always when I send string from C# , only first character occurs on C++ side. COM Method: STDMETHODIMP Initialize(LPTSTR a, LPTSTR b); { cout << "a: " << a << " b:" << b << endl; .... } if I call this method on that COM object (wrapped in C#) IMyObject.Initialize("one", "two"); only thing i get in console is a:o b:t (instead of "a:one b:two") how can i get whole size of string ??

    S S C L 4 Replies Last reply
    0
    • S Stevo Z

      hi, I've a COM object created in C++ , used in C# . I need to pass a string to that COM method, but always when I send string from C# , only first character occurs on C++ side. COM Method: STDMETHODIMP Initialize(LPTSTR a, LPTSTR b); { cout << "a: " << a << " b:" << b << endl; .... } if I call this method on that COM object (wrapped in C#) IMyObject.Initialize("one", "two"); only thing i get in console is a:o b:t (instead of "a:one b:two") how can i get whole size of string ??

      S Offline
      S Offline
      Sujit Gupta
      wrote on last edited by
      #2

      here you pass as array may be it solve ur problem

      Sujit

      1 Reply Last reply
      0
      • S Stevo Z

        hi, I've a COM object created in C++ , used in C# . I need to pass a string to that COM method, but always when I send string from C# , only first character occurs on C++ side. COM Method: STDMETHODIMP Initialize(LPTSTR a, LPTSTR b); { cout << "a: " << a << " b:" << b << endl; .... } if I call this method on that COM object (wrapped in C#) IMyObject.Initialize("one", "two"); only thing i get in console is a:o b:t (instead of "a:one b:two") how can i get whole size of string ??

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

        Try to send StringBuilder instances from C# application..

        Cheers, Suresh

        1 Reply Last reply
        0
        • S Stevo Z

          hi, I've a COM object created in C++ , used in C# . I need to pass a string to that COM method, but always when I send string from C# , only first character occurs on C++ side. COM Method: STDMETHODIMP Initialize(LPTSTR a, LPTSTR b); { cout << "a: " << a << " b:" << b << endl; .... } if I call this method on that COM object (wrapped in C#) IMyObject.Initialize("one", "two"); only thing i get in console is a:o b:t (instead of "a:one b:two") how can i get whole size of string ??

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          Have a look at this [^]. :)

          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.

          1 Reply Last reply
          0
          • S Stevo Z

            hi, I've a COM object created in C++ , used in C# . I need to pass a string to that COM method, but always when I send string from C# , only first character occurs on C++ side. COM Method: STDMETHODIMP Initialize(LPTSTR a, LPTSTR b); { cout << "a: " << a << " b:" << b << endl; .... } if I call this method on that COM object (wrapped in C#) IMyObject.Initialize("one", "two"); only thing i get in console is a:o b:t (instead of "a:one b:two") how can i get whole size of string ??

            L Offline
            L Offline
            lafleon
            wrote on last edited by
            #5

            Hello, You need to use BSTR instead of LPTSTR in your server. Regards

            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