ホーム » VC

VC」カテゴリーアーカイブ

2024年7月
 123456
78910111213
14151617181920
21222324252627
28293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 88,807 アクセス


warning C4786

VC 6 でビルドしているとよく出力される C4786

--------------------Configuration: T_prm_c - Win32 Debug--------------------
Compiling...
T_prm_c.cpp
c:\program files (x86)\microsoft visual studio\vc98\include\utility(21) : warning C4786: 'std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char> > con
st *>::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *>' : identifier was truncated to '255' characters in the debug information
Linking...
T_prm_c.exe - 0 error(s), 1 warning(s)

warning C4786
最初の頃は場所が限定てきていたので #pragma warning (… : 4786 ) で切り替えていた.
がそのうち,プロジェクトによっては StdAfx.h で対応する様になった.


古くからのプロジェクトで,直接はこれらの対応を行っていない(共通のヘッダでの対応)プロジェクトが幾つもある.
コンパイル単位ではほとんど C4786 は出力されないが,一部のソースで出力され,また限定できたのでそのメモ.

--------------------Configuration: BlockIn - Win32 Debug--------------------
Compiling...
SMastSel.cpp
c:\program files (x86)\microsoft visual studio\vc98\mfc\include\afxtempl.h(63) : warning C4786: 'std::vector<std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char
>,std::allocator<char> > > >,std::allocator<std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > > >' : identifier was truncated to '
255' characters in the debug information
SMastSel.obj - 0 error(s), 1 warning(s)

ソースに #pragma warning (disable : 4786 ) を追加して,更にそのヘッダがインクルードしているものをソースに追加.
warning C4786  AfxTempl.h
これで AfxTempl.h をインクルードしているヘッダファイルが限定できた.


iostream を使用している場合も,その前に disable : C4786 が必要みたいだが,その場合は簡単には見つけられない?
warning C4786  iostream


他には fstream ,string .

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

::ShellExecute

「インデックスのオプション」を開くために ::ShellExecute などから開けないかと…
検索するとコマンドプロンプトなどで「control.exe /name Microsoft.IndexingOptions」とすれば良いことがわかった.


この動作の cpp のコード.

CString	Error_FormatMessage(const DWORD error)
{
	CString	message ;
	LPVOID	lpMessageBuffer = NULL ;
	if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
			NULL,error,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
			(LPTSTR)&lpMessageBuffer,0,NULL)) {
		message = LPTSTR(lpMessageBuffer) ;
		::LocalFree(lpMessageBuffer) ;
		}
	return	message ;
	}
void CShellEDlg::OnExecute() 
{
	UpdateData(TRUE) ;
	HINSTANCE hInst = ::ShellExecute(this->GetSafeHwnd(),m_StrOper,m_StrFile,m_StrPara,NULL,SW_SHOW) ;
	if (UINT64(hInst) > 32)	{	return ;	}
	DWORD	error = ::GetLastError() ;
	CString	str ;
	{
		str.Format(_T("%d\r\n%d"),DWORD(hInst),error) ;
		str += _T("    ") + ::Error_FormatMessage(error) ;
		str += _T("\r\n") + m_StrOper ;
		str += _T("\r\n") + m_StrFile ;
		str += _T("\r\n") + m_StrPara ;
		}
	AfxMessageBox(str) ;
	}

CShellEDlg::OnExecute()
ShellE  メンバ変数
ShellE.exe
https://itl.mish.work/i_Tools/Doc/blog/vc/ShellE.zip

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

VC6 から VC2019 への移行

今回は VC 6 ds? の VC 2019 への更新.
VS 2022 では,VC 6 からのアップグレードがなくなった


VS 2019 で dsw を開き 2019 に更新.
設定は VC 8 の時の手順とほとんど変わらない(設定値が微妙に異なる部分あり).
出力ディレクトリなどを「c:\Temp\…\$(ProjectName)\$(Configuration).142\」に.
VC 2019 出力ファイル
「文字セット」を「Unicode 文字セットを使用する」に.
VC 2019 文字セット
「プリコンパイル済み…」を「$(IntDir)$(TargetName).pch」に.
VC 2019  プリコンパイル済みヘッダ
「C/C++」の「出力ファイル」を「$(IntDir)」に.
VC 2019 C/C++ 出力ファイル
「リンカ」の「出力ファイル」を「$(OutDir)$(ProjectName).exe」に.
VC 2019 リンカ 出力ファイル
「ブラウザ情報」の「出力ファイル」を「$(OutDir)$(ProjectName).bsc」に.
VC 2019 ブラウザ情報 出力ファイル


