|
Thanks for your answer and WARNING!!!
Jahangir Raza Shah
Pakistan.
VC, Directx Programmer. (Intermediate Level).
|
|
|
|
|
I want to create a logger program which should keep track of how many times the host computer was started and also the Date & time of each startup & shutdown.
Please tell me about any win 32 api or MFC solution to achieve my goal.
Jahangir Raza Shah
Pakistan.
VC, Directx Programmer. (Intermediate Level).
|
|
|
|
|
Hi all. I thought yesterday of creating a very simple encryption program using a basic if/else statement. This is the basic idea for it.
#include <iostream.h>
int main()
{
int const pword = (whatever your password is);
float password
cout << "To open program, enter the password: << endl;
cin >> password;
if (password = (password))
{
// this is where i have a problem, how do you open a file from a program?
}
else
{
cout << "Access Denied" << endl;
}
return 0;
}
Please help or comment on this or my idea in any way. Is this even a good idea? A workable idea? Thanks in advance.
|
|
|
|
|
if you want an external program to open with the file (like notepad, for instance...) use the you could system() command.
like:
if(password == paswd)
{
system("notepad file.txt");
}
that comes from the command prompt commands. you can actually type "notepad file.txt" in a command prompt, and it will execute notepad, with the file.
There's other ways using various window commands to open applications, but thats a pretty simple way.
*.*
cin >> knowledge;
|
|
|
|
|
There are several options. Here are a few:
- standard C++ lib: <fstream>
- MFC: CFile, CstdioFile
- Win32 API: CreateFile()
“…is this even a good idea…”
No. There are so many reasons but the most obvious is nothing is encrypted. It appears your intent was to “password protect” a file but it only works if the file is opened with your app. What’s to stop someone from opening the file with notepad.exe for example. You have hard-coded the password into the code. Bad idea. With little effort, someone could just open your compiled exe with a hex editor and nab the password. The list goes on (and its long). Encryption is a very complex subject. If you are seriously interested consider picking up a copy of Bruce Shneier’s Applied Cryptography.
you wrote:
“ if(password = (password)) “
what you meant was:
if(password == pword)…
I have seen some of your other posts on this forum and I am not sure what compelled me to answer this one. I would suggest searching www.msdn.microsoft.com and google for your questions and if they still remain unanswered, post them as a question. “How to open a file” can be answered in less than 1 minute by searching the above sites
|
|
|
|
|
Thanks for the answers, sorry if they seem easy or whatnot. I am very new at programming.
|
|
|
|
|
HackerBoy wrote:
if (password = (password))
This is an error and is common for beginners. Get into the habit now of putting constants on the left of the equality operator and the compiler will be quick to tell you when you've mistakingly used the assignment operator instead. Otherwise, while what you have is syntactically correct, it does not produce the desired result.
HackerBoy wrote:
...how do you open a file from a program?
I'm not quite sure what you mean by this. There are many ways to open files. Among them are CreateFile() , fopen() , and CFile::Open() .
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Which tool to use for detecting heap fragmentation. Does any come free with visual studio or windows2000.
As any other free downloadable
|
|
|
|
|
Ofcourse microsoft provides one such tool called heap walker(heapwalk.exe).
It can be freely downloaded from here
But one draw back is that it does not tell exactly which application is holding the memory.
greatest thing is to do wot others think you cant suhredayan@omniquad.com
|
|
|
|
|
Not really an answer to your question, but I question from myself, knowing you are using Fortran as well:
Although we don't write Fortran anymore, some of our applications still have Fortran.
When we started to use Visual Studio .Net/2003 we noticed that our mixed C++/Fortran applications crashed at startup with a run-time error (even before the main was reached).
Our Fortran is compiled with Fortran PowerStation (we can't use Visual Fortran because it does not support all constructions we use in our Fortran).
Which Fortran compiler are you using? Which C++ compiler?
Did you also encounter such strange problems in mixed language applications? And how did you solve it?
Thanks.
Enjoy life, this is not a rehearsal !!!
|
|
|
|
|
Hi,
the problem is a very strange.That's the code:
static char pszFilter[]="Text Files (*.txt)|*.txt|All Files (*.*)|*.*||";
fileDlg CFileDialog(false, "txt", "*.txt", OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST, pszFilter, this, 0);
fileDlg.DoModal();
if(m_table.OpenAll()==S_OK) /*m_table - OLE DB ACCESSOR*/
m_table.CloseAll();
if I close the CFileDialog by the OK button, the table will receive E_FAIL, but
if I close the CFileDialog by the Cancel button, the table will be opened properly.
Does anybody have idea what the problem is?
|
|
|
|
|
shouldn't you check the return value of DoModal() before opening m_table?
|
|
|
|
|
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
|
|
|
|