|
There are many ways to do this. This is pretty efficient except when the files get very large.
-------------------------------------
// Copy.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <tchar.h>
#include <algorithm>
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
#include <string>
#include <sstream>
#ifdef _UNICODE
typedef std::wstring tstring;
typedef std::wostringstream tostringstream;
#else
typedef std::string tstring;
typedef std::ostringstream tostringstream;
#endif // _UNICODE
void WriteData(LPCTSTR pFile, unsigned int n, const char *pBegin, const char *pEnd)
{
// Generate numbered filename.
LPCTSTR pExt = PathFindExtension(pFile);
tstring FileName(pFile, pExt);
tostringstream ss(FileName);
ss.seekp(0, std::ios::end);
ss << n;
ss << pExt;
FileName = ss.str();
// Create the output file.
HANDLE hOut = CreateFile(
FileName.c_str(), // lpFileName,
GENERIC_WRITE, // dwDesiredAccess
0, // dwShareMode,
NULL, // lpSecurityAttributes
CREATE_ALWAYS, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL, // dwFlagsAndAttributes
NULL // hTemplateFile
);
if ( hOut!=INVALID_HANDLE_VALUE )
{
DWORD dwWritten;
WriteFile(hOut, pBegin, pEnd-pBegin, &dwWritten, 0);
CloseHandle(hOut);
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Open the file.
HANDLE hFile = CreateFile(
_T("C:\\a.txt"), // lpFileName,
FILE_READ_DATA, // dwDesiredAccess
FILE_SHARE_READ, // dwShareMode,
NULL, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL, // dwFlagsAndAttributes
NULL // hTemplateFile
);
if ( hFile==INVALID_HANDLE_VALUE )
{
return 1;
}
DWORD dwFileSize = GetFileSize(hFile, NULL);
// Create the file mapping.
HANDLE hMapping = CreateFileMapping(
hFile, // hFile
NULL, // lpAttributes
PAGE_READONLY, // flProtect
0, // dwMaximumSizeHigh
0, // dwMaximumSizeLow
NULL // lpName
);
if ( hMapping==NULL )
{
// Close the file.
CloseHandle(hFile);
return 1;
}
LPVOID pData = MapViewOfFile(
hMapping, // hFileMappingObject
FILE_MAP_READ, // dwDesiredAccess
0, // dwFileOffsetHigh
0, // dwFileOffsetLow
0 // dwNumberOfBytesToMap
);
if ( pData==NULL )
{
// Close the file mapping.
CloseHandle(hMapping);
// Close the file.
CloseHandle(hFile);
return 1;
}
// Now search for the data we want...
// The file data we've loaded.
const char *pStart = reinterpret_cast<const char *>(pData);
const char *pEnd = pStart + dwFileSize;
// The data we're looking for.
const char DataToFind[] = "|Hello|";
const char *pSearchStart = DataToFind;
const char *pSearchEnd = pSearchStart+sizeof(DataToFind)-1; // -1 to strip off the NULL terminator.
// Search.
unsigned int num = 1;
const char *pMatch = std::search(pStart, pEnd, pSearchStart, pSearchEnd);
if ( pMatch!=pEnd )
{
const char *pMatch2;
do
{
pMatch2 = std::search(pMatch+sizeof(DataToFind)-1, pEnd, pSearchStart, pSearchEnd);
WriteData(_T("C:\\out.txt"), num++, pMatch, pMatch2);
pMatch = pMatch2;
}
while (pMatch2!=pEnd);
}
// Unmap the file.
UnmapViewOfFile(pData);
// Close the file mapping.
CloseHandle(hMapping);
// Close the file.
CloseHandle(hFile);
return 0;
}
Steve
-- modified at 5:12 Friday 24th March, 2006
|
|
|
|
|
Thanks! This helps me out a lot.
|
|
|
|
|
Sir
Can anyone help me in knowing better about
AFX_GETMODULE_STATE macro and why is needed.
Always Be What you Are.
|
|
|
|
|
AfxGetModuleState returns a pointer to thread-local storage for a struct called AFX_MODULE_STATE that stores information about the current running module, including a pointer to the application object.
Vision is Always important and so is your ATTITUDE.
Wishes.
Anshuman Dandekar
|
|
|
|
|
Hi, I have this error message when compling the project:
Creating library ..\giscbir\Debug/geocbir.lib and object ..\giscbir\Debug/geocbir.exp
geocbir.obj : error LNK2001: unresolved external symbol "unsigned long __cdecl CBIRTextTamura(struct tagCBIRIMAGE *,struct tagCBIRTEXTUREDATA *,unsigned long,unsigned long)" (?CBIRTextTamura@@YAKPAUtagCBIRIMAGE@@PAUtagCBIRTEXTUREDATA@@KK@Z)
..\giscbir\Debug/geocbir.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Anyone got an idea what is the reason? Thanks in advance!
|
|
|
|
|
The reason is that a declaration of the function "unsigned long __cdecl CBIRTextTamura " is present but there is no definition. ie.
unsigned long __cdecl CBIRTextTamura(struct tagCBIRIMAGE *,struct tagCBIRTEXTUREDATA *,unsigned long,unsigned long);
unsigned long __cdecl CBIRTextTamura(struct tagCBIRIMAGE *,struct tagCBIRTEXTUREDATA *,unsigned long,unsigned long)
{
return 0;
}
The most likely cause is that you forgot to add the .CPP file that contains the defintion to your project.
Steve
|
|
|
|
|
It has definition in the header file and implemention in cpp file.
|
|
|
|
|
zms413 wrote: It has definition in the header file and implemention in cpp file.
This should read:
"It has declaration in the header file and definition in cpp file."
I think the reason is probably that the .CPP file isn't added to the project. In file view add the file and try again.
Steve
|
|
|
|
|
Another possibility is a spelling mistake. Make sure definition is spelled exactly the same as the definition, and remember that some compilers are case sensitive.
|
|
|
|
|
All C/C++ compilers I know of are case sensitive.
Steve
|
|
|
|
|
I have problem on converting UINT8 data type variable to char.
For example,
for the
UNIT8 byte_data_var[6];
char char_data_var[6];
for (int i = 0; i< 6;i++)
byte_data_var[i];--->how to convert to char[i];
Anyone please help me? Thanks la =)
|
|
|
|
|
a UINT8 is basically an unsigned integer, which can take on numbers from 0 to 255. A char is generally a signed integer, which can take on numbers from -128 to 127. As you can see, these types are not compatible in theory, as they're ranges differ quite a lot. What exactly is it that you are trying to accomplish? Printing the data?
--
Pictures[^] from my Japan trip.
|
|
|
|
|
actually i wish to take out the UINT8 variable and then convert it to string or characters so that I could print out the value to display....
|
|
|
|
|
char buf[4];
_snprintf(buf, 3, "%u", unsigned(byte_variable));
printf("buf is %s\n", buf);
|
|
|
|
|
Thank you very much. I will try on it first =)
|
|
|
|
|
Hi, I'm trying to change the font of a popup menu, and I am wondering if that is possible, and how so....I tried to see if there was a SetFont function like there is for Dialog items "GetDlgItem(xxx)->SetFont(&m_Font)" but couldn't find one. Any help would be greatly apperciated.
Thanks
|
|
|
|
|
Another thing to achieve the same effect is that you can use a bitmap image on the menu and set it to any size that you want and any format.
Vision is Always important and so is your ATTITUDE.
Wishes.
Anshuman Dandekar
|
|
|
|
|
Hi,
cout << "*"<< endl;
and
cout << '* '<
|
|
|
|
|
Well one's outputting a string and the other is outputting a character.
so you could do this:
<br />
std::cout<<"This string"<<std::endl;
but this will surely give you problems:
<br />
std::cout<<'this is invalid'<<std::endl;
I Dream of Absolute Zero
|
|
|
|
|
The first one outputs a asterix because the double quotes denotes a char array, the second one is a little trickier because you are using a single quote to wrap two bytes. That means that the operator << is outputting a short (two bytes) instead of a char (one byte).
Try this
cout << "asdf" << endl;
cout << 'asdf' << endl; and you get the same type of result.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
-- modified at 17:48 Thursday 23rd March, 2006
|
|
|
|
|
Is 'asdf' valid? I thought single quotes only applied to single characters?
|
|
|
|
|
Hi y'all,
I hav created a database MyBBN in SQL server (inbuilt in VC++ 7 using server explorer) with a dataset say BBN and i want to use a column (username) within a table in this dataset as a verifier on a log-on form.
How can i connect to the database or the dataset for that matter?
and how do i check the inputed username from a user against the one in the table.? if sample coding could be provided, it would help a lot. As i mentioned earlier its a managed App in Windows Forms.Net
Thanks for all help in advance...
regards
|
|
|
|
|
Sir
Can anyone help me
How to Capture Atl+Tab combinational Key for my SDI Application?
Thank :-Du
Always Be What you Are.
|
|
|
|
|
GetKeyboardState(...)
A nice hyper tool for optimizing your Microsoft html-help contents.
A best image tool for Windows C++ programmers, don't miss it!.
Includeh10
|
|
|
|
|
WM_SYSKEYDOWN
Nibu thomas
Software Developer
|
|
|
|