ホーム » VC (ページ 6)

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

2025年7月
 12345
6789101112
13141516171819
20212223242526
2728293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 117,885 アクセス




VC 14 デバッグ MFC にステップイン

VC 2015 で MFC を使用した SDI.exe をデバッグしていると,MFC のコードにステップインできない?
入っている他の VC で試すと VC 2013 まではうまく機能している.
検索しても,これはという内容には引っ掛からなかった?


アプリケーションクラスの CG3toMApp::InitInstance() を抜ける時,そのままステップ実行していると…
mfc140ud.i386.pdb は読み込まれていません
「Microsoft Symbol Servers」にチェックを付けて「読み込み」.
MFC ソース内のデバッグができる様になった.


設定としては「ツール」-「オプション」の中の「デバッグ」-「シンボル」.
「ツール」-「オプション」-「デバッグ」-「シンボル」


2022/02
%TEMP% では消えてしまうので,シンボルキャッシュの場所を変更している.
VC 2017 シンボルキャッシュの場所
VC フォールバック 設定


https://itl.mish.work/Iwao/Doc/other/vs/
https://jml.mish.work/index.php/cpp/vs-install.html

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

VC 12 LNK1104 , VC 14.2 LNK2019

VC 6 のプロジェクトを順に更新して,…

------ ビルド開始: プロジェクト:BChgN, 構成:Debug Win32 ------
BChgN.obj : warning LNK4075: /EDITANDCONTINUE は /OPT:LBR の指定によって無視されます。
LINK : fatal error LNK1104: ファイル 'mfc120d.lib' を開くことができません。
------ ビルド開始: プロジェクト:G3_CLS, 構成:Release Win32 ------
LINK : fatal error LNK1104: ファイル 'mfc120.lib' を開くことができません。
------ ビルド開始: プロジェクト:G3_CLS, 構成:Debug Win32 ------
G3_CLS.obj : warning LNK4075: /EDITANDCONTINUE は /OPT:LBR の指定によって無視されます。
LINK : fatal error LNK1104: ファイル 'mfc120d.lib' を開くことができません。
------ ビルド開始: プロジェクト:G3_toM, 構成:Debug Win32 ------
ComPrj01.obj : warning LNK4075: /EDITANDCONTINUE は /OPT:LBR の指定によって無視されます。
LINK : fatal error LNK1104: ファイル 'mfc120d.lib' を開くことができません。
------ ビルド開始: プロジェクト:ig3_toM, 構成:Release Win32 ------
LINK : fatal error LNK1104: ファイル 'mfc120.lib' を開くことができません。
------ ビルド開始: プロジェクト:ig3_toM, 構成:Debug Win32 ------
ComPrj01.obj : warning LNK4075: /EDITANDCONTINUE は /OPT:LBR の指定によって無視されます。
LINK : fatal error LNK1104: ファイル 'mfc120d.lib' を開くことができません。
========== ビルド: 0 正常終了、6 失敗、4 更新不要、0 スキップ ==========
ビルドを開始しました...
------ ビルド開始: プロジェクト: BChgN, 構成: Debug Win32 ------
BChgN.obj : warning LNK4075: /EDITANDCONTINUE は /INCREMENTAL:NO の指定によって無視されます。
msvcrtd.lib(exe_wwinmain.obj) : error LNK2019: 未解決の外部シンボル _wWinMain@16 が関数 "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) で参照されました
c:\Temp\TestMBL\BChgN\Debug.142\BChgN.exe : fatal error LNK1120: 1 件の未解決の外部参照
プロジェクト "BChg142.vcxproj" のビルドが終了しました -- 失敗。
========== ビルド: 0 正常終了、1 失敗、9 更新不要、0 スキップ ==========

BChgN は SDI.exe .それ以外は MFC を使用したコンソール AP .


うまくビルドできる vcxproj と比べると,ソースのプリプロセッサの定義が異なる.
VC 12 LNK1104 の対応のためエディタでコンパイルオプションを削除
それならと思い,VC の「ソリューション エクスプローラ」で,ソースを一度プロジェクトから外して,再度追加.
うまくビルドできる様になった.
vcxproj をエディタで開き直すと,<PreprocessorDefinitions Condition> がない.

  <ItemGroup>
    <ClCompile Include="ComPrj01.cpp" />
    <ClCompile Include="ig3_toM.cpp" />
  </ItemGroup> 

StdAfx.cpp 以外はファイル名のみで良さそう.
他のプロジェクトは,エディタで削除して対応.


2020/01/25
今度は,MFC を使用していないコンソール AP .
VC の設定で「それぞれのソースのプロパティページ」-「構成プロパティ」-「C/C++」-「プリプロセッサ」-「プリプロセッサの定義」をブランクにしてみたが…
「構成プロパティ」-「C/C++」-「プリプロセッサ」-「プリプロセッサの定義」
コンパイルすると _UNICODE などが定義されない.
<親またはプロジェクトの既定値から継承>
<親またはプロジェクトの既定値から継承>」にすることで,意図した設定になった.


