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. cannot convert from string to System.IntPtr

cannot convert from string to System.IntPtr

Scheduled Pinned Locked Moved C#
c++helpquestion
3 Posts 3 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.
  • S Offline
    S Offline
    steve_rm
    wrote on last edited by
    #1

    Hello, I have a P/Invoke to a C++ function:

    int dll_registerAccount(char* uri, char* reguri, char*);

    So I have done this:

    [DllImport("pjsipDlld")]
    static extern int dll_registerAccount(IntPtr uri,
    IntPtr reguri);

    When I use this in my code:

    success = dll_registerAccount("Bob", "Joe");

    I get the following error message: cannot convert from string to System.IntPtr Am I going about this the wrong way? Many thanks for any advice,

    D L 2 Replies Last reply
    0
    • S steve_rm

      Hello, I have a P/Invoke to a C++ function:

      int dll_registerAccount(char* uri, char* reguri, char*);

      So I have done this:

      [DllImport("pjsipDlld")]
      static extern int dll_registerAccount(IntPtr uri,
      IntPtr reguri);

      When I use this in my code:

      success = dll_registerAccount("Bob", "Joe");

      I get the following error message: cannot convert from string to System.IntPtr Am I going about this the wrong way? Many thanks for any advice,

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Change the IntPtr in your declaration to string and you might be all set.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      1 Reply Last reply
      0
      • S steve_rm

        Hello, I have a P/Invoke to a C++ function:

        int dll_registerAccount(char* uri, char* reguri, char*);

        So I have done this:

        [DllImport("pjsipDlld")]
        static extern int dll_registerAccount(IntPtr uri,
        IntPtr reguri);

        When I use this in my code:

        success = dll_registerAccount("Bob", "Joe");

        I get the following error message: cannot convert from string to System.IntPtr Am I going about this the wrong way? Many thanks for any advice,

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, when strings are input parameters and the native code is dealing with ANSI, not Unicode, then just typing the parameters as string should be sufficient. for output parameters, you would need a StringBuilder instance with sufficient capacity; and for Unicode native code, you would have to add "CharSet=CharSet.Unicode" to your DllImport. :)

        Luc Pattyn


        Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


        Local announcement (Antwerp region): Lange Wapper? Neen!


        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