そのままビルドすると,デバッグ版では D8016 エラーになる.
「C/C++」-「すべてのオプション」の「関数レベルでリンクする」をブランクに.
「関数レベルでリンクする」をブランクに


https://itl.mish.work/i_Tools/Doc/blog/migrate/Test0526.zip

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

VC6 プロジェクトの移行

今更の内容ではあるが,VC 6 プロジェクトを VC 8 などに移行する手順のまとめ.


私の場合,VC 6 からプロジェクトを作成して VC 2017 などでビルドした exe をリリースすることが多い.
他にも,コードの単体テストのためにコンソール AP を作成する時も VC 6 がお手軽.
Win11 でも MFC42*.dll などは入っているので,テストも exe をコピーすれば可能となる.
以前は VC 7 なども対象としていたが,関係するプロジェクトで必要がなくなり,今は使っていない.
また VC 7 形式を通すvcproj を直接編集しないといけない状態になることがある.
プロジェクトのバックアップをしやすい様に exe などの出力先は,別の所を指定している.


VC 6 で MDI プロジェクトとして作成.プロジェクト名はなるべく 5 文字以下にしている.
出力ディレクトリを変更.この時 VC のバージョンごとに出力先を分けている.
出力ディレクトリを変更

C:.
└─Test
    ├─Debug.060
    ├─Debug.080
    ├─Release.060
    └─Release.080

VC 8 で Test.dsw を開く.
文字セットを「Unicode 文字セットを使用する」に.
出力ディレクトリなどを「c:\Temp\…\$(ProjectName)\$(ConfigurationName).080」に.
VC 8 出力ディレクトリ
「プリコンパイル済み…」を「$(IntDir)/$(TargetName).pch」に.
プリコンパイル済みヘッダファイル
「C/C++」の「出力ファイル」を「$(IntDir)/」に.
C/C++  出力ファイル
「リンカ」の「出力ファイル」を「$(OutDir)/$(ProjectName).exe」に.
リンカ 出力ファイル
「プログラム データベース…」を「$(OutDir)/$(ProjectName).pdb」に.
プログラム データベース ファイルの生成
「ブラウザ情報」の「出力ファイル」を「$(OutDir)/$(ProjectName).bsc」に.
ブラウザ情報 出力ファイル
ツリーに「MIDL」が表示されている場合は「タイプライブラリ」を「$(IntDir)/$(ProjectName).tlb」に変更.
必要に応じて,それぞれの「コマンド ライン」で 060 のままの所がないか確認.


ビルドすると次のワーニングになる.

1>------ ビルド開始: プロジェクト: Test, 構成: Debug Win32 ------
1>コンパイルしています...
1>Test.cpp
1>o:\document\vc_test\migrate\test\test.cpp(61) : warning C4996: 'CWinApp::Enable3dControls': CWinApp::Enable3dControls is no longer needed. You should remove this call.
1>        c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(4477) : 'CWinApp::Enable3dControls' の宣言を確認してください。
1>リンクしています...
1>マニフェストを埋め込んでいます...
1>Test - エラー 0、警告 1
========== ビルド: 1 正常終了、0 失敗、0 更新、0 スキップ ==========

削除,または次の様に修正する.

#if(_MFC_VER >= 0x0700)
#else
#ifdef _AFXDLL
	Enable3dControls();		// 共有 DLL 内で MFC を使う場合はここをコールしてください。
#else
	Enable3dControlsStatic();	// MFC と静的にリンクする場合はここをコールしてください。
#endif
#endif

個人的によく変更する設定として
「C/C++」-「言語」-「OpenMP サポート」を「はい」に.
「リンカ」-「システム」-「大きい…アドレス」を「2GBを超える…サポートする」に.