2024/07/04
以前は VC 7 などを通していたが,最近は VC 8 以降のみにしている.
 VC6 プロジェクトの移行
 VC6 から VC2019 への移行
こうすることで,プリプロセッサの定義がうまくない現象はなくなった様に思う..

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

VC でのプロファイル

VC 6 の頃はよく使っていたが…
VC 12 では何故かうまく動かなかった.
VC 14 で簡単に動作を確認すると,前より使い易くなっている.


メニューの「分析」-「パフォーマンス プロファイラー」.
VC 14 「メニュー」-「分析」-「パフォーマンス プロファイラー」
「CPU 使用率」にチェックを付けて「開始」.
プロファイル用にビルドされて exe が起動する.
テストする操作を行い exe を終了させる.
暫くすると結果が表示される(この情報の見方はよくわからず).
VC 14 プロファイル exe を終了した後に表示される「概要」?
CPU のグラフの下の「詳細なレポートを作成します…」を「クリック」.
プロファイラ 詳細なレポート 概要
上の方のドロップダウンから「関数」を選択.
表示された関数名のリストから関数をダブルクリック(ここでは CF_GetOuterLine ).
CF_GetOuterLine の「関数コード ビュー」
ちょっと意外だったが,Vd3A の代入に時間がかかっている.


2020/12/23
Vd3A の代入ではなく参照にコードを変更.
テストする exe も,もう少し機能を単純化したものを使用.
VC 14 プロファイル Vd3A の「代入」を「参照」に変更
データにもよるが,該当部分の時間が半分位になった.


更にループ内の Vd3 も参照にしてみたが,こちらは効果なし.

typedef	Vector3<double> 	Vd3 ;		//  3D 座標 ( double の x , y , z ) 
typedef	std::vector<Vd3>	Vd3A ;		//  3D 座標の配列 

Vd3A は可変長で,メモリの確保と解放が伴うためと思われる.
std::vector の配列の要素に対する操作の逆アセンブル表示
* デバッグ版のため実際のコード(計測した Release 版)とは異なると思う.
1 回の「面の結合」

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

SetConsoleCtrlHandler

コンソール AP で,キー入力による中断ができないかと…
やりたいことは,時間がかかるコンソール AP で,その途中までの計算結果を保存すること.
コンソールアプリ 中断」で検索すると ::SetConsoleCtrlHandler を使えば良さそう.
MSDN を「PHANDLER_ROUTINE」で検索.次のサンプルが見つかった.
NSDN 2001/10 PHANDLER_ROUTINE
そのタイトル「Registering a Control Handler Function」で検索.
コントロール ハンドラー関数の登録
https://www.installsetupconfig.com/win32programming/
https://www.installsetupconfig.com/win32programming/winconsolecharapplication8index.html

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

#pragma message ( … (value) )

FBX SDK を使用したプロジェクトで,コンパイル時 FBX SDK のバージョンを表示したくなった.
FBX 2013.3 SDK 位からは FBXSDK_VERSION_STRING が使える.

#ifdef	FBXSDK_VERSION_STRING
	#pragma	message	("FBXSDK_VERSION " FBXSDK_VERSION_STRING)
#endif

それより古い場合に,コンパイルオプションで FS_VER=201100 などと指定する様にした.
考え方や動作は意図した通りになったが,この FS_VER を表示できないものかと…
検索すると VC では _CRT_STRINGIZE が使えるとあった.
コンパイル時に#defineの値を表示するにはどうすればよいですか?

#ifdef	FS_VER
	#pragma	message	("FS_VER " _CRT_STRINGIZE(FS_VER))
#endif

_CRT_STRINGIZE は …\VC\include\crtdefs.h や …\VC\include\vcruntime.h に定義されている.


古い VC などでも使える様に…

#ifndef		__CRT_STRINGIZE
	#define	__CRT_STRINGIZE(Value)	#Value
#endif
#ifndef		_CRT_STRINGIZE
	#define	_CRT_STRINGIZE(Value)	__CRT_STRINGIZE(Value)
#endif

https://python5.com/q/uxqhkyvx
#pragma message (_CRT_STRINGIZE(FS_VER))

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

MFC DLL error C2371 cerr

FBX SDK を使用したテストプロジェクト.
以前「MFC を使用する」になっていたもの.
関連するコードを変更して「MFC を使用しない」に書き換え.
そのままのコードを「MFC を使用する」に戻すと,…

