Tuesday, March 3, 2009

[VC++] Finding executable filename for a document

You can find a document's executable file name and path using FindExecutable() API. For example if you want to know the executable file path of a *.doc file it will return winword.exe installed path. Below code demonstrate how to use this.
TCHAR wcsExecutablePath[MAX_PATH];
// Find Executable path of the document
if( 32 < (int)FindExecutable( _T( "C:\\Test.doc" ),// Document Name
NULL, // Current working directory
wcsExecutablePath )) // Executable path returned
{
// Show the executable path obtained
AfxMessageBox( wcsExecutablePath );
}

No comments: