Nicholas Paldino said:
At first, thanks a lot for your effor to help me...
here it comes: (and it gives me an exception of type "The specified module
could not be found"
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.IO;
namespace WindowsApplication12
{
public class Form1 : System.Windows.Forms.Form
{
[DllImport("kernel32", SetLastError=true, ExactSpelling=true)]
static extern bool AllocConsole();
[DllImport("kernel32.dll")]
static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll")]
static extern bool SetConsoleTitle(string lpConsoleTitle);
[DllImport("Kernel32.DLL", EntryPoint="WriteConsoleW",
CallingConvention=CallingConvention.StdCall)]
public static extern bool WriteConsole
(
IntPtr hConsoleOutput, // handle to screen buffer
string lpBuffer, // write buffer
uint nNumberOfCharsToWrite, // number of characters to write
ref uint lpNumberOfCharsWritten, // number of characters written
IntPtr lpReserved // reserved
);
private const int STD_OUTPUT_HANDLE = -11;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(64, 64);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e) {
bool ok = AllocConsole();
IntPtr ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTitle("xexexe");
IntPtr intptr = new IntPtr(0);
uint dwNumberOfCharsWritten = 0;
string wbuffer = "anthonyb";
WriteConsole
(
ConsoleHandle, // handle to screen buffer
wbuffer, // write buffer
(uint) wbuffer.Length, // number of characters to write
ref dwNumberOfCharsWritten, // number of characters written
intptr // reserved
);
throw new Win32Exception();
}
}
}