00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <cstdio>
00021
00022 #import <MiKTeX206-session.tlb>
00023
00024 using namespace MiKTeXSession2_6;
00025
00026 int
00027 main ( int argc,
00028 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 }