Solved

Direct File manipulation

Posted on 2002-04-05
5
147 Views
Last Modified: 2010-04-02
Hello,
   I need to search directly for different records within a file in its actual location...as basically as possible.  Does anyone have any suggestions for me?
Thanks
0
Comment
Question by:pingle
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
See http://support.microsoft.com/support/kb/articles/Q292/4/85.ASP ('HOWTO: Programmatically Save an HTML Page to Disk'). The scoop is:

Accomplishing this task from a Visual C++ host is very straightforward. You can use an IWebBrowser2
interface to call the QueryInterface method for the IHTMLDocument2 interface. After you obtain a pointer
to the document, then call QueryInterface for the IPersistFile interface. After you obtain this interface
pointer, you can call the save method to save the file to disk.

   HRESULT          hr    = E_FAIL;
   IDispatch*       pDisp = NULL;
   IHTMLDocument2*  pDoc  = NULL;
   
   pDisp                  = m_webOC.GetDocument();

  if(SUCCEEDED(hr = pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc)))
  {
      IPersistFile*     pFile     =     NULL;
      if(SUCCEEDED(pDoc->QueryInterface(IID_IPersistFile,(void**)&pFile)))
      {
    LPCOLESTR     file = L"c:\\test1.htm";
    pFile->Save(file,TRUE);
      }
  }
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Ooops, sorry, wrong browser window :o)
0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
Comment Utility
Well, the easiest way for navigating a file is using 'fseek()':


#include <stdio.h>

void main( void )
{
   FILE *stream;
   char line[81];
   int  result;

   stream = fopen( "fseek.out", "w+" );
   if( stream == NULL )
      printf( "The file fseek.out was not opened\n" );
   else
   {
      fprintf( stream, "The fseek begins here: "
                       "This is the file 'fseek.out'.\n" );
      result = fseek( stream, 23L, SEEK_SET);
      if( result )
         perror( "Fseek failed" );
      else
      {
         printf( "File pointer is set to middle of first line.\n" );
         fgets( line, 80, stream );
         printf( "%s", line );

      }
      fclose( stream );
   }
}

0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
If you're running on a Windows platform, you can do a MapView, and get a (void*) pointer to the data in the file.
You can then use regular C++ functions to manipulation the data in the file.
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
FYI:
You can also do MapView from unix using mmap and munmap functions.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now