Test.sln と Test.vcproj を Test_80.sln と Test_80.vcproj としてコピー.
Test_80.sln をエディタで開いて,Test_80.vcproj に.
sln ファイルを編集して ~_80.vcproj に


vC 9 以降に更新する場合は Test.sln を開く.
出力ディレクトリなどを「c:\Temp\…\$(ProjectName)\$(ConfigurationName).090」などに.
VC 9 出力ファイル
VC 8 の時と同様に
Test.sln と Test.vcproj を Test_90.sln と Test_90.vcproj としてコピー.
Test_90.sln をエディタで開いて,Test_90.vcproj に.


vcproj をエディタで開くと TypeLibraryName が c:\Temp\…\Test\Debug.060/Test.tlb として残っている.
そのままでも問題はなさそうだが,修正するとすれば $(IntDir)/$(ProjectName).tlb か.
https://itl.mish.work/i_Tools/Doc/blog/migrate/Test0520.zip


2024/07/26
VC 10 以降でビルドした MDI.exe で「引数が正しくありません。」となることがある.
対応方法は InitInstance に AfxOleInit() の呼出しを追加する.

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

error C2272

次の様なコードで static にしようとすると,

class	RegPatNo	:	public	iDocCSV	{
//	...
public:
/*	static	*/	tstring		GetPathRPC	(void)	const ;
	} ;

inline	tstring	RegPatNo::GetPathRPC	(void)	const
{

	tstring	tmp_path = ::Get_i_Tools_tmp_date() ;
	::Folder_Create(tmp_path) ;
	tstring	rpc_name = ::Path_AddLastSP(tmp_path) + FN_RP_csv ;
	return	rpc_name ;
	}
--------------------Configuration: T_CSV_ - Win32 Debug--------------------
Compiling...
T_CSV_.cpp
t:\develop\_.src\test\regpatno.hpp(101) : error C2272: 'GetPathRPC' : modifiers not allowed on static member functions
Error executing cl.exe.

T_CSV_.exe - 1 error(s), 0 warning(s)

error C2272  : modifiers not allowed on static member functions
次の様に const の指定を外さなければならない.
static tstring GetPathRPC (void) ;
const の指定を外す

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

DirectoryNotFoundException

以前作成した .NET の ZipFile クラス使用した exe
この iZIP.exe で System.IO.DirectoryNotFoundException .


原因は,ある環境でユーザ名に半角スペースが含まれていた.
ユーザ名に半角スペースを含む環境を作成して ZipFold.exe で同じ様な操作を行ったが,再現できない.
いろいろと調べていると,iZIP.exe に渡す時の入力のフォルダ名に半角スペースが含まれていると現象が発生する.

C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\test>Q:\C_Temp\i_Tools\ZIP\iZIP\Release.140\iZIP.exe a "C:\Users\Iwao\AppData\Local\Temp\Send.tmp\20240416\09 22 39\" abc.zip

ハンドルされていない例外: System.IO.DirectoryNotFoundException: パス 'C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\zip_CLI\20240416\154459\a' の一部が見つかりませんでした。
   場所 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   場所 System.IO.FileSystemEnumerableIterator`1.CommonInit()
   場所 System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   場所 System.IO.DirectoryInfo.EnumerateFileSystemInfos(String searchPattern, SearchOption searchOption)
   場所 System.IO.Compression.ZipFile.DoCreateFromDirectory(String sourceDirectoryName, String destinationArchiveFileName, Nullable`1 compressionLevel, Boolean includeBaseDirectory, Encoding entryNameEncoding)
   場所 ZipFile_create(Char* fld_file, Char* zip_name) 場所 c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring:行 1017
   場所 zip_create(basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> >* , Char* zip_root) 場所 t:\develop\_.src\__mlt_\zip_func.hxx:行 47
   場所 zip_create(Char* fld_file, Char* zip_name) 場所 t:\develop\_.src\__mlt_\zip_func.hxx:行 143
   場所 call_func(Int32 argc, Char** argv) 場所 c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring:行 521
   場所 wmain(Int32 argc, Char** argv) 場所 l:\document\develop\tools\_free\ziptools\izip\izip.cpp:行 168
   場所 _wmainCRTStartup()

