Konsole öffnen
-
Hallo Leute,
ich versuche ein Programm zu schreiben, vielleicht ist genau da der Fehler ^^
Ne Spass bei Seite ich will eigentlich nur aus einem Fenster heraus die Konsole öffnen und ihr dann mit teilen dass sie meinem Fenster untergeordnet ist.
Aber soweit bin ich ja noch gar nicht, mom versuch ich nur via CreateProces mal die Konsole zu "starten" das allerdings nicht mit Erfolg
Ich poste einfach mal den Code#include <windows.h> #include <tchar.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow) { HWND hwnd; MSG msg; WNDCLASSEX wndclassex; STARTUPINFO si; PROCESS_INFORMATION pi; SECURITY_ATTRIBUTES secattr; HANDLE rPipe, wPipe; ZeroMemory( &si, sizeof(si) ); ZeroMemory( &pi, sizeof(pi) ); ZeroMemory( &secattr, sizeof(secattr) ); static TCHAR szAppName[] = TEXT ("ConsoleDesktop"); LPTSTR szCmdline = _tcsdup(_T("Console")); secattr.nLength = sizeof(secattr); secattr.bInheritHandle = TRUE; CreatePipe(&rPipe,&wPipe,&secattr,0); si.cb = sizeof(si); wndclassex.cbSize = sizeof(WNDCLASSEX); wndclassex.style = CS_HREDRAW | CS_VREDRAW; wndclassex.lpfnWndProc = WndProc; wndclassex.cbClsExtra = 0; wndclassex.cbWndExtra = 0; wndclassex.hInstance = hInstance; wndclassex.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclassex.hCursor = LoadCursor (NULL, IDC_ARROW); wndclassex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclassex.lpszMenuName = NULL; wndclassex.lpszClassName = szAppName; wndclassex.hIconSm = wndclassex.hIcon; if (!RegisterClassEx (&wndclassex)) { MessageBox (NULL, TEXT ("RegisterClassEx fehlgeschlagen!"), szAppName, MB_ICONERROR); return -1; } hwnd = CreateWindowEx(WS_EX_APPWINDOW, szAppName, TEXT (""), WS_VISIBLE | WS_POPUPWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); if( !CreateProcess( NULL,_T("cmd"),NULL,NULL,TRUE, NORMAL_PRIORITY_CLASS|CREATE_NEW_CONSOLE, NULL,NULL,&si,&pi)) //HIER BRICHT ALLES ZUSAMMEN UND ICH WEIS NICHT WIESO {MessageBox(0,_T("ohoh"),_T("ohoh"),0);} while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } // Die Hauptnachrichtenschleife LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch (message) { case WM_DESTROY: PostQuitMessage (0); return (0); } return DefWindowProc (hwnd, message, wParam, lParam); }Die Fehlermeldung die ich beim starten bekomme lautet:
Unbehandelte Ausnahme bei 0x7c82f293 in api.exe: 0xC0000005: Zugriffsverletzung beim Schreiben an Position 0x0041599a.
also es muss an der STARTUPINFO oder PROCESS_INFORMATION liegen aber ich komm nicht dahinter
need help
-
Definier
STARTUPINFO si und
PROCESS_INFORMATION pi
mal global. Bei mir geht es dann, ansonsten nicht.