findfile.cpp

Find a file (C++). Uses the FindFile() method to locate a file.

00001 /* findfile.cpp: find a file                                    -*- C++ -*-
00002 
00003    Copyright (C) 2006-2007 Christian Schenk
00004 
00005    This file is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published
00007    by the Free Software Foundation; either version 2, or (at your
00008    option) any later version.
00009    
00010    This file is distributed in the hope that it will be useful, but
00011    WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    General Public License for more details.
00014    
00015    You should have received a copy of the GNU General Public License
00016    along with this file; if not, write to the Free Software
00017    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00018    USA.  */
00019 
00020 #include <cstdio>
00021 
00022 #import <MiKTeX206-session.tlb>
00023 
00024 using namespace MiKTeXSession2_6;
00025 
00026 int
00027 main (/*[in]*/ int              argc,
00028       /*[in]*/ const char **    argv)
00029 {
00030   if (argc != 2)
00031     {
00032       puts ("Usage: findfile FILENAME");
00033       puts (" e.g.: findfile sample2e.tex");
00034       return (1);
00035     }
00036 
00037   if (FAILED(CoInitialize(0)))
00038   {
00039     puts ("COM library could not be initialized.");
00040     return (1);
00041   }
00042 
00043   int retCode = 0;
00044 
00045   try
00046     {
00047       ISession2Ptr pSession2;
00048       HRESULT hr = pSession2.CreateInstance(L"MiKTeX.Session");
00049       if (FAILED(hr))
00050       {
00051         _com_raise_error (hr);
00052       }
00053       _bstr_t fileName (argv[1]);
00054       _bstr_t path;
00055       if (pSession2->FindFile(fileName, path.GetAddress()))
00056       {
00057         puts (path);
00058       }
00059     }
00060   catch (const _com_error & e)
00061     {
00062       puts (e.Description());
00063       retCode = 1;
00064     }
00065 
00066   CoUninitialize ();
00067 
00068   return (retCode);
00069 }

Generated on Tue May 29 21:24:53 2007 for MiKTeX by  doxygen 1.5.1-p1