|
Check KB article Q190351 "HOWTO: Spawn Console Processes with Redirected Standard Handles".
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
Thanks, I have tried this, and had problems. Have you ever tried to implement code from this article?
|
|
|
|
|
No. What is the problem?
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
Thanks anyway, there are several problems, but it's not worth getting into. I was hoping to find someone that had actually implemented something similar to what I am attempting.
|
|
|
|
|
It just doesnt work Thats why I wrote the CSpawn class.
int x=1, y=5;
x^=y^=x^=y;
<a href="http://www.codeproject.com/useritems/StupidXORTrick.asp" target="_blank">ClickHereForHelp();</a>
|
|
|
|
|
Whats wrong with CSpawn? What does it do under Win98? As far as I know it should work. Maybe I can give you a hint on how to adapt it (well, I wrote it).
int x=1, y=5;
x^=y^=x^=y;
<a href="http://www.codeproject.com/useritems/StupidXORTrick.asp" target="_blank">ClickHereForHelp();</a>
|
|
|
|
|
Thanks,
I think it probably does very well when using it the way you intended.
I am using it as a "read only", and wait until completed type of operation.
I was able to get it going under w98 by ignoring the following failure:
(In Execute(...))
if (!SetStdHandle(STD_OUTPUT_HANDLE, m_hSaveStdout)){
}
For some reason, this fails under W98, but not NT. It does not seem to affect anything, so I am ignoring the failure for now.
Any idea what is happening?
Thanks,
Dave
|
|
|
|
|
You can modify the behavior as you need it when you look at the comment to CSpawn.
About the failure under W98 I have no clue as I have no W98 system available (its almost obsolete anyway). Maybe someone with W98 experience might tell.
int x=1, y=5;
x^=y^=x^=y;
<a href="http://www.codeproject.com/useritems/StupidXORTrick.asp" target="_blank">ClickHereForHelp();</a>
|
|
|
|
|
Thanks for the reply. I was able to make some modifications to make it work the way I needed it. I'm going to try to see why the one failure happens in W98. What you have written is great stuff. I'm sure I would have had no problems if I were using it the way you intended.
|
|
|
|
|
Hows this - note that there may be some missing headers - I've just cut'n'pasted this out of a working application, so it's missing context...
#include <windows.h>
#include <malloc.h>
#include <string>
namespace std {
#ifdef _UNICODE
typedef wstring tstring;
#else
typedef string tstring;
#endif
};
std::tstring RunProcessAndCaptureOutput(LPCTSTR CmdLine, DWORD maxWaitTime = INFINITE)
{
LPTSTR copyOfCmdLine = LPTSTR(alloca(sizeof(TCHAR) * (lstrlen(CmdLine) + 1)));
lstrcpy(copyOfCmdLine, CmdLine);
std::tstring s;
SECURITY_ATTRIBUTES SecAttr;
SecAttr.nLength = sizeof(SecAttr);
SecAttr.lpSecurityDescriptor = NULL;
SecAttr.bInheritHandle = TRUE;
HANDLE hRead, hWrite;
if (::CreatePipe(&hRead, &hWrite, &SecAttr, 0)) {
STARTUPINFO StartupInfo;
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
StartupInfo.dwFlags = STARTF_FORCEOFFFEEDBACK|STARTF_USESTDHANDLES;
StartupInfo.hStdError = hWrite;
StartupInfo.hStdOutput = hWrite;
PROCESS_INFORMATION ProcessInfo;
if (::CreateProcess(NULL, copyOfCmdLine, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &StartupInfo, &ProcessInfo)) {
std::tstring capturedOutput;
const DWORD smallWaitTime = 100;
__int64 ftEnd;
GetSystemTimeAsFileTime(LPFILETIME(&ftEnd));
ftEnd += __int64(maxWaitTime) * __int64(10000);
CloseHandle(hWrite);
while (::WaitForSingleObject(ProcessInfo.hProcess, smallWaitTime) != WAIT_OBJECT_0) {
EmptyPipeAndAppendToString(hRead, capturedOutput);
__int64 ftNow;
GetSystemTimeAsFileTime(LPFILETIME(&ftNow));
if (ftNow > ftEnd) {
s += "Command \"";
s += CmdLine;
s += "\" timed out.";
s += " Partial output received\r\n\r\n";
break;
}
}
EmptyPipeAndAppendToString(hRead, capturedOutput);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
s += capturedOutput;
s += "\r\n\r\n";
}
else {
CloseHandle(hWrite);
s += "Error creating process with command \"";
s += CmdLine;
s += "\"\r\n\r\n";
}
CloseHandle(hRead);
}
else {
s += "Error creating pipe\r\n\r\n";
}
return s;
}
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Thank you very much, I'll give it a try.
|
|
|
|
|
Assume I have a CFont object in my CWnd derived class. And assume I wanna repeatedly change the font of my CWnd derived class. Say I do this :-
CFont *pf = GetFont();
LOGFONT lf;
pf->GetLogFont(&lf);
m_font.Detach();
m_font.DeleteObject();
m_font.CreateFontIndirect(&lf);
SetFont(&m_font);
Am I doing it right? Or is there a leak?
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Get rid of the Detach() call, or DeleteObject() won't actually do anything. Otherwise it looks good to me.
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
There is a leak,
m_Font.Detach() clears the HFONT handle from the m_Font wrapper class object so your not deleting anything when calling m_Font.DeleteObject().
Just remove the m_Font.Detach() line.
Roger Allen
Sonork 100.10016
I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.
|
|
|
|
|
|
I have read my image field from my database and put it in a variant as byte.Now I don't know how to show these bytes in my dialog.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
1) Create device-independent bitmap (DIB) filling all required parameters - see CreateDIBSection
2) Fill DIB bits from your data - see SetBitmapBits
3) Create memory DC and select DIB in it - see CreateCompatibleDC, SelectObject
3) BitBlt or StretchBlt from memory DC to window DC
|
|
|
|
|
Thanks.I have to go through them now.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
I have a CEditView and no matter what I try and can't get it so that there is a horizontal scroll bar. I've tried adding the ES_AUTOHSCROLL and the WS_HSCROLL but that doesn't seem to be doing it. Any help? Thanks.
[EDIT]: I just noticed that when I have the WS_HSCROLL and ES_AUTOHSCROLL styles on, when the window is resized the horizontal scroll bar appears but you can't horizontally scroll beacuse it is "wordwraped."
|
|
|
|
|
code snippet:
AfxSocketInit();
CSocket socket;
socket.Create();
if(!socket.Connect(url,80))
{
int err=socket.GetLastError();
cout << err << endl;
}
Url is someting like: "http://www.somewhere.com/somepage.html".
The CSocket::Connect() always failes. It's strange but the errorcode returned by getlasterror is zero (0), so I can't retrieve any information about the error.
Init and create succeed though.
Somebody got a clue? What am I doing wrong here?
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Connect() doesn't take an URL as parameter, it wants either a hostname (e.g. "www.somewhere.com") or a numeric IP address.
|
|
|
|
|
What was I thinking, uh ;P;P
btw. It's been a while now since my last programming in java, but it's not gone yet
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Hi,
This is probably a simple question for you experienced folk, but being a beginner to Visual Studio (though a C programmer of old), is foxing me.
I have some C (not C++) code that I have inherited and have to develop further that was intended to be compiled into a dll using Visual C++ 6.0.
I have so far only been able to get hold of a licenced copy of Visual Studio .NET (standard) and have tried to build the existing code. It compiles but will not load, even though I think I have specified this as an unmanaged Win32 dll. Using a copy of Visual C++ 6.0, I can build and run successfully, but need to be able to do this with .NET C++
Any hints on what I need to do?
The files consist of:
Three .h source files
Three .h header files
One .def file used for declaring exported functions
Appreciate any help I can get.
|
|
|
|
|
I shall try to assume that the cause is far from DLL problem. Perhaps, it is a new for-scope interpretation of VC7??? Very frequent situation while you update VC6 to VC7. VC6 works with for-scope out of standard, but VC7 has corrected this mistake and at the same time it does not support correctly "old VC6" code
Try to switch
option "C++\Language\Force conformance in For Loop Scope" on and to observe what will happened
Beg pardon in advance if my suggestion is very stupid
|
|
|
|
|
Thanks for the suggestion. Tried it, but no change. The dll still refuses to load. I have noticed that the dll generated through C++ 6.0 is 237Kb in size whilst the version generated through .NET is 184Kb in size. I might have expected that given exactly the same source code, that the output dlls would be roughly if not exactly equivalent in size.
Does .NET C++ support the .def style of declaring exported functions, or is another method now required?
|
|
|
|