::FindExecutable の動作を確認しようと思い次の様なコードを書いた.
#include <clocale>
#include <iostream>
#include <Windows.h>
#include "i_define.hxx "
#include "tstring.hxx "
tstring Get_doc_exe (LPCTSTR doc)
{
tstring exe_path ;
exe_path.resize(MAX_PATH,0) ;
::FindExecutable(doc,NULL,&exe_path[0]) ;
return exe_path.c_str() ;
}
int _tmain (int argc,TCHAR* argv[])
{
_tsetlocale(LC_ALL,_T("")) ;
{
tstring buf ;
buf.resize(1000) ;
{
while (std::terr << _T("file ? =") , std::tin.getline(&buf[0],buf.size()))
{
tstring str = buf.c_str() ;
if (str == _T("q")) { break ; }
else if (str == _T("Q")) { break ; }
// str = ::QuotM_Del_All(str) ;
if (str.empty()) { continue ; }
// if (::File_IsNothing(str)) { continue ; }
std::tout << ::Get_doc_exe(str.c_str()) << std::endl ;
}
}
}
return 0 ;
}
MBCS でビルドすると問題ないが,UNICODE にすると,
--------------------構成: get_exe - Win32 Release--------------------
コンパイル中...
get_exe.cpp
C:\Documents and Settings\All Users\Documents\Develop\VC_Test\PC_doc\get_exe\get_exe.cpp(37) : error C2664: 'class std::basic_istream<unsigned short,struct std::char_traits<unsigned short> > &__thiscall std::basic_istream<unsigned short,struct std::
char_traits<unsigned short> >::getline(unsigned short *,int)' : 1 番目の引数を 'char *' から 'unsigned short *' に変換できません。 (新しい機能 ; ヘルプを参照)
指示された型は関連がありません; 変換には reinterpret_cast、 C スタイル キャストまたは関数スタイルのキャストが必要です。
C:\Documents and Settings\All Users\Documents\Develop\VC_Test\PC_doc\get_exe\get_exe.cpp(37) : fatal error C1903: 直前のエラーを修復できません; コンパイルを中止します。
cl.exe の実行エラー
get_exe.exe - エラー 2、警告 0
C2664 については ここ .
Windows.h の include を i_define.hxx より後に.
::FindExecutable ではうまくない様な記述もあるが,今回の目的にはこれで良いかなと思う.
https://dobon.net/vb/dotnet/system/findassociatedexe.html
https://itl.mydns.jp/…/get_exe_2020_09.zip
更にちょっと面白い動作があったので…
#include "i_define.hxx"
#include "tstring.hxx"
#include <Windows.h>
#include <clocale>
#include <iostream>
int _tmain (int argc,TCHAR* argv[])
{
_tsetlocale(LC_ALL,_T("")) ;
{
tstring buf ;
buf.resize(1000) ;
{
while (std::terr << _T("file ? =") , std::tin.getline(&buf[0],buf.size()))
{
tstring str = buf.c_str() ;
if (str == _T("q")) { break ; }
else if (str == _T("Q")) { break ; }
if (str.empty()) { continue ; }
::ShellExecute(NULL,NULL,str.c_str(),NULL,NULL,SW_SHOWNORMAL) ;
}
}
}
return 0 ;
}
関連付けされているドキュメントは,::ShellExecute で普通に開く.
そうでないドキュメントは,エクスプローラでクリックしたのと同じような動作.
NotePad や MSPaint などと入力すると,幾つかの exe は起動できる.
起動できないものもあり,その違いは不明.
https://itl.mydns.jp/…/se_doc_2020_09.zip