--------------------構成: T_FBX - Win32 DebugM--------------------
コンパイル中...
T_FBX.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(1941) : error C2371: 'cerr' : 再定義されています。異なる基本型です。
        c:\program files\microsoft visual studio\vc98\include\iostream(19) : 'cerr' の宣言を確認してください。
nothing   FS_VER
  VC 6    200508
cl.exe の実行エラー

T_FBX.exe - エラー 1、警告 0

MFC を使用する方法に戻してエラー C2371
前に変更しているが,元に戻す方が良いのか?
そもそもこの部分を削除した方が良いか?
https://dev.mish.work/wordpress/2020/04/17/rc1047-c2679/


今回は i_define.hxx から次の部分を削除.

#ifdef	_MSC_VER
	#ifdef		_MFC_VER
	#else
		#ifndef	afxDump
		#define	afxDump		std::terr
		#endif
	#endif
#endif

必要があれば i_debug.hxx に追加する.

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

ドライブ名からリモート名に

ネットワークドライブ名から UNC での表現に変換するコード.

#include	<clocale>
#include	"i_trace.hxx"

//#include	<winnetwk.h>
#pragma		comment	(lib,"mpr.lib")

tstring	W_get_remote_name	(LPCTSTR path_)
{
	tstring	dpath = path_ ;
	if (dpath.size() < 2)		{	return	dpath ;		}
	tstring	drive = dpath.substr(0,2) ;
	tstring	_path = dpath.substr(2) ;
	tstring	remote_path ;
	if (drive.length() == 2) {
		if (drive[1] == _T(':')) {
			u_16	d_t  = ::GetDriveType(drive.c_str()) ;
			if (d_t == DRIVE_REMOTE) {
				DWORD	buf_size = MAX_PATH ;
				tstring	remote_name ;
				remote_name.resize(buf_size+1) ;
				::WNetGetConnection(drive.c_str(),&remote_name[0],&buf_size) ;
				if (!remote_name.empty()) {
					remote_path = remote_name.c_str() + _path ;
					}
				}
			}
		}
	if (remote_path.empty())	{	return	dpath ;		}
	return	remote_path ;
	}

bool	Test	(void)
{
	for (long index=0 ; index<26 ; index++)	{
		tstring	drv  ;
				drv += TCHAR(_T('A')+index) ;
				drv += _T(":\\") ;
	//	if (index%2 == 0)
		{
			u_16	d_t  = ::GetDriveType(drv.c_str()) ;
			if (d_t == DRIVE_REMOTE) {
				drv += _T("*.*") ;
				v_tstring	files = ::EnumFiles(drv.c_str()) ;
				if (files.size() > 0) {
					drv = files[0] ;
					}
				}
			}
		drv += _T("                                      ") ;
		tstring	info = drv.substr(0,20) + _T("\t") + W_get_remote_name(drv.c_str()) ;
		{
			std::tout << info << std::endl ;
			}
		}
	return	true ;
	}

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	{
		::Test() ;
		}
	return	0 ;
	}

WNetGetConnection と net use
net use 」とコマンド入力することで似た様なことを確認できる.


管理者で起動した PowerShell の Get-SmbConnection で SMB のバージョンを確認できる.
ファイル共有で使われている SMB のバージョンを見る
Get-SmbConnection


S_open_2024_04.zip

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

std::vector のコピーで実行時エラー

std::vector のデータ vf3a をコピーしようとして実行時エラー.

---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!
Program: c:\Temp\Test\T_gonsa\T_cmb_f\debug.080\T_cmb_f.exe
File: c:\program files (x86)\microsoft visual studio 8\vc\include\vector
Line: 741
Expression: vector subscript out of range
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
中止(A)   再試行(R)   無視(I)   
---------------------------

原因は vf3a のサイズが 0 .
std::vector のサイズが 0 で実行時エラー
vf3a.size() が 0 より大きい時のみコピーする様に変更しなければならない.


inline	v_u__8	To_v_u__8	(const Vf3A& vf3a)
{
	v_u__8	data ;
	{
		size_t	vCount = vf3a.size() ;
		u_16	vf3_size = u_16(sizeof(float)*3*vCount) ;
		data.resize(sizeof(u_16)+vf3_size) ;
		{
			::MemMove(&data[0],sizeof(u_16),&vCount,sizeof(u_16)) ;
			}
		if (vCount > 0) {
			::MemMove(&data[2],vf3_size,	&vf3a[0],vf3_size) ;
			}
		}
	return	data ;
	}
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

フォルダの更新日時の変更

今までファイルの更新日時の変更は使っていた.
https://www.vector.co.jp/soft/winnt/util/se500182.html
が,このツールでフォルダの更新日時を変更しようとするとできない.
コードは CFile::SetStatus を使用している.

	CFileStatus	fs ;
	CFile::GetStatus(file,fs) ;
	fs.m_mtime = newTime ;
	CFile::SetStatus(file,fs) ;

