C# String conversion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TmVvbWl0ZQ==?=

    C# String conversion

    Hi, I'm having some difficulty converting a String to a std::basic_stri ng
    (c++).

    I've tried using StringBuilder and Marshal.LPxxxx , no luck.

    I consistently get AccessViolation errors.

    I've been reading all day but I can't seem to find the same problem posted
    anywhere.

    bool NNSMCAPI::Clien t::initialize(c lass std::basic_stri ng<unsigned
    short,struct std::char_trait s<unsigned short>,class std::allocator< unsigned
    short const &)

    Can anyone help me with this issue?

    thanks!



  • G Himangi

    #2
    Re: C# String conversion

    It wont work becuase Marshal.LPxxxx does not convert to basic_string, but
    only gets you a pointer to the raw string charcters in memory.

    You can try using a wrapper around your function which takes LPTSTR, this
    way you can use Marshal.LPxxxx

    ---------
    - G Himangi, LogicNP Software http://www.ssware.com
    Shell MegaPack: GUI Controls For Drop-In Windows Explorer like File/Folder
    Browsing Functionality (.Net & ActiveX Editions).
    EZNamespaceExte nsions: Develop namespace extensions rapidly in .Net and
    MFC/ATL/C++
    EZShellExtensio ns: Develop all shell extensions,expl orer bars and BHOs
    rapidly in .Net & MFC/ATL/C++
    ---------


    "Neomite" <Neomite@discus sions.microsoft .comwrote in message
    news:0B4CAA10-6D81-4F3A-8FE8-6269631B8D21@mi crosoft.com...
    Hi, I'm having some difficulty converting a String to a std::basic_stri ng
    (c++).
    >
    I've tried using StringBuilder and Marshal.LPxxxx , no luck.
    >
    I consistently get AccessViolation errors.
    >
    I've been reading all day but I can't seem to find the same problem posted
    anywhere.
    >
    bool NNSMCAPI::Clien t::initialize(c lass std::basic_stri ng<unsigned
    short,struct std::char_trait s<unsigned short>,class
    std::allocator< unsigned
    short const &)
    >
    Can anyone help me with this issue?
    >
    thanks!
    >
    >
    >

    Comment

    • =?Utf-8?B?TmVvbWl0ZQ==?=

      #3
      Re: C# String conversion

      I read a few similiar posts that talked about using StringBuilder? Are you
      familiar with this approach?

      "G Himangi" wrote:
      It wont work becuase Marshal.LPxxxx does not convert to basic_string, but
      only gets you a pointer to the raw string charcters in memory.
      >
      You can try using a wrapper around your function which takes LPTSTR, this
      way you can use Marshal.LPxxxx
      >
      ---------
      - G Himangi, LogicNP Software http://www.ssware.com
      Shell MegaPack: GUI Controls For Drop-In Windows Explorer like File/Folder
      Browsing Functionality (.Net & ActiveX Editions).
      EZNamespaceExte nsions: Develop namespace extensions rapidly in .Net and
      MFC/ATL/C++
      EZShellExtensio ns: Develop all shell extensions,expl orer bars and BHOs
      rapidly in .Net & MFC/ATL/C++
      ---------
      >
      >
      "Neomite" <Neomite@discus sions.microsoft .comwrote in message
      news:0B4CAA10-6D81-4F3A-8FE8-6269631B8D21@mi crosoft.com...
      Hi, I'm having some difficulty converting a String to a std::basic_stri ng
      (c++).

      I've tried using StringBuilder and Marshal.LPxxxx , no luck.

      I consistently get AccessViolation errors.

      I've been reading all day but I can't seem to find the same problem posted
      anywhere.

      bool NNSMCAPI::Clien t::initialize(c lass std::basic_stri ng<unsigned
      short,struct std::char_trait s<unsigned short>,class
      std::allocator< unsigned
      short const &)

      Can anyone help me with this issue?

      thanks!

      >
      >
      >

      Comment

      • G Himangi

        #4
        Re: C# String conversion

        Yes, but that works only if data flow is from called function to yourself.
        In this case, if i understand correctly, its the other way round.

        ---------
        - G Himangi, LogicNP Software http://www.ssware.com
        Shell MegaPack: GUI Controls For Drop-In Windows Explorer like File/Folder
        Browsing Functionality (.Net & ActiveX Editions).
        EZNamespaceExte nsions: Develop namespace extensions rapidly in .Net and
        MFC/ATL/C++
        EZShellExtensio ns: Develop all shell extensions,expl orer bars and BHOs
        rapidly in .Net & MFC/ATL/C++
        ---------

        "Neomite" <Neomite@discus sions.microsoft .comwrote in message
        news:F5648F6B-03BF-4004-BCFD-1CB3825BFBD4@mi crosoft.com...
        >I read a few similiar posts that talked about using StringBuilder? Are you
        familiar with this approach?
        >
        "G Himangi" wrote:
        >
        >It wont work becuase Marshal.LPxxxx does not convert to basic_string, but
        >only gets you a pointer to the raw string charcters in memory.
        >>
        >You can try using a wrapper around your function which takes LPTSTR, this
        >way you can use Marshal.LPxxxx
        >>
        >---------
        >- G Himangi, LogicNP Software http://www.ssware.com
        >Shell MegaPack: GUI Controls For Drop-In Windows Explorer like
        >File/Folder
        >Browsing Functionality (.Net & ActiveX Editions).
        >EZNamespaceExt ensions: Develop namespace extensions rapidly in .Net and
        >MFC/ATL/C++
        >EZShellExtensi ons: Develop all shell extensions,expl orer bars and BHOs
        >rapidly in .Net & MFC/ATL/C++
        >---------
        >>
        >>
        >"Neomite" <Neomite@discus sions.microsoft .comwrote in message
        >news:0B4CAA1 0-6D81-4F3A-8FE8-6269631B8D21@mi crosoft.com...
        Hi, I'm having some difficulty converting a String to a
        std::basic_stri ng
        (c++).
        >
        I've tried using StringBuilder and Marshal.LPxxxx , no luck.
        >
        I consistently get AccessViolation errors.
        >
        I've been reading all day but I can't seem to find the same problem
        posted
        anywhere.
        >
        bool NNSMCAPI::Clien t::initialize(c lass std::basic_stri ng<unsigned
        short,struct std::char_trait s<unsigned short>,class
        std::allocator< unsigned
        short const &)
        >
        Can anyone help me with this issue?
        >
        thanks!
        >
        >
        >
        >>
        >>
        >>

        Comment

        Working...