E
hi, noch ein versuch
ich bekomms nicht hin ... woran könnte es liegen??
hier mal etwas testcode, vielleicht hilfts ja?!:
#include <windows.h>
#include <process.h>
#define ID_EDIT 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
TCHAR szAppName[] = TEXT ("PopPad1") ;
LPTSTR comandline;
LPTSTR *test;
int *pNumArgs;
unsigned long bio; //bytes in/out
unsigned long bio2;
unsigned long exitcode=0;
unsigned long avail;
static HWND hwndEdit;
TCHAR buf[10000]; //in buffer
/*const */TCHAR buffer[6]="dir\r\n"; //out buffer
/*const */TCHAR buffer2[1024];//="ping zimmer2\r\n";
STARTUPINFO si;
SECURITY_ATTRIBUTES sa;
PROCESS_INFORMATION pi;
HANDLE read, newread, write, newwrite; //pipe handles
// Global variable
CRITICAL_SECTION CriticalSection;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
comandline=szCmdLine;
/*int nArgs;
comandline=GetCommandLine();
test = CommandLineToArgvW(comandline, &nArgs);
if( NULL == test )
{
MessageBox (NULL, TEXT ("Fehler"),
szAppName, 0) ;
return 0;
}
comandline+=lstrlen(test[0])+3;
MessageBox (NULL, comandline,
szAppName, 0) ;*/
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{ // UNICODE-Compilierung ist die einzige realistische Fehlermöglichkeit
MessageBox (NULL, TEXT ("Programm arbeitet mit Unicode und setzt Windows NT voraus!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
InitializeCriticalSection(&CriticalSection);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
DeleteCriticalSection(&CriticalSection);
return (int) msg.wParam ;
}
void ThreadProc(PVOID pParam)
{
while(true)
{
WaitForSingleObject(pi.hProcess,true);
PeekNamedPipe(newread,buf,10000,NULL,&avail,NULL);
if(avail!=0)
{
RtlZeroMemory(&buf,10000);
//Hier darf uns nichts zwischen funken!
EnterCriticalSection(&CriticalSection);
ReadFile(newread,buf,10000,&bio,NULL);
SendMessage(hwndEdit,EM_SETSEL,-1,0);
SendMessage(hwndEdit,EM_REPLACESEL,FALSE,(LPARAM)buf);
//ok, jetzt kann jemand anderes übernehmen
LeaveCriticalSection(&CriticalSection);
}
}
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static LRESULT lResult;
switch(message)
{//dir funzt sofort, regedit oder ähnliches nicht!??(erst nach erneutem senden) warum
case WM_RBUTTONDOWN:
WriteFile(newwrite,"regedit\r\n",9,&bio2,NULL);
return 0 ;
case WM_LBUTTONDOWN://funktioniert ohne probleme
WriteFile(newwrite,"ping\r\n",6,&bio2,NULL);
return 0 ;//statt ping könnte man auch dir oder so machen
case WM_CREATE :
hwndEdit = CreateWindow (TEXT ("edit"), NULL, WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL, 0, 0, 0, 0, hWnd, (HMENU) ID_EDIT,((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
sa.lpSecurityDescriptor = NULL;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true; //allow inheritable handles
//Pipe to read from Child
if(!CreatePipe(&newread,&read,&sa,0))
{
MessageBox(hWnd,TEXT("CreatePipe"),TEXT("FEHLER"),0);
CloseHandle(read);
CloseHandle(newread);
return -1;
}
//Pipe to write to Child
if(!CreatePipe(&write,&newwrite,&sa,0))
{
MessageBox(hWnd,TEXT("CreatePipe"),TEXT("FEHLER"),0);
CloseHandle(write);
CloseHandle(newwrite);
return -1;
}
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdOutput= read;
si.hStdError=read;
si.hStdInput=write;
si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
//spawn the child process
if (!CreateProcess(NULL,comandline,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
{
MessageBox(hWnd,TEXT("CreateProcess"),TEXT("FEHLER"),0);
CloseHandle(read);
CloseHandle(newread);
CloseHandle(write);
CloseHandle(newwrite);
return -1;
}
//not needed
CloseHandle(write);
CloseHandle(read);
_beginthread(ThreadProc,0, NULL);
return 0 ;
case WM_SETFOCUS :
SetFocus (hwndEdit) ;
return 0 ;
case WM_SIZE :
MoveWindow (hwndEdit, 0, 0, 600, 500, TRUE) ;
return 0 ;
case WM_DESTROY :
//clean up some stuff
TerminateProcess(pi.hProcess,0);
CloseHandle(newread);
CloseHandle(newwrite);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hWnd, message, wParam, lParam) ;
}
bitte nichts stilistisches beanstanden soll ein reines testprogramm sein!!
das problem tritt bei WM_RBUTTONDOWN auf, rechtsklick irgend wo im rechten bereich des festers...
man sollte, nachdem das prompt nach dem start ausgegeben wurde, alles löschen und zb durch "regedit"
achja, als komandozeilenparameter bitte "cmd"
ich danke für eventuelle mühen
mfg
error