CFile::SetStatus の中(…\atlmfc\src\mfc\filest.cpp)を見ると ::SetFileTime を使用している.
また Linux などでも使える utime(…\crt\src\utime.c)も ::SetFileTime を使っている.
VC 6 で作成したものをデバッガで追いかけると ::CreateFile で 0xffffffff が返ってきている.


ASUSTOR NAS で試すと,特に問題なく変更できる.

Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $ cat t_utime.cpp
#include        <clocale>

#include        "i_trace.hxx"
#include        "filetime.hxx"
#include        "itls_tmp.hxx"
#include        "c_which.hxx"

int     _tmain  (int argc,TCHAR* argv[])
{
        _tsetlocale(LC_ALL,_T("")) ;
        {
                tstring temp_path = ::Get_i_Tools_tmp_date() ;
                tstring fold_path = ::Path_AddLastSP(temp_path) + ::Now_Format(_T("%H%M%S")) ;
                tstring file_path = ::Path_AddLastSP(temp_path) + ::Now_Format(_T("%H%M%S")) + _T(".tmp") ;
                {
                        ::Folder_Create   (fold_path) ;
                        ::File_CreateEmpty(file_path) ;
                        }
                {
                        time_t  f_time = ::File_GetMTime(file_path.c_str()) ;
                                f_time-= 3600*24*7 ;
                        ::File_SetMTime(file_path.c_str(),f_time) ;
                        ::File_SetMTime(fold_path.c_str(),f_time) ;
                        }
                {
                        tstring cmd     = tstring(cmd_ls_la) + _T(" ") + ::QuotM_Add_Auto(temp_path) ;
                        _tsystem(cmd.c_str()) ;
                        }
                }
        return  0 ;
        }
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $ g++ t_utime.cpp -Wall
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $ ll
total 136
drwxrwxrwx    2 Iwao     users       4.0K Nov  7 16:24 ./
drwxrwxrwx    3 Iwao     users       4.0K Nov  7 15:32 ../
-rwxr-xr-x    1 Iwao     users     122.7K Nov  7 16:24 a.out*
-rwxrwxrwx    1 Iwao     users        838 Nov  7 16:22 t_utime.cpp*
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $ ./a.out
total 0
drwxr-xr-x    3 Iwao     users           80 Nov  7 16:24 .
drwxr-xr-x    3 Iwao     users           60 Nov  7 16:24 ..
drwxr-xr-x    2 Iwao     users           40 Oct 31 16:24 162451
-rw-------    1 Iwao     users            0 Oct 31 16:24 162451.tmp
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $                                  

ASUSTOR NAS AS5202T 上で utime
今日はここまで.


2024/01/04
フォルダの更新日時の設定

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

C++ 継承でのエラー C2660

元々一つのクラスとしていたが,それを分割した時のエラー対応のメモ.

bool	D_Image::Draw	(HDC hdc,const RECT rect)
{
	if (GetDocPath().empty())		{	return	false ;		}
	{
		if (::Path_GetExtLow(GetDocPath()) == _T("emf")) {
			return	E_MetaF::Play(hdc,GetDocPath().c_str(),rect) ;
			}
		}
	if (HBMP == NULL && HICN == NULL) {
	//	...
		}
	if	(HBMP != NULL)	{	return	::Bitmap_Draw(hdc,rect,HBMP) ;	}
	else if	(HICN != NULL)	{	return	::Icon_Draw  (hdc,rect,HICN) ;	}
	return	false ;
	}
bool	D_Image::Draw	(HWND hwnd)
{
	if (GetDocPath().empty())		{	return	false ;		}
	if (hwnd == NULL)			{	return	false ;		}
	RECT	rect = {	0	} ;
	::GetClientRect(hwnd,&rect) ;
	bool	result = false ;
	{
		HDC		hdc  = ::GetDC(hwnd) ;
		result = Draw(hdc,rect) ;
		::ReleaseDC(hwnd,hdc) ;
		}
	return	result ;
	}

この E_MetaF::Play の部分を分離.

class	D_I_E	:	public		D_Image		{
public:
	virtual	bool	Draw		(HDC  hdc,const RECT rect)	{
		if (GetDocPath().empty())	{	return	false ;		}
		{
			if (::Path_GetExtLow(GetDocPath()) == _T("emf")) {
				return	E_MetaF::Play(hdc,GetDocPath().c_str(),rect) ;
				}
			}
		return	D_Image::Draw(hdc,rect) ;
		}
	} ;

この状態で変数の宣言を D_I_E として呼び出している所でエラー.

		Sel_doc.Draw(this->GetSafeHwnd()) ;
	//	Sel_doc.D_Image::Draw(this->GetSafeHwnd()) ;
