|
It should be 'using std::vector', without 'namespace'
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
Tomasz Sowinski wrote:
It should be 'using std::vector', without 'namespace'
Yep. I know... Just made a silly mistake.
Regards,
Brian Dela
|
|
|
|
|
Does the path string returned by CFileDialog look like C:\dir\abc.txt or C:\\dir\\abc.txt . THrowing a messagebox with this pathstring displays it as the former but that doesnt necessarily mean its the way its returned. I plan to be using splitpath on the returned string and so need to know.
Thnaks,
ns
|
|
|
|
|
|
I wanted commas to replace the backslashes, so I tried
CString m_szlstfile = fileDlg.GetPathName();
m_szlstfile.Replace('\\', ',');
AfxMessageBox(m_szlstfile);
which worked, whereas if I did
Replace('\', ',');<br /> it complained that there was a newline in the sequence. So apparentlt there is a \\ somewhere in the process ??
ns
|
|
|
|
|
|
no, there is no \\ the sequence. the first \ escapes the second ' , changing it from a special C/C++ metacharacter to a literal string character. so, your statement ends up meaning roughly the same as this:
Replace('x, ',');
and that can't be parsed
bottom line: if you want a \ in a string, you have to use \\.
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
I'm TRYING to catch database exception and output that to an error file. Here's the CATCH code :
catch (CdbException)
{
FILE* errorfile;
errorfile=fopen("c:\\cristi\\error.err","a");
fprintf(errorfile,"v,dmlkvmdsv");
for (long ct = 0; ct < dben.Errors.GetCount(); ct++)
{
fprintf(errorfile,_T("\t Error #%ld: #%ld -- %s\n"),
ct,
DBERR(dben.Errors[ct].GetNumber()),
dben.Errors[ct].GetDescription());
}
fclose(errorfile);
return;
}
This code just won't work. I get nothing in the file. Nothing. It's not even accessed.
This other code below that prints the error data to the screen works.
catch (CdbException)
{
for (long ct = 0; ct < dben.Errors.GetCount(); ct++)
{
printf(_T("\t Error #%ld: #%ld -- %s\n"),
ct,
DBERR(dben.Errors[ct].GetNumber()),
dben.Errors[ct].GetDescription());
}
return;
}
Now. ---> In both cases I get this error message:
Debug Assertion Failed!
Program: ...program
File:dbgheap.c
Line:1044
Expression: _CrtIsValidHeapPointer(pUserData)
I belive the second code works because of the printf lack of buffering so that the error message that I display at the console displays faster than the debug assertion failed error. Anyway, this isn't the problem. The problem is why do I get that error message. What happend over there. Anyone encountered this problem before ?
Thank you!
|
|
|
|
|
Are you sure dben.Errors[ct].GetDescription() is returning a char* and not some other kind of string like CString or wchar_t* ? That's the only thing I can see by just looking at your code.
|
|
|
|
|
I have been trying to execute a console application (32 bit), and get it's output from a Win32 (MFC) application. I have tried the CSpawn article on www.codeproject.com, but it does not work fur Windows98, and does not wait until the program exits they way I need it to.
I have also tried the MSDN articles. They mention that 16-bit console apps need an extra CreateProcess, but I don't think I need that since the console app is a 32-bit app? I do not ever create console apps, so am I wrong about this? Are all console apps considered 16-bit?
I'd rather not re-invent something if someone has already solved this one.
Any ideas on where to look?
Thanks,
Dave
|
|
|
|
|
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.
|
|
|
|
|