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. pinvoke to send text in a console app

pinvoke to send text in a console app

Scheduled Pinned Locked Moved C#
question
6 Posts 3 Posters 1 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.
  • J Offline
    J Offline
    jpeternel
    wrote on last edited by
    #1

    Hi I'm trying to write a WM 5.0 console application which can send string data to a text box on a web page (Internet Explorer). Any suggestions on this?

    J A C 4 Replies Last reply
    0
    • J jpeternel

      Hi I'm trying to write a WM 5.0 console application which can send string data to a text box on a web page (Internet Explorer). Any suggestions on this?

      J Offline
      J Offline
      jpeternel
      wrote on last edited by
      #2

      I should mention this is a C# console application

      1 Reply Last reply
      0
      • J jpeternel

        Hi I'm trying to write a WM 5.0 console application which can send string data to a text box on a web page (Internet Explorer). Any suggestions on this?

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

        I thought I would also mention that this sample code below for win32 c# does nothing. It runs but no message is displayed in the console. I'm using VS 2005. I find this example all over the net. using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { [DllImport("msvcrt.dll")] public static extern int puts( [MarshalAs(UnmanagedType.LPStr)] string m); [DllImport("msvcrt.dll")] internal static extern int _flushall(); public static void Main() { puts("Hello World!"); _flushall(); return; } } }

        1 Reply Last reply
        0
        • J jpeternel

          Hi I'm trying to write a WM 5.0 console application which can send string data to a text box on a web page (Internet Explorer). Any suggestions on this?

          A Offline
          A Offline
          Adeel Chaudhry
          wrote on last edited by
          #4

          For mentioning and re-mentioning, you can always use Edit link at bottom right of your post.

          Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

          1 Reply Last reply
          0
          • J jpeternel

            Hi I'm trying to write a WM 5.0 console application which can send string data to a text box on a web page (Internet Explorer). Any suggestions on this?

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            The only way to send text to a web page, is to host that web page in your own windows application, so you can directly access and change the HTML of the page.

            Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            J 1 Reply Last reply
            0
            • C Christian Graus

              The only way to send text to a web page, is to host that web page in your own windows application, so you can directly access and change the HTML of the page.

              Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              J Offline
              J Offline
              jpeternel
              wrote on last edited by
              #6

              I dug in to some very old c code of mine for the solution. I didn't expect it to work but I'm not complaining. Here is the SIMPLE solution for anyone that is interested: Add to your project: using System.Runtime.InteropServices; [DllImport("coredll.dll")] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); Then add this function, please note many of the original C constants are not valid in C# but you can look them up and define them for WM 5.0 if you need them. My app only needed to worry about alphanumeric data, no special characters. static void SendKeyStroke(int mevent) { //******************************************************* //send character to screen by simulating a key press //******************************************************* int evt = 0; byte keyCode = 0x00; //SPECIAL KEYS ************* const int KEYEVENTF_EXTENDEDKEY = 0x1; const int KEYEVENTF_KEYUP = 0x2; const int VK_RETURN = 0x0D; const int VK_SHIFT = 0x10; const int VK_SPACE = 0x20; //************************** evt = mevent; /* //these codes are not defined switch(mevent) { case 258: evt = VK_DOWN; break; //down arrow case 259: evt = VK_LEFT; break; //left arrow case 300: evt = VK_RETURN; break; //return key case 301: evt = VK_UP; break; //up arrow case 302: evt = VK_BACK; break; //back space key case 10: evt = NULL; break; //do nothing case 59: evt = VK_SEMICOLON; break; // ; case 61: evt = VK_EQUAL; break; // = case 44: evt = VK_COMMA; break; // , case 45: evt = VK_HYPHEN; break; // - case 46: evt = VK_PERIOD; break; // . case 47: evt = VK_SLASH; break; // / case 91: evt = VK_LBRACKET; break; // [ case 92: evt = VK_BACKSLASH; break; // "\" char case 93: evt = VK_RBRACKET; break; // ] case 39: evt = VK_APOSTROPHE; break; // ' //shifted keys(same order as above) case 58: evt = VK_SEMICOLON; keybd_event(VK_SHIFT, 0, 0, 0); break; //colon : case 43: evt = VK_EQUAL; keybd_event(VK_SHIFT, 0, 0, 0); break;//plus +

              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