Results 1 to 5 of 5

Thread: [RESOLVED] [2.0] string pointers?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Resolved [RESOLVED] [2.0] string pointers?

    Well I need to pass the location of a string in memory to a function. In C++ you would just do &string but what do you do in C#? I have tried many things and nothing seems to work.

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] string pointers?

    Just on C# you don't need to use Pointers and you don't need to delete them because of garbage collection. But you can use pointers. You declare them like so...

    Code:
    int *a;

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2.0] string pointers?

    Quote Originally Posted by Hell-Lord
    Just on C# you don't need to use Pointers and you don't need to delete them because of garbage collection. But you can use pointers. You declare them like so...

    Code:
    int *a;
    Ya but I need to call a function that uses the strings location.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] string pointers?

    You can also use the Marshal.StringToBSTR to get an IntPtr to an unmanaged string that you can then pass to your function. BSTRToString will convert back again if needed. Make sure you read the documentation first if you choose to use these methods.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] string pointers?

    Are you talking about a DLL function? Just use a StringBuilder, they are automatically marchalled as char*.

    (you'll have to alter your DllImport statement to change char* to Stringbuilder in your C# code).
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width