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. C#
  4. Using String Buffers of Win32 Libraries in C#

Using String Buffers of Win32 Libraries in C#

Scheduled Pinned Locked Moved C#
csharpfunctionalquestion
2 Posts 2 Posters 2 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.
  • Y Offline
    Y Offline
    yyf
    wrote on last edited by
    #1

    Hi, everyone For functions in Win32 libraries that will copy a string value into a string buffer, I try to use string. It works. But recently, I read an article about this, it suggests to use StringBuilder instead of string. Because string type is an immutable type in .Net. If using string for string buffer, it could corrupt the temporary buffer created by the marshaler when a string is translated or corrupt the managed heap. But my program works pretty good and I saw some other people's code is doing the same thing as min. Can anyone give me more ideas about this? Thanks in advance.

    H 1 Reply Last reply
    0
    • Y yyf

      Hi, everyone For functions in Win32 libraries that will copy a string value into a string buffer, I try to use string. It works. But recently, I read an article about this, it suggests to use StringBuilder instead of string. Because string type is an immutable type in .Net. If using string for string buffer, it could corrupt the temporary buffer created by the marshaler when a string is translated or corrupt the managed heap. But my program works pretty good and I saw some other people's code is doing the same thing as min. Can anyone give me more ideas about this? Thanks in advance.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      I've been using string almost every time without problem, and so does Microsoft most of the time in the Framework Class Library (FCL) for various native API P/Invoke declarations and struct fields. It wouldn't hurt to use a StringBuilder instead, but so long as you take care of allocating and freeing your strings appropriately (when necessary), you probably should be fine.

      Microsoft MVP, Visual C# My Articles

      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