ホーム » VC » FindExecutable と C2664

2020年9月
 12345
6789101112
13141516171819
20212223242526
27282930  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,354 アクセス



FindExecutable と C2664

::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
::FindExecutable を使用した動作テスト
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

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

2件のコメント

  1. iwaoさん!
    いつも、私にはレベル高すぎ~ブログですが、チャレンジ精神にいみふめいながら面白く債権してますよ~😄!
    チャレンジャー人好きだなぁ~!(笑)

    • いつもありがとうございます.
      ここに書いている情報のほとんどは,私が後で同じ様な状況になった時のメモとして残しています.
      他の人にはあまり役に立たなくて申し訳なく思っております.
      PC の使い方などで困ったことがあれば,お問合せください.
      わかる範囲であれば,ブログのネタとして書いてみます.

Iwao へ返信する コメントをキャンセル

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。