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. String to char* in DLL

String to char* in DLL

Scheduled Pinned Locked Moved C#
xmlquestion
5 Posts 4 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.
  • L Offline
    L Offline
    leslie wu
    wrote on last edited by
    #1

    Dear All, I have a DLL with method signature like this : void printname (char* name) I tried using the following code to to make use of my method: ----------------------- string s="abc.xml"; char[] b = new char[100]; s.CopyTo(0,b,0,20); unsafe { fixed (char* p=b); printname(p); } ------------------------ but it seems not working.... can anyone give me some hints ?? Thanks, Leslie

    S J P 3 Replies Last reply
    0
    • L leslie wu

      Dear All, I have a DLL with method signature like this : void printname (char* name) I tried using the following code to to make use of my method: ----------------------- string s="abc.xml"; char[] b = new char[100]; s.CopyTo(0,b,0,20); unsafe { fixed (char* p=b); printname(p); } ------------------------ but it seems not working.... can anyone give me some hints ?? Thanks, Leslie

      S Offline
      S Offline
      Shyam K Pananghat
      wrote on last edited by
      #2

      (char* name) Means it is a single char right ? or else it should be (char** name) if it is an array. May be it needs the first Position. try s[0] where s is a string in your case

      Shyam.. My Blog dotnetscoups.blogspot.com

      1 Reply Last reply
      0
      • L leslie wu

        Dear All, I have a DLL with method signature like this : void printname (char* name) I tried using the following code to to make use of my method: ----------------------- string s="abc.xml"; char[] b = new char[100]; s.CopyTo(0,b,0,20); unsafe { fixed (char* p=b); printname(p); } ------------------------ but it seems not working.... can anyone give me some hints ?? Thanks, Leslie

        J Offline
        J Offline
        Jimmanuel
        wrote on last edited by
        #3

        MSDN[^] another reference : MSDN[^]


        Last modified: 18mins after originally posted --

        1 Reply Last reply
        0
        • L leslie wu

          Dear All, I have a DLL with method signature like this : void printname (char* name) I tried using the following code to to make use of my method: ----------------------- string s="abc.xml"; char[] b = new char[100]; s.CopyTo(0,b,0,20); unsafe { fixed (char* p=b); printname(p); } ------------------------ but it seems not working.... can anyone give me some hints ?? Thanks, Leslie

          P Online
          P Online
          PIEBALDconsult
          wrote on last edited by
          #4

          You don't need the char array. char* tends to be strings, you may be able to pass a .net string in directly. Otherwise, maybe fixed (char* p=s) Plus you shouldn't have the semi-colon after the fixed statement.

          L 1 Reply Last reply
          0
          • P PIEBALDconsult

            You don't need the char array. char* tends to be strings, you may be able to pass a .net string in directly. Otherwise, maybe fixed (char* p=s) Plus you shouldn't have the semi-colon after the fixed statement.

            L Offline
            L Offline
            leslie wu
            wrote on last edited by
            #5

            Dear All, You have be soo helpful !! I let you know which one is working as soon as get back from home !!! Regards, Leslie

            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