|
yep, i'm checking it, but i removed it from there to make the code clear. I have been making a lot of tests and the resoult is:
after I run the CFileDialog all accessors are not working (OpenAll is returning E_FAIL)
(there are about 25 accessors in my code)
disaster
|
|
|
|
|
I've found the information about this problem. The CFileDialog changes the working directory, so if database is opened from the working directory (without a full path) the system will not be able to open it.
Krzys
|
|
|
|
|
Hi
I am writing a C++ program thats requires me to execute another program using the DOS prompt. Hence, whenever I execute the command line, the dos window will pop up at the background. Thus I am wondering if anyone can teach me how to prevent the dos prompt from popping out. Thank you
I am using system(command) to execute the program.
|
|
|
|
|
Danny Chan wrote:
I am using system(command) to execute the program.
system() is a holdover from DOS days. Use CreateProcess() instead!
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Hello,
Use ShellExecute function,
ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);
With Regards,
R.Selvam
|
|
|
|
|
it must be SW_HIDE if he wants to hide the Win32 Console
scio me nihil scire
My OpenSource(zlib/libpng License) Engine:
http://sourceforge.net/projects/rendertech
Its incurable, its a Pentium division failure.
|
|
|
|
|
One solution is CreateProcess() and pass in CREATE_NO_WINDOW.
Kuphryn
|
|
|
|
|
There's a great article on this site that explains how to do this with ShellExecuteEx(). He also talks about CreateProcess as well. I've found in my particular app ShellExecuteEx() did exactly what I wanted. (I just used this in a program yesterday which is how I know the article works great!)
click here for the article
Here's the excerpt for what you are looking for:
Q: How do I start a program, and halt execution of my current program, till that program exits?
A: You start the program using ShellExecuteEx and use WaitForSingleObject on the process handle.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\MyProgram.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
...The only thing that you will have to do is where it says ShExecInfo.nShow = SW_SHOW; ... change the SW_SHOW to SW_HIDE and it'll work perfectly.
|
|
|
|
|
hi
Thank you for the reply.
I had tried the code but it seem like it cannot execute the command line tat i wanted. Because my program required me to launch this external program that require me to key in the command line on to the DOS Prompt.
My inital program
command = "jpegtran -greyscale JPEG.jpg greyscale.jpg";
system(command);
thus if I am using wat u told me, how can i execute the above command line without DOS prompt popping out.
Thank you so much
cheers
Danny Chan
|
|
|
|
|
Hey there. Here's the code snippet that I pasted in my previous post. I made some modifications to it that should suit your needs.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\jpegtran.exe";
ShExecInfo.lpParameters = "-greyscale JPEG.jpg greyscale.jpg"; // --- THIS IS YOUR PARAMS!
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
..............
Have a peek at the line
ShExecInfo.lpParameters = "-greyscale JPEG.jpg greyscale.jpg"; // --- THIS IS YOUR PARAMS!
MSDN says...
lpParameters:
Address of a null-terminated string that contains the application parameters. The parameters must be separated by spaces. If the lpFile member specifies a document file, lpParameters should be NULL.
So, using this code with
ShExecInfo.lpFile = "c:\\jpegtran.exe";
ShExecInfo.lpParameters = "-greyscale JPEG.jpg greyscale.jpg"; // --- THIS IS YOUR PARAMS!
will run the program just like:
command = "jpegtran -greyscale JPEG.jpg greyscale.jpg";
system(command);
(except by using SW_HIDE it won't show the DOS window)
Hope that helps!!
|
|
|
|
|
Hi shultas
Thank you so much for your help. But i still got a small problem to trouble u again. Hope u dont mind. Cause after inserting what you had given to me, I got this error on the <shellexecuteinfo shexecinfo="{0};"> line. This is because the shellexecute is carried out in a few case function and i think this is why it give me these errors. Hence, is it possible for u to guide me for the one last time to solve this problem. Below is the portion of my program tat I insert the codes. Thank you so much for you help. Really appreciated.
switch(*selection)
{
case'1':
//AfxMessageBox(_T("Executing Case 1"));
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\jpegtran.exe";
ShExecInfo.lpParameters = "-greyscale JPEG.jpg greyscale.jpg"; // --- THIS IS YOUR PARAMS!
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
//AfxMessageBox(_T("Opening greyscale images"));
imageFile2.Open( _T("C:\\FYP Test Folder\\best.jpg"), CFile::modeRead|CFile::typeBinary);
imageFile2.Read(image1, size.uintVal);
imageFile2.Close();
//AfxMessageBox(_T("Sending greyscale images"));
send(clientsock, (const char*) image1, size.uintVal, 0);
break;
The error message
error C2360: initialization of 'ShExecInfo' is skipped by 'case' label
cheers
Danny Chan
|
|
|
|
|
Hello Danny
I see your problem is in your case statement. Here's an article that explains pretty good what you are experiencing. Click here for article.
One way you can quickly get rid of this problem is by enclosing each of your case statements in brackets {}. case '1': { ... } case '2': { ... }
Check out that article above and let me know if you need any more help or if you got it to work
Shultas
|
|
|
|
|
Hi Shultas
It works!!! Thank you so much for your help. You are great manz!!!
cheers
Danny Chan
|
|
|
|
|
Hi Shultas
Sorry to bother you again. As the advise you gave to me work perfectly but what if i need to execute 2 different .exe in the dos prompt? What parameters do i need to insert to the shell to do it? Thank you once again. Really sorry to trouble you again.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\djpeg.exe";
ShExecInfo.lpParameters = "JPEG.jpg jpeg.ppm"; // --- THIS IS YOUR PARAMS!
ShExecInfo.lpFile = "c:\\cjpeg.exe";
ShExecInfo.lpParameters = "-smooth 50 jpeg.ppm average.jpg"; // --- This is the second program needed to execute.
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
|
|
|
|
|
Hi Danny.
That's an easy add-on!
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\djpeg.exe";
ShExecInfo.lpParameters = "JPEG.jpg jpeg.ppm"; // --- THIS IS YOUR PARAMS!
// ShExecInfo.lpFile = "c:\\cjpeg.exe";
// ShExecInfo.lpParameters = "-smooth 50 jpeg.ppm average.jpg"; // --- This is the second
// program needed to execute.
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
Lets do one at a time. So, we've got the first program to excute. Right after the WaitForSingleObject() line, put your second EXE in there. Such as this:
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\djpeg.exe";
ShExecInfo.lpParameters = "JPEG.jpg jpeg.ppm"; // --- THIS IS YOUR PARAMS!
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
// When first .EXE is done running, we'll get here. Now, we've already got most of the data
// that we need, lets just make a modification to it real quick.
ShExecInfo.lpFile = "c:\\cjpeg.exe";
ShExecInfo.lpParameters = "-smooth 50 jpeg.ppm average.jpg"; // --- This is the second
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
Bingo. Simple as that. Add those four extra lines in there. Your program will now call djpeg.exe first. Then, once that is done running, it'll call cjpeg.exe to do the rest of the work!!!!
That shall help you out!
Shultas
|
|
|
|
|
Hi Shultas
Thank you once again for you help. You are great man.;)
cheers
Danny Chan
|
|
|
|
|
NP! It's all good!
Cheers!
Shultas
|
|
|
|
|
My server application (database intensive) takes large memory.
1. I wanna confirm whether my application allocated the memory, or is the database driver is taking the memory.
2. in "TaskManager.exe" counters are as follows:
a: Memory Usage: 18,000 K
b: Virtual Memory: 10,000 K
So why is this big difference, which counter reflects the memory allocated by my code (a or b)??
Is the extra memory showed in Memory Usage counter was allocated by database driver and would be deallocated by the same driver in the end..?
|
|
|
|
|
See if this article helps.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
if the memory usage is only 18,000K I would not worry about it my db application takes 20 times that... Most people have at least 256 mb or more memory so this is not very signifigant... On my computer gator (password helper for ie) uses 33,000 K...
John
|
|
|
|
|
Don't you know gator is spyware?
One should not trust a program that does a simple task yet consumes so much memory.
|
|
|
|
|
I know but I have accounts on over 100 internet sites and it is impossible to remember all the usernames and passwords so I put up with gator. I have tryied other programs like robohelp but they suck big time...
John
|
|
|
|
|
John M. Drescher wrote:
remember all the usernames and passwords so I put up with gator
How do you know that Gator doesn't leak? It's a spyware like Trickler and I would never in my wholel ife trust a spyware! I would go for a real password reminder app instead, but that's just me...
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
Hey,
I have a question for the board. I have an application running as a Windows service. It uses printf statements to print data to the screen. However, I can't see it because no Windows command prompt is opened. Can I access another app's stout stream through another application? Thanks.
|
|
|
|
|
Normally a service does not output data to the screen. Have you tried using TextOut() instead? Otherwise, outputting to a log file of some sort is more common practice.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|