Autor Beitrag
Cäptin Pommes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 142
Erhaltene Danke: 2



BeitragVerfasst: Do 06.10.11 19:40 
hi,

kann man wenn man ein Windows Forms Projekt hat die Konsole aufrufen? wenn ja, wie soll das gehen?
storestore
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 397
Erhaltene Danke: 7

WIN 7
C#
BeitragVerfasst: Do 06.10.11 19:46 
Das kenne ich doch irrgendwo her?!
www.c-sharp-forum.de...ewtopic.php?t=107019

_________________
Der Pc ist nur so schlau, wie derjenige der in steuert!
"Don't Quit. Suffer now, and live the rest of your life as a champion"
pdelvo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 55
Erhaltene Danke: 11



BeitragVerfasst: Do 06.10.11 19:47 
user profile iconCäptin Pommes hat folgendes geschrieben Zum zitierten Posting springen:
hi,

kann man wenn man ein Windows Forms Projekt hat die Konsole aufrufen? wenn ja, wie soll das gehen?


Soll sie die ganze Zeit mitlaufen?

Wenn ja in den Projekteigenschafften auf Konsolenprojekt umschallten

Wenn Nein:

ausblenden C#-Quelltext
1:
2:
3:
4:
    [DllImport("kernel32",SetLastError=true)]
    static extern bool AllocConsole();
    [DllImport("kernel32", SetLastError = true)]
    static extern bool FreeConsole();
Cäptin Pommes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 142
Erhaltene Danke: 2



BeitragVerfasst: Fr 07.10.11 09:47 
hmm und wie läuft das wenn ich ein Konsolen projekt habe, kann ich dann die Konsole deaktivieren und aktivieren? bzw verstecken oder so?
Cäptin Pommes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 142
Erhaltene Danke: 2



BeitragVerfasst: Fr 07.10.11 11:15 
also ich hab das jetzt so:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
class Class1
    {
        [DllImport("kernel32", SetLastError = true)]
        static extern bool AllocConsole();
        [DllImport("kernel32", SetLastError = true)]
        static extern bool FreeConsole();

        public void bla()
        {
            Console.WriteLine("HALLO!!!!!!!!!!!!!");
            Console.Read();
        }
    }


aber wenn ich die die methode bla aufrufe dann passiert nichts :/ muss ich die Console noch vorher sichtbar machen? ich finde jedenfalls keine eigenschaft um das zu setzen :/
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4807
Erhaltene Danke: 1061

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Fr 07.10.11 11:27 
Hallo,

du mußt natürlich die Funktion auch noch aufrufen :gruebel:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
public void bla()
{
    Class1.AllocConsole();
            
    Console.WriteLine("HALLO!!!!!!!!!!!!!");
    Console.Read();
}

[DllImport] in Verbindung mit "extern" ist nur eine Methoden-Deklaration.

Und besser ist es diese Deklarationen in eine eigene statische Klasse (z.B. WinAPI) auszulagern. Dann sieht man anhand des Namens sofort, woher die Methode stammt:
ausblenden C#-Quelltext
1:
WinAPI.AllocConsole();					
Cäptin Pommes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 142
Erhaltene Danke: 2



BeitragVerfasst: Fr 07.10.11 11:33 
ah ^^ alles klar, vielen dank