Click here to Skip to main content
15,921,989 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC App needs to call routine from a DLL made using JNI -- Urgent Pin
Nibu babu thomas24-Mar-06 1:15
Nibu babu thomas24-Mar-06 1:15 
GeneralRe: MFC App needs to call routine from a DLL made using JNI -- Urgent Pin
a1prashant@yahoo.com24-Mar-06 1:23
a1prashant@yahoo.com24-Mar-06 1:23 
GeneralRe: MFC App needs to call routine from a DLL made using JNI -- Urgent Pin
Nibu babu thomas24-Mar-06 1:29
Nibu babu thomas24-Mar-06 1:29 
GeneralRe: MFC App needs to call routine from a DLL made using JNI -- Urgent Pin
a1prashant@yahoo.com26-Mar-06 16:40
a1prashant@yahoo.com26-Mar-06 16:40 
GeneralRe: MFC App needs to call routine from a DLL made using JNI -- Urgent Pin
Nibu babu thomas26-Mar-06 17:04
Nibu babu thomas26-Mar-06 17:04 
QuestionWhat happens if an ActiveX control's property page is clicked? Pin
Sstar23-Mar-06 15:16
Sstar23-Mar-06 15:16 
QuestionSearching binary file Pin
delta3223-Mar-06 14:50
delta3223-Mar-06 14:50 
AnswerRe: Searching binary file Pin
Stephen Hewitt23-Mar-06 15:46
Stephen Hewitt23-Mar-06 15:46 
The easiest way would be the load the whole file into memory, do the search, and then copy the bit you want into the new file (unless the file is so big and that this isn't feasable).
------------------

// Copy.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include <tchar.h>
#include <algorithm>

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.
const char *pMatch = std::search(pStart, pEnd, pSearchStart, pSearchEnd);
if ( pMatch!=pEnd )
{
pMatch += sizeof(DataToFind)-1;
const char *pMatch2 = std::search(pMatch, pEnd, pSearchStart, pSearchEnd);
if ( pMatch2!=pEnd )
{
// Copy out [pMatch, pMatch2).

// Create the output file.
HANDLE hOut = CreateFile(
_T("C:\\out.txt"), // 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, pMatch, pMatch2-pMatch, &dwWritten, 0);
CloseHandle(hOut);
}
}
}

// Unmap the file.
UnmapViewOfFile(pData);

// Close the file mapping.
CloseHandle(hMapping);

// Close the file.
CloseHandle(hFile);

return 0;
}


Steve
GeneralRe: Searching binary file Pin
PJ Arends23-Mar-06 16:20
professionalPJ Arends23-Mar-06 16:20 
GeneralRe: Searching binary file Pin
Stephen Hewitt23-Mar-06 16:28
Stephen Hewitt23-Mar-06 16:28 
GeneralRe: Searching binary file Pin
delta3223-Mar-06 17:50
delta3223-Mar-06 17:50 
GeneralRe: Searching binary file Pin
Stephen Hewitt23-Mar-06 18:30
Stephen Hewitt23-Mar-06 18:30 
GeneralRe: Searching binary file Pin
delta3223-Mar-06 18:54
delta3223-Mar-06 18:54 
QuestionFor What reason AFX_GETMODULE_STATE macro is used? Pin
charpointer23-Mar-06 14:38
charpointer23-Mar-06 14:38 
AnswerRe: For What reason AFX_GETMODULE_STATE macro is used? Pin
_AnsHUMAN_ 23-Mar-06 16:37
_AnsHUMAN_ 23-Mar-06 16:37 
Questionunsolved external symbol Pin
zms41323-Mar-06 13:46
zms41323-Mar-06 13:46 
AnswerRe: unsolved external symbol Pin
Stephen Hewitt23-Mar-06 15:01
Stephen Hewitt23-Mar-06 15:01 
GeneralRe: unsolved external symbol Pin
zms41323-Mar-06 15:31
zms41323-Mar-06 15:31 
GeneralRe: unsolved external symbol Pin
Stephen Hewitt23-Mar-06 15:52
Stephen Hewitt23-Mar-06 15:52 
GeneralRe: unsolved external symbol Pin
Waldermort23-Mar-06 23:03
Waldermort23-Mar-06 23:03 
GeneralRe: unsolved external symbol Pin
Stephen Hewitt23-Mar-06 23:07
Stephen Hewitt23-Mar-06 23:07 
QuestionUrgent! How to convert a UINT8 data type variable to char? Pin
Ting Li Che23-Mar-06 12:34
Ting Li Che23-Mar-06 12:34 
AnswerRe: Urgent! How to convert a UINT8 data type variable to char? Pin
Jörgen Sigvardsson23-Mar-06 12:39
Jörgen Sigvardsson23-Mar-06 12:39 
GeneralRe: Urgent! How to convert a UINT8 data type variable to char? Pin
Ting Li Che24-Mar-06 2:58
Ting Li Che24-Mar-06 2:58 
GeneralRe: Urgent! How to convert a UINT8 data type variable to char? Pin
Jörgen Sigvardsson24-Mar-06 4:19
Jörgen Sigvardsson24-Mar-06 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.