--------------------構成: T_DImage - Win32 Debug--------------------
コンパイル中...
T_DI_Dlg.cpp
\\TestXP\Documents\Develop\VC_Test\Test\etc\EnhMetaF\T_DImage\T_DI_Dlg.cpp(186) : error C2660: 'Draw' : 関数が不正な 1 個の実引数をともなって呼び出されました。
cl.exe の実行エラー
T_DImage.exe - エラー 1、警告 0

下の様に修飾すれば通る.
また,D_I_E の関数として次のものを用意すれば D_Image:: の様に修飾しなくても大丈夫.

	virtual	bool	Draw		(HWND hwnd)	{
		return	D_Image::Draw(hwnd) ;
		}

変更の内容にもよるが,
なるべく既存のコード(呼び出している部分)の変更が最小限となる方が良いか?
C++ 継承でのエラー

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

構造体の初期化

幾つかの Windows API を呼び出す所を書き換えていて,
RECT や POINT の構造体の初期化で色々と気になり少し調べたことのまとめ.


class として書く場合は,コンストラクタで初期化しているので意識しない.

struct	Vector2	{
//	Vector2	()					{}
	Vector2	(T v=0)		: x(v),	y(v)		{}
	Vector2	(T x, T y)	: x(x),	y(y)		{}
//	...
	T	x ;
	T	y ;
	} ;

MFC を使用している時も同様.

	CRect	rect(0,0,0,0) ;

他の Win32 の構造体だと

	MEMORYSTATUSEX	memStat ;
	memset(&memStat,0,sizeof(MEMORYSTATUSEX)) ;
	memStat.dwLength= sizeof(MEMORYSTATUSEX) ;
	::GlobalMemoryStatusEx(&memStat) ;

Windows では ::ZeroMemory を使っていることもあり.

#define ZeroMemory(pb,cb)           memset((pb),0,(cb))

これまで RECT を 0 にする場合,次の様にも書いていた.

	RECT	rect = { 0,0,0,0 } ;

次の様に省略する方法もあるのは知っていたがあまり使っていない.

	RECT	rect = { 0 } ;

K & R 2nd の A8.7 に書かれている.
Web で検索すると ” RECT rect = { } ; ” の様な記述もあったが,これはどうかと…


構造体のコピーや戻り値は悩む所.
RECT の様な単純な構造では特に問題ないと思う.
XML などのツリー構造の場合はデータにより時間がかかるので注意が必要.


2020/10/13
次の様なコードで動作 を確認.

struct	strct_c	{
	i__8	i1 ;
	i_32	i4 ;
	i_16	i2 ;
	i_64	i8 ;
	} ;

bool	test_struct	(void)
{
	strct_a	sa_rn ;
	strct_b	sb_rn ;
	strct_c	sc_rn ;
	strct_a	sa_f0 = {1,2,3,4} ;
	strct_b	sb_f0 = {1,2,3,4} ;
	strct_c	sc_f0 = {1,2,3,4} ;
	strct_a	sa__0 = {0} ;
	strct_b	sb__0 = {0} ;
	strct_c	sc__0 = {0} ;
	strct_a	sa_m0 ;	memset(&sa_m0,0,sizeof(sa_m0)) ;
	strct_b	sb_m0 ;	memset(&sb_m0,0,sizeof(sb_m0)) ;
	strct_c	sc_m0 ;	memset(&sc_m0,0,sizeof(sc_m0)) ;
	::dump_mem(&sc_rn,sizeof(sc_rn)) ;
	::dump_mem(&sc_f0,sizeof(sc_f0)) ;
	::dump_mem(&sc__0,sizeof(sc__0)) ;
	::dump_mem(&sc_m0,sizeof(sc_m0)) ;
	return	true ;
	}

構造体の初期化 VC6
構造体の初期化 ASUSTOR NAS AS5202T
ある程度は予想通り…
パディング部分の扱いが異なるのでコードによっては注意が必要.

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

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.

Python から C の呼出し – 3

Win10 環境に入っている Python.h を検索.

C:\Users\Iwao> where /R \ Python.h
C:\CocosCreator\resources\utils\Python27\include\Python.h
C:\Microsoft\AndroidNDK64\android-ndk-r15c\prebuilt\windows-x86_64\include\python2.7\Python.h
C:\Microsoft\AndroidNDK64\android-ndk-r16b\prebuilt\windows-x86_64\include\python2.7\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\Python\Core\Packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\dll\python.h
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\Python\Core\Packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\linux\python.h
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\Microsoft\Python\Core\debugpy\_vendored\pydevd\pydevd_attach_to_process\common\python.h
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\Microsoft\Python\Miniconda\Miniconda3-x64\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pkgs\python-3.6.5-h0c2934d_0\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_86\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\include\Python.h
C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\prebuilt\windows-x86_64\include\python2.7\Python.h
C:\salt\bin\include\Python.h
C:\Users\All Users\Microsoft\AndroidNDK64\android-ndk-r11c\prebuilt\windows-x86_64\include\python2.7\Python.h
C:\Users\Iwao\AppData\Local\Microsoft\Linux\HeaderCache\1.0\-1863842710\usr\include\python2.7\Python.h
C:\Users\Iwao\AppData\Local\Microsoft\Linux\HeaderCache\1.0\-1863842710\usr\include\python3.7\Python.h
C:\Users\Iwao\AppData\Local\Microsoft\Linux\HeaderCache\1.0\-1863842710\usr\include\python3.7m\Python.h
C:\Windows.old\Users\All Users\Microsoft\AndroidNDK64\android-ndk-r11c\prebuilt\windows-x86_64\include\python2.7\Python.h