C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\test>Q:\C_Temp\i_Tools\ZIP\iZIP\Release.140\iZIP.exe a "C:\Users\Iwao\AppData\Local\Temp\Send.tmp\20240416\09 22 39\" ".\20240416\1545\abc.zip"

ハンドルされていない例外: System.IO.DirectoryNotFoundException: パス 'C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\zip_CLI\20240416\154602\a' の一部が見つかりませんでした。
   場所 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   場所 System.IO.FileSystemEnumerableIterator`1.CommonInit()
   場所 System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   場所 System.IO.DirectoryInfo.EnumerateFileSystemInfos(String searchPattern, SearchOption searchOption)
   場所 System.IO.Compression.ZipFile.DoCreateFromDirectory(String sourceDirectoryName, String destinationArchiveFileName, Nullable`1 compressionLevel, Boolean includeBaseDirectory, Encoding entryNameEncoding)
   場所 ZipFile_create(Char* fld_file, Char* zip_name) 場所 c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring:行 1017
   場所 zip_create(basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> >* , Char* zip_root) 場所 t:\develop\_.src\__mlt_\zip_func.hxx:行 47
   場所 zip_create(Char* fld_file, Char* zip_name) 場所 t:\develop\_.src\__mlt_\zip_func.hxx:行 143
   場所 call_func(Int32 argc, Char** argv) 場所 c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring:行 521
   場所 wmain(Int32 argc, Char** argv) 場所 l:\document\develop\tools\_free\ziptools\izip\izip.cpp:行 168
   場所 _wmainCRTStartup()

C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\test>

iZIP.exe  System.IO.DirectoryNotFoundException
入力のフォルダ名の “…\20240416\09 22 39\” の “09 22 39” 直後の ‘\’ を削除するとうまくいく.


デバッガで iZIP.exe に渡されるコマンドラインを確認.
iZIP.exe コマンドライン引数
デバッグ時,ダンプする様にコードを書換え.
iZIP.exe コマンドライン引数のダンプ
やはり argv がうまく解釈されていない.
argv[2]が「…\17 53 06″ c:\…」となってしまっている.
“…\17 53 06\\” の様にすれば通ることは確認できた.
perse_commandline では ‘\”‘ がダブルクォーテーションと解釈され,’\\’ はバックスラッシュ?


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

「引数が正しくありません」

以前に書いた情報を整理.
Win10 21H1 でうまく動作しない exe
Win10 環境で,MDI exe にドキュメントをドロップすると「引数が正しくありません」となることがある.


原因は ::CoInitinalize が呼び出されていないため.
コードでの対応方法としては InitInstance の最初に以下を追加.

	// OLE ライブラリを初期化します。
	if (!AfxOleInit()) {
		AfxMessageBox(_T("OLE の初期化に失敗しました。")) ;
		return	FALSE ;
		}

また,一度「開く」ダイアログを表示すると,その後は問題ない.

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

引数が正しくありません

ツールチップの表示内容に幾つかの情報を追加してテストしていると…
—————————
xxxxxxxx
—————————
引数が正しくありません。
—————————
OK
—————————
引数が正しくありません
デバッガで追いかけると MAX_TIP_TEXT_LENGTH の制限を超えていた.
CToolTipCtrl::UpdateTipText
呼び元で超えない様にカットして対応.

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

フォルダの更新日時の設定

以前に作成した mtime を更新するツール
データファイルなどの更新日時を揃えるために作成したもの.
更新日時の設定は CFile::SetStatus で行っている.

	CString		file = UpdateFiles[index] ;
	CFileStatus	fs ;
	CFile::GetStatus(file,fs) ;
	fs.m_mtime = newTime ;
	CFile::SetStatus(file,fs) ;

このツールではフォルダの更新日時は変更できない.


その後 Linux 環境などでも動作する様なコードを作成
utime を使用したもの.
Linux 環境ではフォルダに対してもうまく動作するが,Windows 環境では相変わらず.
DS220  utime
ここまでは,以前調べたもの


2ヶ月ほど前だったと思うが,検索していて次のページを見つけた.
ファイル・フォルダーの更新日時を変更


