Click here to Skip to main content
15,887,294 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: ReleaseBuffer() of CSimpleString is not working. Pin
Andrew Brock3-Feb-11 19:10
Andrew Brock3-Feb-11 19:10 
GeneralRe: ReleaseBuffer() of CSimpleString is not working. Pin
Amrit Agr3-Feb-11 21:38
Amrit Agr3-Feb-11 21:38 
QuestionDos command Pin
MsmVc3-Feb-11 18:17
MsmVc3-Feb-11 18:17 
QuestionRe: Dos command Pin
Rajesh R Subramanian3-Feb-11 18:39
professionalRajesh R Subramanian3-Feb-11 18:39 
AnswerRe: Dos command Pin
Andrew Brock3-Feb-11 18:49
Andrew Brock3-Feb-11 18:49 
GeneralRe: Dos command Pin
MsmVc4-Feb-11 0:27
MsmVc4-Feb-11 0:27 
AnswerRe: Dos comman Pin
Cool_Dev3-Feb-11 23:03
Cool_Dev3-Feb-11 23:03 
AnswerRe: Dos command Pin
csrss3-Feb-11 23:25
csrss3-Feb-11 23:25 
C WinAPI solution (you can adopt it in mfc easily i think):

#include <windows.h>
#include <stdio.h>

char * ExecuteCMD(char * command)
{
		SECURITY_ATTRIBUTES sec;
		PROCESS_INFORMATION pi;
        STARTUPINFO si;
		HANDLE hOutR, hOutW;
		DWORD BTAvail;
		char * Result = NULL;
		char * cmdline = NULL;
		char cmdpath[256];
		OSVERSIONINFO OSVersionInfo;
		DWORD Read = 0;

			ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
			ZeroMemory(&sec, sizeof(SECURITY_ATTRIBUTES));
			sec.nLength = sizeof(SECURITY_ATTRIBUTES);
			sec.bInheritHandle = TRUE;
			sec.lpSecurityDescriptor = NULL;
	
	if (CreatePipe(&hOutR, &hOutW, &sec, 0)) 
	{
				ZeroMemory(&si, sizeof(STARTUPINFO));
				si.cb = sizeof(STARTUPINFO);
				si.hStdOutput = hOutW;
				si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;

			cmdline = (char *) GlobalAlloc(GMEM_FIXED, (7 + lstrlen(command)));
			lstrcat(lstrcpy(cmdline, " /a /c "), command);

			OSVersionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
			GetVersionEx (&OSVersionInfo);

			if (OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
			{
				GetEnvironmentVariable("ComSpec", cmdpath, 2048);
			}

		if (CreateProcess(cmdpath, cmdline, &sec, &sec, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
		{
			WaitForSingleObject(pi.hProcess, INFINITE);
			CloseHandle(pi.hThread);
			CloseHandle(pi.hProcess);
			PeekNamedPipe (hOutR, NULL, 0, NULL, &BTAvail, NULL);
				if (BTAvail > 0)
				{
					Result = (char *) GlobalAlloc(GMEM_FIXED, BTAvail + 1);
					ReadFile(hOutR, Result, BTAvail, &Read, NULL);
					Result[BTAvail] = '\0';
					OemToChar(Result, Result);
					return Result;
				}
		}
}
	return NULL;
}

int main(int argc, char **argv)
{
	char *cmd = ExecuteCMD("dir");
	puts(cmd);
}

011011010110000101100011011010000110100101101110
0110010101110011

GeneralRe: Dos command Pin
MsmVc4-Feb-11 1:11
MsmVc4-Feb-11 1:11 
QuestionWould you all call this namespace abuse? Pin
asincero3-Feb-11 14:06
asincero3-Feb-11 14:06 
AnswerRe: Would you all call this namespace abuse? Pin
Madhu Nair3-Feb-11 16:33
Madhu Nair3-Feb-11 16:33 
GeneralRe: Would you all call this namespace abuse? Pin
asincero3-Feb-11 16:45
asincero3-Feb-11 16:45 
GeneralRe: Would you all call this namespace abuse? Pin
Stefan_Lang3-Feb-11 21:55
Stefan_Lang3-Feb-11 21:55 
AnswerRe: Would you all call this namespace abuse? Pin
Alain Rist3-Feb-11 20:31
Alain Rist3-Feb-11 20:31 
QuestionRe: Would you all call this namespace abuse? Pin
bob169724-Feb-11 5:03
bob169724-Feb-11 5:03 
QuestionChange Image size Pin
john56322-Feb-11 20:32
john56322-Feb-11 20:32 
AnswerRe: Change Image size Pin
Madhu Nair2-Feb-11 21:17
Madhu Nair2-Feb-11 21:17 
AnswerRe: Change Image size Pin
S p k 5213-Feb-11 1:00
S p k 5213-Feb-11 1:00 
AnswerRe: Change Image size Pin
Cool_Dev3-Feb-11 2:01
Cool_Dev3-Feb-11 2:01 
QuestionError in Release() throw function Pin
Anu_Bala2-Feb-11 19:30
Anu_Bala2-Feb-11 19:30 
AnswerRe: Error in Release() throw function Pin
Andrew Brock2-Feb-11 19:43
Andrew Brock2-Feb-11 19:43 
GeneralRe: Error in Release() throw function Pin
Anu_Bala2-Feb-11 20:05
Anu_Bala2-Feb-11 20:05 
GeneralRe: Error in Release() throw function Pin
Andrew Brock2-Feb-11 20:35
Andrew Brock2-Feb-11 20:35 
GeneralRe: Error in Release() throw function Pin
Richard MacCutchan2-Feb-11 21:54
mveRichard MacCutchan2-Feb-11 21:54 
QuestionGetting the error Link2001: unresolved reference to the function Pin
charanmanjunath2-Feb-11 18:14
charanmanjunath2-Feb-11 18:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.