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. Win32 API pointer question

Win32 API pointer question

Scheduled Pinned Locked Moved C#
questioncsharpjson
5 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.
  • A Offline
    A Offline
    albean
    wrote on last edited by
    #1

    Guys, I've seen this type of question before but my search did not turn up anything. Here is the C# API definition: [DllImport"user32.dll",EntryPoint="SendMessage",ExactSpelling=false,SetLastError=true)] public static extern int SendMessage(int hwnd,int wMsg,int wParam,int lParam); All the places where I call this function I use simple integers. But now I have a spot where I want to call this function and for lParam I need to pass a pointer to a null-terminated string. How do I do that?

    J J 2 Replies Last reply
    0
    • A albean

      Guys, I've seen this type of question before but my search did not turn up anything. Here is the C# API definition: [DllImport"user32.dll",EntryPoint="SendMessage",ExactSpelling=false,SetLastError=true)] public static extern int SendMessage(int hwnd,int wMsg,int wParam,int lParam); All the places where I call this function I use simple integers. But now I have a spot where I want to call this function and for lParam I need to pass a pointer to a null-terminated string. How do I do that?

      J Offline
      J Offline
      John Fisher
      wrote on last edited by
      #2

      This link should give you some valuable info: http://msdn.microsoft.com/msdntv/episode.aspx?xml=episodes/en/20030424NETFXSK/manifest.xml[^] John
      "We want to be alone when we hear too many words and we feel alone when it has been a while since anyone has spoken to us." Paul David Tripp -- War of Words

      1 Reply Last reply
      0
      • A albean

        Guys, I've seen this type of question before but my search did not turn up anything. Here is the C# API definition: [DllImport"user32.dll",EntryPoint="SendMessage",ExactSpelling=false,SetLastError=true)] public static extern int SendMessage(int hwnd,int wMsg,int wParam,int lParam); All the places where I call this function I use simple integers. But now I have a spot where I want to call this function and for lParam I need to pass a pointer to a null-terminated string. How do I do that?

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

        For recieving a string:

        //put your string in the szText member of this struct
        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
        public struct STRINGBUFFER
        {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=512)]
        public string szText;
        }

        [DllImport"user32.dll",EntryPoint="SendMessage", ExactSpelling=false,
        SetLastError=true,CharSet=CharSet.Auto)]
        public static extern int SendMessage(IntPtr hwnd,int wMsg,int wParam,out STRINGBUFFER lParam);

        For passing a string out:

        [DllImport"user32.dll",EntryPoint="SendMessage",ExactSpelling=false,
        SetLastError=true, CharSet=CharSet.Auto)]
        public static extern int SendMessage(IntPtr hwnd,int wMsg,int wParam,text lParam);

        "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
        "You must be the change you wish to see in the world." - Mahatma Gandhi

        A 1 Reply Last reply
        0
        • J J Dunlap

          For recieving a string:

          //put your string in the szText member of this struct
          [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
          public struct STRINGBUFFER
          {
          [MarshalAs(UnmanagedType.ByValTStr, SizeConst=512)]
          public string szText;
          }

          [DllImport"user32.dll",EntryPoint="SendMessage", ExactSpelling=false,
          SetLastError=true,CharSet=CharSet.Auto)]
          public static extern int SendMessage(IntPtr hwnd,int wMsg,int wParam,out STRINGBUFFER lParam);

          For passing a string out:

          [DllImport"user32.dll",EntryPoint="SendMessage",ExactSpelling=false,
          SetLastError=true, CharSet=CharSet.Auto)]
          public static extern int SendMessage(IntPtr hwnd,int wMsg,int wParam,text lParam);

          "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
          "You must be the change you wish to see in the world." - Mahatma Gandhi

          A Offline
          A Offline
          albean
          wrote on last edited by
          #4

          Thanks J, I was sort of looking for a way to do it without having to change the import. I'm able to do what I need by using "..., String lParam)". But I am wondering if there was some way I could still use the "..., int lParam)" definition and do something special in the calling statment.

          J 1 Reply Last reply
          0
          • A albean

            Thanks J, I was sort of looking for a way to do it without having to change the import. I'm able to do what I need by using "..., String lParam)". But I am wondering if there was some way I could still use the "..., int lParam)" definition and do something special in the calling statment.

            J Offline
            J Offline
            J Dunlap
            wrote on last edited by
            #5

            albean wrote: I was sort of looking for a way to do it without having to change the import. Well, I don't know of a way, short of using pointers (which I think is more time-consuming). But you can have multiple defs for the same API with the same name. All you have to do is copy the original SendMessage each time and change the lParam parameter's data type.

            "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
            "You must be the change you wish to see in the world." - Mahatma Gandhi

            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