ホーム » 2023 » 12月

月別アーカイブ: 12月 2023

2023年12月
 12
3456789
10111213141516
17181920212223
24252627282930
31  

カテゴリー

アーカイブ

ブログ統計情報

  • 81,162 アクセス



.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.

#pragma omp critical

共通のリソースに対してのコードを書いていて,ちょっと気になったので調べてみた.
テスト用に書いたのコードは次の様なもの.

#ifdef		_OPENMP
#include	<omp.h>
#endif

#include	<clocale>
#include	<iostream>

#ifdef	_MSC_VER
	#include	<tchar.h>
#else
	#define		 _T(x)			x
	typedef		char			TCHAR ;
#endif

#ifdef	_UNICODE
	#define		_tmain			wmain
	#define		tout			wcout
#else
	#define		_tmain			main
	#define		tout			cout
#endif

bool	test_n	(const long n)
{
	std::tout << _T("test_") << n << _T("\t") ;
	{
		for (long index=0 ; index<10 ; index++) {
			#ifdef	_OPENMP
			//	#pragma	omp	critical	//	(test)		//	--- (C)
			#endif
			{
				std::tout << (n*10 + index+1) << _T("\t") ;
				}
			}
		}
	return	true ;
	}

bool	test_	(void)
{
	std::tout << _T("test_") << std::endl ;
	{
		#ifdef	_OPENMP
			#pragma	omp	parallel for
		#endif
		for (long index=0 ; index<10 ; index++) {
			#ifdef	_OPENMP
				#pragma	omp	critical	//	(test)		//	--- (P)
			#endif
			{
				test_n(index) ;
				std::tout << std::endl ;
				}
			}
		}
	return	true ;
	}

int	_tmain	(int argc,TCHAR* argv[])
{
	{
		::test_() ;
		}
	return	0 ;
	}

実行させると,期待通り.
#pragma omp critical


ここで,関数 test_n() の次の行を有効にしてしまうと…
#pragma omp critical // (test) // — (C)
test_
test_0 致命的なユーザー エラー 1002: 同一名の 1 つで ‘#pragma omp critical’ が不適切に入れ子にされています
致命的なユーザー エラー 1002: 同一名の 1 つで '#pragma omp critical' が不適切に入れ子にされています
それぞれを異なる名称で指定する必要がある.
#pragma omp critical (test_n) // — (C)
#pragma omp critical (test_) // — (P)
#pragma omp critical 異なる名称
VC リリース版ではうまく動作してしまうこともある?


Linux 環境でコンパイルした a.out を NAS 環境に持っていくと,DS220+ では実行できた.
-fopenmp を付けたコンパイルは不可
TS253D では「libgomp.so がない」となって実行できない.
OpenMP  a.out の NAS での実行

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

VERR_UNRESOLVED_ERROR

Win11 上の仮想マシン Mint を起動しようとすると,
VM Name: Mint
Unresolved (unknown) host platform error. (VERR_UNRESOLVED_ERROR).
Result Code:
E_FAIL (0X80004005)
Component:
ConsoleWrap
Interface:
IConsole {6ac83d89-6ee7-4e33-8ae6-b257b2e81be8}
VirtualBox VERR_UNRESOLVED_ERROR
検索しても該当しそうなものがわからない.
多く見つかるのは,Hyper-V などの無効化.


PC を再起動させよう思い,他の仮想マシンを「保存」して,試しに Mint を起動するとうまく起動した.
それで,「保存」した他の仮想マシンを起動しようとすると同様のエラーに.
こうなると,システムリソースの問題と思い,プロセッサ数を減らすが効果はない.
次にメモリ量を減らしてうまく起動した.
先日作成した WS 2019 のメモリ量を 6G から 4G にして運用することにした.
VirtualBox  Mint


Mint 環境でコンパイルできる様に,共通のコードを参照するための mount .
/mnt/_.src を作成して,Fedora 環境にあった .sh をコピー.が,エラーとなる.
以前やった時を見直すと,IP で指定しないとうまくいかないことがあった
.sh を書き換えてうまくいった.
Mint   mount  IP

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.