==============================ModuleC===================================== | | | The program examples' source codes have been arranged in the same | | order that appeared in the Tutorial. This is unedited and unverified | | compilation. Published as is basis for educational, reacretional and | | brain teaser purposes. All trademarks, copyrights and IPs, wherever | | exist, are the sole property of their respective owner and/or | | holder. Any damage or loss by using the materials presented in this | | tutorial is USER responsibility. Part or full distribution, | | reproduction and modification is granted to any body. | | Copyright 2003-2005 © Tenouk, Inc. All rights reserved. | | Distributed through http://www.tenouk.com | | | | | =========================================================================== Compiled using VC++/VC++ .Net.....unmanaged... #include #include int main() { //handle for file HANDLE hFile; //file and path char fname[30] = "c:\\testfile.txt"; DWORD lpdwFlags[100]; hFile = CreateFile(fname, // file to be opened GENERIC_WRITE, // open for writing FILE_SHARE_WRITE, // share for writing NULL, // default security CREATE_ALWAYS, // create new file only FILE_ATTRIBUTE_NORMAL |FILE_ATTRIBUTE_ARCHIVE | SECURITY_IMPERSONATION, // normal file archive and impersonate client NULL); // no attr. template if(hFile == INVALID_HANDLE_VALUE) printf("Could not open %s file, error %d\n", fname, GetLastError()); printf("File's HANDLE is OK!\n"); BOOL test = GetHandleInformation(hFile, lpdwFlags); printf("The return value is %d, error %d\n", test, GetLastError()); CloseHandle(hFile); DeleteFile(fname); return 0; } --------------------------------------------------------------------------------------------------- #include #include #define BUFSIZE 2048 int main() { char chrBuf[BUFSIZE]; DWORD dwRead, dwWritten; HANDLE hStdin, hStdout; BOOL fSuccess; //Standard output handle hStdout = GetStdHandle(STD_OUTPUT_HANDLE); //Standard input handle hStdin = GetStdHandle(STD_INPUT_HANDLE); //If something wrong with handle for standard input or output if((hStdout == INVALID_HANDLE_VALUE) || (hStdin == INVALID_HANDLE_VALUE)) //Just exit exit(1); printf("Waiting data from standard input:\n"); printf("--EOF to end--\n"); //To stop, press end of file characters for(;;) { //Read from standard input, keyboard. fSuccess = ReadFile(hStdin, chrBuf, BUFSIZE, &dwRead, NULL); if(!fSuccess || dwRead == 0) break; printf("Data to the standard output:\n"); //Write to standard output, console. fSuccess = WriteFile(hStdout, chrBuf, dwRead, &dwWritten, NULL); if(!fSuccess) break; } return 0; } --------------------------------------------------------------------------------------------------- #include #include char szlongpath[100] = "C:\\Documents and Settings\\All Users"; char szshortpath[100]; char buffer = 100; int main() { DWORD test = GetShortPathName( szlongpath, szshortpath, buffer ); printf("The long path name = %s, the error is %d\n", szlongpath, GetLastError()); printf("The short path name = %s, the error is %d\n", szshortpath, GetLastError()); printf("The length in TCHARs = %d, the error is %d\n", test, GetLastError()); return 0; } --------------------------------------------------------------------------------------------------- #include #include int main() { char lpFileName[20] = "module20.txt"; char lpBuffer[50]; LPSTR *lpFilePart = NULL; DWORD test = GetFullPathName( lpFileName, 100, lpBuffer, lpFilePart ); printf("The %s\'s path is %s.\n", lpFileName, lpBuffer); return 0; } --------------------------------------------------------------------------------------------------- #include #include int main() { //handle for file HANDLE hFile; //file and path char fname[30] = "c:\\testfile.txt"; hFile = CreateFile(fname, //file to be opened GENERIC_WRITE, //open for writing FILE_SHARE_WRITE, //share for writing NULL, //default security CREATE_ALWAYS, //create new file only FILE_ATTRIBUTE_NORMAL |FILE_ATTRIBUTE_ARCHIVE | SECURITY_IMPERSONATION, //normal file archive and impersonate client NULL); //no attribute template if(hFile == INVALID_HANDLE_VALUE) printf("Could not open %s file, error %d\n", fname, GetLastError()); else { printf("File's HANDLE is OK!\n"); printf("%s opened successfully!\n", fname); } if(CloseHandle(hFile) != 0) printf("CloseHandle() succeeded!\n"); if(DeleteFile(fname) != 0) printf("%s file successfully deleted!\n", fname); return 0; } ==========================================================================================================