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. C#
  4. strings in DLL calls

strings in DLL calls

Scheduled Pinned Locked Moved C#
csharpc++data-structureshelpquestion
2 Posts 1 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.
  • G Offline
    G Offline
    Gian
    wrote on last edited by
    #1

    i need to call a function of a C DLL. the function is declared as _EXTERN int __stdcall MyFunction(HWND hWndParent, LPTSTR lpszRow1, LPTSTR lpszRow2, LPTSTR lpszRow3); so i've defined in my c# code [DllImport("library.dll", CharSet=CharSet.Auto)] protected static extern Int32 MyFunction(int hWndParent, StringBuilder lpszRow1, StringBuilder lpszRow2, StringBuilder lpszRow3); in the C/C++ code i have to pass 3 strings of 42 chars (8-bit each) and the function fills the tree with some names. in c# i've created 3 StringBuilder variables and initialized to 42 of both length and max capacity. When i call the function the strings are written but the problem is that each char of the StringBuilder is of 16-bit so 2 characters are in one. Is there a way to extract each single char or to define a StringBuilder of 8-bit elements? I've tried to use string and LPTStr parameters for the function but the DLL doesnt seem to copy anything in my strings. Gianmaria

    G 1 Reply Last reply
    0
    • G Gian

      i need to call a function of a C DLL. the function is declared as _EXTERN int __stdcall MyFunction(HWND hWndParent, LPTSTR lpszRow1, LPTSTR lpszRow2, LPTSTR lpszRow3); so i've defined in my c# code [DllImport("library.dll", CharSet=CharSet.Auto)] protected static extern Int32 MyFunction(int hWndParent, StringBuilder lpszRow1, StringBuilder lpszRow2, StringBuilder lpszRow3); in the C/C++ code i have to pass 3 strings of 42 chars (8-bit each) and the function fills the tree with some names. in c# i've created 3 StringBuilder variables and initialized to 42 of both length and max capacity. When i call the function the strings are written but the problem is that each char of the StringBuilder is of 16-bit so 2 characters are in one. Is there a way to extract each single char or to define a StringBuilder of 8-bit elements? I've tried to use string and LPTStr parameters for the function but the DLL doesnt seem to copy anything in my strings. Gianmaria

      G Offline
      G Offline
      Gian
      wrote on last edited by
      #2

      i've resolved changing CharSet=CharSet.Auto to CharSet=CharSet.Ansi in the function definition :)

      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