C:\Users\Iwao>  

Win10 環境の Python.h


https://jml.mish.work/python/call-c-python.html

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

Python から CPP の呼出し – 3

////////////////////////////////////////////////////////////////////
//	test_cpp.hpp
//
#pragma		once

#include	"_s_func.hxx"
#include	"_t_func.hxx"
#include	"_tdefine.hxx"

class	test_class	{
public:
			test_class	(LPCTSTR n)	{	name = n ;	std::tout<< name + _T("\t***") << std::endl ;	}
	virtual		~test_class	()      	{	          	std::tout<< name + _T("\t---") << std::endl ;	}
public:
	tstring		name ;
	} ;

inline	test_class*	get_test_class	(void)
{
	static	test_class	G_tc("G_test") ;
	return	&G_tc ;
	}

////////////////////////////////////////////////////////////////////
//	test_cpp.cpp
//
#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	test_class	tc(_T("local 1")) ;
	{
		test_class	tc(_T("local 2")) ;
		std::tout << _T("hello") << std::endl ;
		}
	{
		test_class*	gt = ::get_test_class() ;
		std::tout << gt->name << std::endl ;
		}
	return	0 ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ test_cpp.cpp -Wall
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ ./a.out
global  ***
local 1 ***
local 2 ***
hello
local 2 ---
G_test  ***
G_test
local 1 ---
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $
////////////////////////////////////////////////////////////////////
//	t_cpp.cpp
//
#include	<Python.h>

#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

static	PyObject*	local__	(PyObject* self, PyObject* args)
{
	test_class	tc(_T("local")) ;
	std::tout << tc.name << std::endl ;
	return	Py_None;
	}

static	PyObject*	global_	(PyObject* self, PyObject* args)
{
	test_class*	gt = ::get_test_class() ;
	std::tout << gt->name << std::endl ;
	return	Py_None;
	}

static	PyMethodDef			t_cpp_methods[] = {
	{	"local__",   	local__,	METH_NOARGS,	"local__"	},
	{	"global_",   	global_,	METH_NOARGS,	"global_"	},
	{	NULL								},
	} ;

static	struct	PyModuleDef	t_cpp = {
	PyModuleDef_HEAD_INIT,
	"t_cpp",
	"test cpp module",
	-1,
	t_cpp_methods
	} ;

PyMODINIT_FUNC	PyInit_t_cpp(void)
{
	return	PyModule_Create(&t_cpp) ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ t_cpp.cpp -Wall -fPIC -shared -o t_cpp.so -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import t_cpp
global  ***
>>> dir(t_cpp)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'global_', 'local__']
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test  ***
G_test
>>> t_cpp.global_()
G_test
>>> import t_cpp
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test
>>> exit()
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ 

Python から C++ 呼び出し時のコンストラクタ,デストラクタ

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

AS5202T Debian 10 と VC

VC で ASUSTOR NAS Linux Center の Debian 10 Desktop を使用するための設定.


SSH 接続を可能にして gcc などをインストールしておく必要がある.
Linux development with C++ in Visual Studio


VC の「ツール」-「オプション」,「クロスプラットフォーム」-「接続マネージャー」-「追加」.
Debian 10 への接続の設定
SSH 接続する時の情報を設定する.
追加後「接続マネージャー」-「リモートヘッダー…」で「更新」するとエラー.
エラーが発生しました。Could not start the ‘rsync’ command on the remote host, please install it using your system package manager. Please see https://aka.ms/AA23jat for troubleshooting。詳細については、C:\Users\Iwao\AppData\Local\Temp\vslinux_header_update_log.txt を参照してください。トラブルシューティングを行うには、https://aka.ms/AA23jat をご覧ください。
エラーが発生しました。Could not start the 'rsync' command on the remote host, please install it using your system package manager.
この部分の対応方法はよくわからない.


VC のプロジェクトの設定を「lxcdebian10」に.
VC リモートビルドマシンを「lxcdebian10」に設定