改めて CFile::SetStatus や _utime の中身を見ると,動作は同じで ::CreateFile と ::SetFileTime を呼出している.
デバッガで追いかけていると ::CreateFile で失敗している.errno は 13 .
::CreateFile を次の様に指定して呼出すと,ファイルの場合は問題ないがフォルダは NG .

HANDLE  hFile = ::CreateFile(file_name,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,     NULL) ;

フォルダの場合 FILE_FLAG_BACKUP_SEMANTICS が指定されていなければならないみたい.

HANDLE  hFile = ::CreateFile(file_name,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL) ;

time_t から FILETIME への変換は次の所.
https://learn.microsoft.com/ja-jp/windows/win32/sysinfo/converting-a-time-t-value-to-a-file-time
SetFTime.hxx

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

.INI に更新されない?

個人的なツールなどでレジストリを汚したくないために .ini を使用している.
今回個人的な ProtectT クラスを書き直してテストしているとうまく動作しない.
該当コードの単体テストではうまく通るが,ツールに組込んで動作させるとうまくいかないことがある.
コードの内容としては,共通の i_Tools.ini と AP.ini に同じ値を更新していて,それを読みだした時に値が異なっていた.


i_Tools.ini は他の AP からも読み書きしている.
タイミングによって,うまく更新できないことがある?
文字の立体化
ProtectT の i_Tools.ini へアクセスするコードを見直して,極力書き込みを減らすようにした.
また,読み込み時,値が意図したものと異なる場合は AP.ini の方を利用する様にした.
これで今回の部分は対応できていると思うが,他の既存部分ではまだ問題がありそう.


次の様なコードで確認すると,やはり書けないことがある様子.

	{
		#define	Sec_test  _T("_test_")
		#define	Ent_test  _T("_test_")
		RI_app	app ;
		RI_env	env ;
		for (long index=0 ; index<500 ; index++) {
			if (index%10 == 0)	{	std::tout << std::endl ;	}
			std::tout << index << _T("\t") ;
			std::tout << app.set(Sec_test,Ent_test,index) ;	std::tout << _T("  ") ;
			std::tout << env.set(Sec_test,Ent_test,index) ;	std::tout << _T("\t") ;
			long	val_a = app.get(Sec_test,Ent_test,-1) ;
			long	val_e = env.get(Sec_test,Ent_test,-2) ;
			if (val_a != val_e) {
				std::tout << std::endl ;
				std::tout << val_a << _T("\t") << val_e << std::endl ;
				::Sleep(1000) ;
				break ;
				}
			::Sleep(10) ;
			}
		std::tout << std::endl ;
		return	true ;
		}

env.set(…) は,内部的に ::WritePrivateProfileString を呼出していて 0 が返っている.
::WritePrivateProfileString


最初現象を簡単には再現できなかったが,エクスプローラのサムネイル表示を行っていると発生しやすい.
また,今回のテスト用 exe が止まってしまうこともあった.開いているエクスプローラをすべて閉じることで解消.
シェルエクステンションのコードの見直しが必要か?


ini への書き込み部分を次の様に変更.

//	return	(     ::WritePrivateProfileString(sec,ent,val,ini)==TRUE) ;
	BOOL	res = ::WritePrivateProfileString(sec,ent,val,ini) ;
	if (!res)	{
		std::terr << _T("::WritePrivateProfileString ")	<< sec << _T(" ") << ent << _T(" ") << ::GetLastError() << std::endl ;
		for (size_t index=0 ; index<10 ; index++) {
			res = ::WritePrivateProfileString(sec,ent,val,ini) ;
			if (res)	{	break ;		}
			::Sleep(10) ;
			}
		}
	return	(res==TRUE) ;

::GetLastError() では 32 ERROR_SHARING_VIOLATION が返ってくる.

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

error C2144 , C2501

ビルドしていると

--------------------Configuration: TToPA - Win32 Release--------------------
Compiling...
TToPADlg.cpp
C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\gl/gl.h(23) : error C2144: syntax error : missing ';' before type 'int'
C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\gl/gl.h(23) : error C2501: 'c' : missing storage-class or type specifiers
C:\Program Files (x86)\Microsoft Visual Studio\VC98\INCLUDE\gl/gl.h(23) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

TToPA.exe - 3 error(s), 0 warning(s)

