patricksd
asked on
Simple eVC Embedded Visual C++ code needed to assist beginner.
I am a beginner and need the eVC code and supporting includes to perform the following tasks:
1) delete a specified file on the device.
2) check if a specified file exists on the device.
3) read a data value from a specified key in the registry.
4) write a data value to a specified key in the registry.
5) execute an external specified program which is a .cab file (installer).
6) exit the program when all tasks are completed. (I notice that even when I exit a simple "Hello World!" program, it is still running on the device. Why doesn't it shut itself down?)
I know many of these tasks can be performed with just a few lines of code, however, I am having trouble getting my code to compile/run and need an experts help. Thanks very much in advance.
1) delete a specified file on the device.
2) check if a specified file exists on the device.
3) read a data value from a specified key in the registry.
4) write a data value to a specified key in the registry.
5) execute an external specified program which is a .cab file (installer).
6) exit the program when all tasks are completed. (I notice that even when I exit a simple "Hello World!" program, it is still running on the device. Why doesn't it shut itself down?)
I know many of these tasks can be performed with just a few lines of code, however, I am having trouble getting my code to compile/run and need an experts help. Thanks very much in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
How do you shut down your program? The following code should do it.
::AfxGetMainWnd()->PostMes sage(WM_CL OSE);
::AfxGetMainWnd()->PostMes
There is a function DeleteFile
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/html/_wcesdk_Win32_DeleteFile.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/html/_wcesdk_Win32_DeleteFile.asp
Here is a whole api reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/html/_wcesdk_Win32_DeleteFile.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/html/_wcesdk_Win32_DeleteFile.asp
ASKER
Thanks for the quick response and pointing me in the right direction. Regarding checking if a file exists, could I just check the return value of CreateFile() to determine this?
void OpenFileExample (void)
{
HANDLE hFile;
hFile = CreateFile (TEXT("\\MYFILE.TXT"), // Open MYFILE.TXT
GENERIC_READ, // Open for reading
FILE_SHARE_READ, // Share for reading
NULL, // No security
OPEN_EXISTING, // Existing file only ////// Right here and if doesnt exist youll get the error so yeah you can use it
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hFile == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
return;
}
} // End of OpenFileExample code
{
HANDLE hFile;
hFile = CreateFile (TEXT("\\MYFILE.TXT"), // Open MYFILE.TXT
GENERIC_READ, // Open for reading
FILE_SHARE_READ, // Share for reading
NULL, // No security
OPEN_EXISTING, // Existing file only ////// Right here and if doesnt exist youll get the error so yeah you can use it
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hFile == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
return;
}
} // End of OpenFileExample code
http://www.wince.org.uk/vc/intermediate/object_store.htm