これでビルドすれば大丈夫なはずだが,何故かエラー.
VC を再起動したり,プロジェクトを読み直したりしていたら通る様になった.
AS5202T Debuan 10 VC ビルド

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

VS 2019 16.6 への更新で失敗

VS 2019 のアップデートがあったので,いつもの様に更新したら何故か失敗.
インストール動作の半分位の所でエラーになってしまった.
実際はアンインストールしてインストールとなるので,アンインストール中かも?


もう一度「スタート」-「Visual Studio Installer」を起動して更新.
「スタート」-「Visual Studio Installer」
一通りのインストールは終わって「再起動」.
VS 2019 インストール   PC 再起動
更新できたみたい.


VirtualBox に入れた Win10 IP の 2004 への更新.
何度か再起動後の 86% の所でエラーとなった.
Win10 IP  2004 への更新で失敗

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

std::fixed でアプリケーションエラー

先日やっていた計算式のコード.これをテストしていてエラーに.
エラーとなるコードの場所は数値を文字列に変換する所.
その部分だけを抜き出したコードは次の様なもの.

bool	test	(c_tstring& str_)
{
	tstring	str = str_ ;
	{
		TCHAR*	endPtr = 0 ;
		double	val = double(_tcstod(str.c_str(),&endPtr)) ;
							std::tout << std::fixed      << val << std::endl ;
	//	if (-1e50 < val && val < 1e50)	{	std::tout << std::fixed      << val << std::endl ;	}
	//	else				{	std::tout << std::scientific << val << std::endl ;	}
		}
	return	true ;
	}

1e300 などの値を std::fixed で表示すると,限られた環境でビルドした exe でエラーになる.
エラーが確認できたのは VC 6 で MFC を使用しないでビルドしたもの.
VC 6 でも DLL でリンクしている場合は,ランタイムの DLL のバージョンにより大丈夫.

Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/mba_20/chk_big $ c++ chk_big.cpp  -Wall
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/mba_20/chk_big $ ./a.out
value ? =1e10
10000000000.000000
value ? =1e100
10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104.000000
value ? =1e200
99999999999999996973312221251036165947450327545502362648241750950346848435554075534196338404706251868027512415973882408182135734368278484639385041047239877871023591066789981811181813306167128854888448.000000
value ? =1e300
1000000000000000052504760255204420248704468581108159154915854115511802457988908195786371375080447864043704443832883878176942523235360430575644792184786706982848387200926575803737830233794788090059368953234970799945081119038967640880074652742780142494579258788820056842838115669472196386865459400540160.000000
value ? =1e400
inf
value ? =1e307
9999999999999999860310597602564577717002641838126363875249660735883565852672743849064846414228960666786379280392654615393353172850252103336275952370615397010730691664689375178569039851073146339641623266071126720011020169553304018596457812688561947201171488461172921822139066929851282122002676667750021070848.000000
value ? =1e308
100000000000000001097906362944045541740492309677311846336810682903157585404911491537163328978494688899061249669721172515611590283743140088328307009198146046031271664502933027185697489699588559043338384466165001178426897626212945177628091195786707458122783970171784415105291802893207873272974885715430223118336.000000
value ? =1e309
inf
value ? =-1e100
-10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104.000000
value ? =-1e307
-9999999999999999860310597602564577717002641838126363875249660735883565852672743849064846414228960666786379280392654615393353172850252103336275952370615397010730691664689375178569039851073146339641623266071126720011020169553304018596457812688561947201171488461172921822139066929851282122002676667750021070848.000000
value ? =-1e308
-100000000000000001097906362944045541740492309677311846336810682903157585404911491537163328978494688899061249669721172515611590283743140088328307009198146046031271664502933027185697489699588559043338384466165001178426897626212945177628091195786707458122783970171784415105291802893207873272974885715430223118336.000000
value ? =-1e309
-inf
value ? =1.e-100
0.000000
value ? =1.e-300
0.000000

ASUSTOR NAS で大きな数値の表示

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

RC1047 , C2679

既存の VC 8 プロジェクトをビルドすると,うまくビルドできなくなっている.
https://itl.mydns.jp/i_Tools/Doc/blog/images/err_2004.txt

1>------ すべてのリビルド開始: プロジェクト: WatchPD, 構成: Debug Win32 ------
1>リソースをコンパイルしています...
1>fatal error RC1047: too many -I# options, 'c:\DP340XPP\D_Drive\Develop\Lib\InkSDK.C80\include'
1>プロジェクト : error PRJ0002 : エラーの結果 1 が 'C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin\rc.exe' より返されました。
1>WatchPD - エラー 1、警告 0

先日サーバ環境を変更(共通ソースを DevS から DevX に)したことによる影響.
その時簡単にはテストしたがメインのプロジェクトでは確認していなかった.
RC1047 の原因は,インクルードパスが長すぎるみたい.