error C2144 , C2501
ファイルの先頭に “c” の文字が入力されてしまっていた.
デバッグしていて,何かの拍子に “c” が入ってしまったことに気づかなかった.
バックアップしてあったファイルを戻して対応.

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

error C2062 , C2065

先日作成した,レジストリなどのアクセスのコード
それを使用しているコードを VC 2015 環境でビルドすると…

1>------ ビルド開始: プロジェクト:S_asZ, 構成:Debug Win32 ------
1>t:\develop\_.src\__win\ri_env.hxx(67): error C2062: 型 'bool' は不要です。
1>t:\develop\_.src\__win\ri_env.hxx(69): error C2065: 'res': 定義されていない識別子です。
1>t:\develop\_.src\__win\ri_env.hxx(70): error C2065: 'res': 定義されていない識別子です。
1>t:\develop\_.src\__win\ri_env.hxx(72): error C2065: 'res': 定義されていない識別子です。
1>t:\develop\_.src\__win\ri_env.hxx(78): error C2062: 型 'bool' は不要です。
1>t:\develop\_.src\__win\ri_env.hxx(80): error C2065: 'res': 定義されていない識別子です。
1>t:\develop\_.src\__win\ri_env.hxx(81): error C2065: 'res': 定義されていない識別子です。
1>t:\develop\_.src\__win\ri_env.hxx(83): error C2065: 'res': 定義されていない識別子です。
1>t:\develop\_.src\__win\ri_env.hxx(133): error C2062: 型 'bool' は不要です。
1>t:\develop\_.src\__win\ri_env.hxx(135): error C2065: 'res': 定義されていない識別子です。
1>t:\develop\_.src\__win\ri_env.hxx(136): error C2065: 'res': 定義されていない識別子です。
1>t:\develop\_.src\__win\ri_env.hxx(138): error C2065: 'res': 定義されていない識別子です。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========

error C2062: 型 'bool' は不要です。
今まで OpenMP が動作しない状態でのビルドだったので気づかなかった.
#ifdef _OPENMP … #endif の位置が違っていた.

bool	set_DW	(LPCTSTR sec,LPCTSTR ent,const u_32 val)    {
    bool	res = false ;
    #ifdef	_OPENMP
        #pragma	omp	critical	(RI_app_set_DW)
    #endif
    {
        if (Use_reg)	{    REG_get_sec_key(sec) ;	res = RI_rkey.set_DW(         ent,val) ;    }
        else       	{                          	res = ::  INI_set(NameINI,sec,ent,val) ;    }
        }
    return	res ;
    }

bool res = false を #ifdef の前に持ってきて対応.

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

error C2666: ‘get’ : 8 overloads …

次の様なコードをコンパイルすると,「error C2666: ‘get’ : 8 のオーバーロード関数があいまいです。」

{
	#define	SecProtectT	_T("Debug")
	RI_app	CountP ;
	RI_env	CountC ;
	tstring	exe_title = ::Path_GetTitle(::RI_get_module_name()) ;
	time_t	nowTime = ::time(NULL) ;
	time_t	countP_ = time_t(CountP.get(SecProtectT,exe_title.c_str(),i_32(nowTime))) ;
	time_t	countC_ = time_t(CountC.get(SecProtectT,exe_title.c_str(),i_32(nowTime))) ;
	time_t	countPT = time_t(CountP.get(SecProtectT,exe_title.c_str(),i_64(nowTime))) ;
	time_t	countCT = time_t(CountC.get(SecProtectT,exe_title.c_str(),i_64(nowTime))) ;
	}
--------------------構成: PrtctT - Win32 Debug--------------------
コンパイル中...
PrtctT.cpp
l:\document\develop\tools\_yet\_other\key2013\prtctt\prtctt.cpp(110) : error C2666: 'get' : 8 のオーバーロード関数があいまいです。(新しい機能 ; ヘルプを参照)
l:\document\develop\tools\_yet\_other\key2013\prtctt\prtctt.cpp(110) : fatal error C1903: 直前のエラーを修復できません; コンパイルを中止します。
cl.exe の実行エラー
PrtctT_d.exe - エラー 2、警告 0

error C2666: 'get' : 8 のオーバーロード関数があいまいです。
次のメンバ関数を追加したことによる影響だったが,RI_app でエラーになっていないのがよくわからない.
i_32 get (c_tstring& sec,c_tstring& ent,const i_32 def) { … }
次の LPCTSTR 形式のメンバ関数を追加して対応.
i_32 get (LPCTSTR sec,LPCTSTR ent,const i_32 def) { … }

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

C2440: ‘return’ : cannot convert …

以前,iniレジストリ を操作する関数を作成した.
それで,少しずつ書き換えていると…

--------------------Configuration: PrtctT - Win32 Debug--------------------
Compiling...
PrtctT.cpp
t:\develop\_.src\__win\ri_reg.hxx(383) : error C2440: 'return' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'int'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
        l:\document\develop\tools\_yet\_other\key2013\prtctt\prtctt.cpp(162) : see reference to function template instantiation 'int __cdecl REG_get(struct HKEY__ *,const class std::basic_string<char,struct std::char_traits<char>,class std::allocato
r<char> > &,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const int &)' being compiled
Error executing cl.exe.

PrtctT_d.exe - 1 error(s), 0 warning(s)

通常の関数であればうまく機能すると思うが…
関数 template は難しい.
error C2440: 'return' : '...' から 'int' に変換することはできません。
コメントにしている部分で書き換えれば OK .

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

Windows C++ __argc __argv

MFC でコードを書いていて,コマンドライン引数を取りたくなった.
MFC では次の様にすれば取れるが,欲しいのは c の main に渡される argc と argv .
CString cmd_line = AfxGetApp()->m_lpCmdLine ;
検索すると次の所があった.欲しかった情報は __argc と __argv
【 VC++ MFC 】MFC でコマンドライン引数を利用する方法
次の様なコードを書いて動作を確認.

#include	<clocale>
#include	<iostream>
#include	<tchar.h>

#ifdef	_UNICODE
	#define		tin 		wcin
	#define		tout		wcout
	#define		terr		wcerr
	#define		tlog		wclog
#else
	#define		tin 		cin
	#define		tout		cout
	#define		terr		cerr
	#define		tlog		clog
#endif

int	_tmain	(int ,TCHAR* )
{
	_tsetlocale(LC_ALL,_T("")) ;
	{
		std::tout   		<< __argc      	<< std::endl ;
		for (int index=0 ; index<__argc ; index++) {
			std::tout	<< __targv[index]	<< std::endl ;
			}
		}
	return	0 ;
	}

Windwos C コマンドライン引数
_tmain が呼び出される前の mainCRTStartup の ::_setargv で設定されている.
::_setargv

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

LNK2001 _WinMain@16

VC 6 で,_MBCS から _UNICODE に変更すると,次のエラーになることがある.

--------------------Configuration: T_mtx_n - Win32 Release--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
T_mtx_n.cpp
T_mtx_nD.cpp
Generating Code...
Linking...
msvcrt.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
c:\Temp\Test_win\T_mtex\T_mtx_n\Release.060/T_mtx_n.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

T_mtx_n.exe - 2 error(s), 0 warning(s)

「リンク」タブの「エントリーポイント シンボル」に wWinMainCRTStartup を入力する.
VC 6  「リンク」タブ-「エントリーポイント シンボル」  wWinMainCRTStartup

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

$(WindowsSDK_IncludePath)

VC 2017 以降?,VS の更新により Windows SDK のパスも更新されてしまうことがある?
プロジェクトの設定にもよるみたいだが…
Windows SDK バージョンの指定


対象のプロジェクトがどれを使用しているかは,次のマクロで確認できる.
$(WindowsSDK_IncludePath) ,$(WindowsSDK_LibraryPath_x86) など.
$(WindowsSDK_IncludePath)
C:\Program Files (x86)\Windows Kits\10\


他によく使うのが,Windows.h などを開いて「このアイテムのフォルダーを開く」.
Windows.h  このアイテムのフォルダーを開く

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

C2039 , C3861 , C2665

個人的なメモです.
VC 6 プロジェクトを VC 7 以降にあげた時のエラー.