もう一つのエラー.

1>------ ビルド開始: プロジェクト: PlnCtrl, 構成: Debug Win32 ------
1>ComUse06.cpp
1>\\devx\public\documents\develop\_.src\_yet\mouse.cxx(1819) : error C2679: 二項演算子 '<<' : 型 'const P2' の右オペランドを扱う演算子が見つかりません (または変換できません)。
1>        c:\program files (x86)\microsoft visual studio 8\vc\include\ostream(656): 'std::basic_ostream<_Elem,_Traits> &std::operator <<<wchar_t,std::char_traits<wchar_t>>(std::basic_ostream<_Elem,_Traits> &,const char *)' の可能性があります。
1>        with
1>        [
1>            _Elem=wchar_t,
1>            _Traits=std::char_traits<wchar_t>
1>        ]
1>

こっちは暫くわからなかった.
afxDump で検索すると 先日書いた記事 が引っ掛かり…
#define afxDump std::terr
これが有効になる条件が間違っていた.
_AFXDLL ではなく _MFC_VER で判断する必要があった.

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

LNK2005 すでに ~.obj で定義…

このエラーは,複数のソースファイルに同じ関数などが定義されている場合に発生します.
別の表現をすると,リンク対象の obj や lib に同じ定義が含まれているということです.


次の様な関数のエラーは,プロジェクトの設定に問題があることがあります.

nafxcwd.lib(afxmem.obj) : error LNK2005: “void * __cdecl operator new(unsigned int)” (??2@YAPAXI@Z) はすでに LIBCD.lib(new.obj) で定義されています

https://dev.mish.work/wordpress/?s=lnk2005


他に,自前のコードでヘッダファイルに関数の実体を定義した場合にも発生します.
その場合はソースファイルに移すか,inline 関数として定義します.
base64.hxx


以下は個人的なもので,ちょっと異なる使い方で発生した時の対応です.


以前,ソースファイルに定義していたテーブルをヘッダファイルに.

struct	CL_function	{
	LPCTSTR	Lower ;
	int	FType ;
	} ;

CL_function	CL_fnc_tbl[] =	{
	_T("atan2") ,	ATAN2	,
	//  ...
	_T(" ") ,	FERROR	,
	_T("\0") ,	FERROR	,
	} ;
--------------------構成: pf_20 - Win32 Debug--------------------
コンパイル中...
ComPrj01.cpp
コードを生成中...
コンパイル中...
ComUse02.cpp
pf_20.cpp
pf_20Dlg.cpp
コードを生成中...
リンク中...
ComUse02.obj : error LNK2005: "struct CL_function * CL_fnc_tbl" (?CL_fnc_tbl@@3PAUCL_function@@A) はすでに ComPrj01.obj で定義されています
pf_20.obj : error LNK2005: "struct CL_function * CL_fnc_tbl" (?CL_fnc_tbl@@3PAUCL_function@@A) はすでに ComPrj01.obj で定義されています
pf_20Dlg.obj : error LNK2005: "struct CL_function * CL_fnc_tbl" (?CL_fnc_tbl@@3PAUCL_function@@A) はすでに ComPrj01.obj で定義されています
pf_20.exe - エラー 3、警告 0

テーブルを cpp から hpp に移して LNK2005
次の様に static を付けて対応したが,ヘッダには static を書いてはいけない 様な記述が多い.

static	CL_function	CL_fnc_tbl[] =	{
	//  ...
	} ;
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

#pragma message (” ~ “) の利用

先日からやっているコードの解析部分を単体テスト用に分割していると,

--------------------構成: prs_frml - Win32 Debug--------------------
コンパイル中...
prs_frml.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afxv_w32.h(14) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>
cl.exe の実行エラー

prs_frml.exe - エラー 1、警告 0

「パッと見」でわかる時は良いが,今回はわかり難い.
そんな時に私が場所を限定していく手順.
次の様に影響していそうな所に #pragma message (” ~ “) を追加.

#pragma	 message ("pass 1")
#include "StrAryTo.hxx"
#pragma	 message ("pass 2")
#ifdef	 _MSC_VER
	 #ifdef	_AFXDLL
	 #else
		#ifndef	afxDump
		#define	afxDump	std::terr
		#endif
	 #endif
#endif
#pragma	 message ("pass 3")

エラーの場所を特定するために #pragma message を追加
今回は次の様になったので StrAyTo.hxx が原因とわかった.

pass 1
c:\program files\microsoft visual studio\vc98\mfc\include\afxv_w32.h(14) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

StrAryTo.hxx は CStringArray と std::vector<tstring> を相互変換するコード.
インクルードから外すことで対応.


MFC を使用しているソースなどの対応方法は次の所.
https://dev.mish.work/wordpress/2019/04/05/c1189-windows-h-already-included/

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