1>------ ビルド開始: プロジェクト: PLtoB, 構成: Debug Win32 ------
1>コンパイルしています...
1>PLtoBDlg.cpp
1> ...
1>t:\develop\_.src\__iwao\htmo_th.hxx(70) : error C2039: 'ToImage' : '`global namespace'' のメンバではありません。
1>t:\develop\_.src\__iwao\htmo_th.hxx(70) : error C3861: 'ToImage': 識別子が見つかりませんでした
1>t:\develop\_.src\__iwao\htmo_th.hxx(155) : error C2665: 'ToDIB' : 3 オーバーロードのどれも、すべての引数の型を変換できませんでした
1>        t:\develop\_.src\__win\i_dib_fn.hxx(188): 'i_DIB ToDIB(const HBITMAP)' の可能性があります。
1>        t:\develop\_.src\_afxw\i_dib_x.hxx(86): または 'i_DIB ToDIB(const MemoryDC &)'
1>        引数リスト '(Image)' を一致させようとしているとき
1> ...
1>PLtoB - エラー 3、警告 0
========== ビルド: 0 正常終了、1 失敗、0 更新、0 スキップ ==========

Imgae.hxx を XxxDlg.h に追加.
次の場合は,MemoryDC.hxx を追加.

1>------ ビルド開始: プロジェクト: PLtoB, 構成: Debug Win32 ------
1>コンパイルしています...
1>PLtoBDlg.cpp
1> ...
1>t:\develop\_.src\__iwao\htmo_th.hxx(35) : error C2665: 'ToDIB' : 3 オーバーロードのどれも、すべての引数の型を変換できませんでした
1>        t:\develop\_.src\__win\i_dib_fn.hxx(188): 'i_DIB ToDIB(const HBITMAP)' の可能性があります。
1>        t:\develop\_.src\_afxw\i_dib_x.hxx(56): または 'i_DIB ToDIB(const Image &)'
1>        引数リスト '(MemoryDC)' を一致させようとしているとき
1> ...
1>PLtoB - エラー 1、警告 0
========== ビルド: 0 正常終了、1 失敗、0 更新、0 スキップ ==========

文字の立体化


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

VC 14.x での MFC のソース?

VC 2019 など最新でない VC を使用していると,MFC ソースにステップイン できなくなることがある.
VC 2019 MFC cstring.h
大抵は,インストールされている最新の MFC の場所を指定すれば良さそう.

C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.37.32822\atlmfc\include
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.37.32822\atlmfc\src\mfc

VC 2019 atlmfc src mfc


VC のアップデートがあり更新したためか,一部で「ビルド時のものと異なる」と表示されるようになった.

---------------------------
Microsoft Visual Studio
---------------------------
ソース ファイル:C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.37.32822\atlmfc\include\cstringt.h
モジュール:C:\Windows\SysWOW64\mfc140ud.dll
プロセス:[28036] GLSmth.exe
ソース ファイルがモジュールがビルドされたときのものと異なります。デバッガーでこのファイルを使用しますか?
---------------------------
はい(Y)   いいえ(N)   
---------------------------

VC 2022 MFC cstring.h
VC 2022 で試しても同様になるので,アップデートの問題か?

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

角の二等分線

https://en.wikipedia.org/wiki/Bisection
wiki にあるアニメーションをコードにしたもの.

Ld2	V2_get_bisector	(const Vd2& vp,const Vd2& vc,const Vd2& vn)
{
	//	    * vp    
	//	    |       
	//	    |       
	//	    |       * vcx
	//	    |     / 
	//	    | o /   
	//	    | / o   
	//	vc  * - - - - - - * vn
	Vd2	vcp = (vp-vc).Normalized() ;
	Vd2	vcn = (vn-vc).Normalized() ;
	Vd2	vcb = (vcp+vcn)/2. ;
	Vd2	vcx = vcb + vc ;
	{
		vcx = ::get_cross_line(vp,vn,vc,vcx) ;
		}
	Ld2	lbs(vc,vcx) ;
	return	lbs ;
	}

青い円弧が,最初の 2 行の Normalized .
次の中点を求めているのは,赤い円弧の交点を結ぶ線にあたる.
二等分線を対辺?まで延長.
二等分線
角の二等分線

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