ホーム » 2021 » 6月

月別アーカイブ: 6月 2021

2021年6月
 12345
6789101112
13141516171819
20212223242526
27282930  

カテゴリー

アーカイブ

ブログ統計情報

  • 79,444 アクセス



C2535 , C2382

今まで特に問題なくビルドできていたプロジェクト.今月に入ってからは VC 2015 まででビルドしていた.

VC 2017
------ ビルド開始: プロジェクト: i3DV, 構成: Debug Win32 ------
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Platforms\Win32\PlatformToolsets\v141_xp\Toolset.targets(39,5): warning MSB8051: Windows XP をターゲットとするサポートは非推奨であり、Visual Studio の将来のリリースで提供されなくなります。詳細については、https://go.microsoft.com/fwlink/?linkid=2023588 をご覧ください。
ComGui03.cpp
OpGL.hxx                    Support
Dbg.hxx Auto server      No Support
c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\comip.h(152): error C2535: '_com_ptr_t<_IIID>::_com_ptr_t(int)': メンバー関数は、既に定義または宣言されています。
c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\comip.h(141): note: '_com_ptr_t<_IIID>::_com_ptr_t' の宣言を確認してください
c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\comip.h(938): note: コンパイル対象の クラス テンプレート インスタンス化 '_com_ptr_t<_IIID>' のリファレンスを確認してください
プロジェクト "i3DV141.vcxproj" のビルドが終了しました -- 失敗。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========
VC 2019
ビルドを開始しました...
------ ビルド開始: プロジェクト: i3DV, 構成: Debug Win32 ------
ComGui03.cpp
OpGL.hxx                    Support
Dbg.hxx Auto server      No Support
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(115,5): error C2382: '_com_ptr_t<_IIID>::_com_ptr_t': 再定義 ; 異なる例外指定です。
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(113): message : '_com_ptr_t<_IIID>::_com_ptr_t' の宣言を確認してください
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(1096): message : コンパイル対象の クラス テンプレート インスタンス化 '_com_ptr_t<_IIID>' のリファレンスを確認してください
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(381,10): error C2382: '_com_ptr_t<_IIID>::operator ==': 再定義 ; 異なる例外指定です。
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(371): message : '_com_ptr_t<_IIID>::operator ==' の宣言を確認してください
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(446,10): error C2382: '_com_ptr_t<_IIID>::operator !=': 再定義 ; 異なる例外指定です。
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(436): message : '_com_ptr_t<_IIID>::operator !=' の宣言を確認してください
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(511,10): error C2382: '_com_ptr_t<_IIID>::operator <': 再定義 ; 異なる例外指定です。
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(501): message : '_com_ptr_t<_IIID>::operator <' の宣言を確認してください
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(577,10): error C2382: '_com_ptr_t<_IIID>::operator >': 再定義 ; 異なる例外指定です。
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(566): message : '_com_ptr_t<_IIID>::operator >' の宣言を確認してください
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(643,10): error C2382: '_com_ptr_t<_IIID>::operator <=': 再定義 ; 異なる例外指定です。
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(633): message : '_com_ptr_t<_IIID>::operator <=' の宣言を確認してください
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(709,10): error C2382: '_com_ptr_t<_IIID>::operator >=': 再定義 ; 異なる例外指定です。
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\comip.h(699): message : '_com_ptr_t<_IIID>::operator >=' の宣言を確認してください
プロジェクト "i3DV142.vcxproj" のビルドが終了しました -- 失敗。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========

Win10 を 1909 から 20H2 に上げたのと,VS 2019 のアップデートがあった.
検索 をかけても,これといった情報には引っかからない.
となると,最近変更したコード?
nullptr を定義したことを思い出した.
#define nullptr NULL
VC 2015 以降では定義されない様に変更.
うまくいった.


nullptr は VC10 以降で使えるみたいで _MSC_VER < 1600 に変更.
https://ja.wikipedia.org/wiki/Microsoft_Visual_C++

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

C2664

スタックを使用した次の様なコード.

	stack_s	so ;

エラー情報を指定する様に変更してビルド.

	i_error	ie ;
	stack_s	so(&ie) ;
--------------------Configuration: t_stack - Win32 Debug--------------------
Compiling...
t_stack.cpp
d:\document\vs\vs\1998\t_stack\t_stack\t_stack.cpp(14) : error C2664: '__thiscall stack_s::stack_s(const class stack_s &)' : cannot convert parameter 1 from 'class i_error *' to 'const class stack_s &'
        Reason: cannot convert from 'class i_error *' to 'const class stack_s'
        No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.

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

C2664 になってしまう.

class	stack_b	{
public:
		stack_b		(i_error* i_err=NULL)	{	ie = &tmp_ie ;	if(i_err != NULL) {	ie = i_err ;	}	}
protected:
	i_error		tmp_ie ;
	i_error*	ie ;
	} ;

class	stack_s	:	public	stack_b	{
public:
//		stack_s		(i_error* i_err=NULL)	:	stack_b	(i_err)		{	;	}
public:
	virtual	bool	push	(c_tstring& s) ;
	virtual	tstring	pop 	(void) ;
	virtual	tstring	last	(void) ;
protected:
	s_tstring	stck_s ;
	} ;

コメントにしている stack_s のコンストラクタを追加すれば OK .
C2664  stack
独習 C++ 7.3 223 ページ

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

SHBrowseForFolder

今度はフォルダの参照.
ダイアログを表示するだけの最低限のコード.

#include	<ShlObj.h>

bool	Test	(void)
{
	BROWSEINFO	bi	=	{	0	} ;
	LPITEMIDLIST	pidl	= ::SHBrowseForFolder(&bi) ;
	if (pidl == NULL)	{	return	false ;		}
	::CoTaskMemFree(pidl) ;
	return	true ;
	}

int	main	(void)
{
	while	(true)	{
		if (!Test()) {
			break ;
			}
		}
	return	0 ;
	}

SHBrowseForFolder VC 6
SHBrowseForFolder hwndOwner のみ指定
BROWSEINFO の hwndOwner も指定していないので動作がモードレスになってしまう.


SHBrowseForFolder のドキュメントを見ると IFileDialog FOS_PICKFOLDERS とある.


選択したフォルダ名を戻すように変更.

tstring	SH_GetPathFromIDList	(LPCITEMIDLIST pidl)
{
	tstring	path ;
	path.resize(MAX_PATH+10) ;
	BOOL	result = ::SHGetPathFromIDList(pidl,&path[0]) ;
	return	path.c_str() ;
	}

tstring	Test	(void)
{
	BROWSEINFO	bi	 =	{	0	} ;
	bi.ulFlags		|=	BIF_RETURNONLYFSDIRS ;
	bi.ulFlags		|=	BIF_NEWDIALOGSTYLE ;
	bi.ulFlags		|=	BIF_NONEWFOLDERBUTTON ;
	LPITEMIDLIST	pidl	 = 	::SHBrowseForFolder(&bi) ;
	if (pidl == NULL)	{	return	tstring() ;		}
	tstring	path = ::SH_GetPathFromIDList(pidl) ;
	::CoTaskMemFree(pidl) ;
	return	path ;
	}

pszDisplayName を指定すると,選択されたフォルダ名が返る.

	tstring		disp_name ;
	disp_name.resize(MAX_PATH) ;
	bi.pszDisplayName	 =	&disp_name[0] ;
//	...	SHBrowseForFolde
	std::tout << disp_name.c_str() << std::endl ;

初期フォルダ指定の追加.

int	CALLBACK	SH_BrowseCallback	(HWND hwnd,UINT uMsg,LPARAM lParam,LPARAM lpData)
{
	switch	(uMsg) {
		case	BFFM_INITIALIZED :
			::SendMessage(hwnd,BFFM_SETSELECTION,1,(LPARAM)(LPCTSTR)lpData) ;
			return	1 ;
			break ;
		default :
			return	0 ;
			break ;
		}
	return	0 ;
	}

{
//	...
	tstring		init_fold = init_fold_ ;
//	...
	bi.lpfn			 =	SH_BrowseCallback ;
	bi.lParam		 =	(LPARAM)init_fold.c_str() ;
	LPITEMIDLIST	pidl	 = ::SHBrowseForFolder(&bi) ;
//	...
	}

S_Browse.hxx
::Browse_Folder

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

Win10 に VS 6 インストール

今まで仮想マシンの WinXP で VC 6 を使用してきたが,ちょっと面倒なので Win10 環境に入れてみた.
使用したのは次の ISO .
en_visual_studio_6.0_professional_x86_dvd_224df581.iso
2021/04 に VS のダウンロードサイトで見つけた.
その時 Win7 環境などにインストールして動作することは確認済み.
Win7 に VS 6


インストール時,データベース関連を入れると止まると書かれていたので,外してインストール.
VB6開発環境をWindows 10にインストールする手順


VC 6 を簡単に確認した限りは何とか使えそう.


Win11 に VS 6 のインストール
Win11 22H2(デバッグできない時の設定も書いています)

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

DS file にログインできない

先日までうまく使えていた DS file にログインできなくなってしまった.
DS file ログインできない


最近 Synology NAS に加えた変更は Synology Calendar を削除したこと.
その時一緒に WebDAV Server も削除した.
どうもこれがいけなかったみたい.
Synology NAS WebDAV Server
インストールして「実行」することでうまく動作する様になった.


2021/09
DSM 7 に更新してログインできなくなった場合は,DSM にログインする時と同様のポート番号を指定する.
DSM  7  DS file ログイン

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

OPENFILENAME

コンソール AP では,標準入力を使用していた.

#include	"quotm.hxx"
#include	"existff.hxx"

inline	bool	Test	(void)
{
	while(true)	{
		tstring	str ;
		{
			tstring	buf ;
			buf.resize(1000) ;
			std::terr << _T("file ...=") ;
			std::tin.getline(&buf[0],std::streamsize(buf.size())) ;
			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 << str << std::endl ;
			}
		}
	return	true ;
	}

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

以前作成した CFileDialog を使用したもの.

#include	<afxwin.h>
#include	"F_Dialog.hxx"
#include	"quotm.hxx"

inline	bool	Test	(void)
{
	while(true)	{
		tstring	str ;
		{
			str = ::FD_GetOpenFile(_T("./")) ;
			if (str.empty())   		{	break ;		}
			}
		{
			if (::File_IsNothing(str))	{	continue ;	}
			std::tout << str << std::endl ;
			}
		}
	return	true ;
	}

CWinApp theApp;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
		std::terr << _T("error : AfxWinInit") << std::endl ;
		nRetCode = 1;
		}
	else  {
		Test() ;
		}
	return nRetCode;
	}

////////////////////////////////////////////////////////////////////////////////////////

#include	<AfxExt.h>
#include	"BrowseFF.cxx"

「開く」ダイアログを表示するだけのコード.

{
	OPENFILENAME	ofn =	{	0	} ;
	ofn.lStructSize = sizeof(OPENFILENAME) ;
	if (!::GetOpenFileName(&ofn))	{	return	tstring() ;	}
//	...
	}

OPENFILENAME の指定が複雑なので,使いそうな内容でまとめてみた.

OPENFILENAME
lStructSize sizeof(OPENFILENAME)
hwndOwner NULL の時,モードレスになる.
CFileDialog では DoModal で求めている.
lpstrFile 選択されたファイル名が入る.
OFN_ALLOWMULTISELECT の場合は,下のメモリイメージ.
nMaxFile lpstrFile で確保している領域の文字数

OFN_ALLOWMULTISELECT の場合の結果の lpstrFile .

0x02C00078  44 3a 5c 44 6f 63 75 6d 65 6e 74 5c 56 53 5c 56  D:\Document\VS\V
0x02C00088  53 5c 32 30 30 35 5c 54 5f 4f 70 65 6e 46 5c 54  S\2005\T_OpenF\T
0x02C00098  5f 4f 46 5f 4d 46 43    54 5f 4f 46 5f 4d 46 43  _OF_MFC.T_OF_MFC
0x02C000A8  2e 42 41 4b    54 5f 4f 46 5f 4d 46 43 2e 63 70  .BAK.T_OF_MFC.cp
0x02C000B8  70    54 5f 4f 46 5f 4d 46 43 2e 76 63 70 72 6f  p.T_OF_MFC.vcpro
0x02C000C8  6a    54 5f 4f 46 5f 4d 46 43 2e 76 63 70 72 6f  j.T_OF_MFC.vcpro
0x02C000D8  6a 2e 5a 31 37 30 53 30 2e 49 77 61 6f 2e 75 73  j.Z170S0.Iwao.us
0x02C000E8  65 72       00 00 00 00 00 00 00 00 00 00 00 00  er..............

0x027E6B50  44 00 3a 00 5c 00 44 00 6f 00 63 00 75 00 6d 00 65 00 6e 00 74 00 5c 00 56 00 53 00 5c 00 56 00  D:\Document\VS\V
0x027E6B70  53 00 5c 00 32 00 30 00 30 00 35 00 5c 00 54 00 5f 00 4f 00 70 00 65 00 6e 00 46 00 5c 00 54 00  S\2005\T_OpenF\T
0x027E6B90  5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00 00 00 54 00 5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00  _OF_MFC.T_OF_MFC
0x027E6BB0  2e 00 42 00 41 00 4b 00 00 00 54 00 5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00 2e 00 63 00 70 00  .BAK.T_OF_MFC.cp
0x027E6BD0  70 00 00 00 54 00 5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00 2e 00 76 00 63 00 70 00 72 00 6f 00  p.T_OF_MFC.vcpro
0x027E6BF0  6a 00 00 00 54 00 5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00 2e 00 76 00 63 00 70 00 72 00 6f 00  j.T_OF_MFC.vcpro
0x027E6C10  6a 00 2e 00 5a 00 31 00 37 00 30 00 53 00 30 00 2e 00 49 00 77 00 61 00 6f 00 2e 00 75 00 73 00  j.Z170S0.Iwao.us
0x027E6C30  65 00 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  er..............

lpstrFile	0x02c10078 "D:\Document\VS\VS\2005\T_OpenF\T_OF_MFC\ReadMe.txt"	char *

デバッガで OPENFILENAME_SIZE_VERSION_400 となる様にしたもの.
OPENFILENAME_SIZE_VERSION_400


MFC 9 で bVistaStyle を FALSE とすると
CFileDialog bVistaStyle == FALSE
VC 8 exe と同様の,左側がフォルダツリーではない表示のもの.
デフォルトの TRUE だと
CFileDialog bVistaStyle == TRUE
COM を利用したもの?
Common Item Dialog


今度は MFC を使用しない方法.
::GetOpenFileName を使用する方法で OFN_ALLOWMULTISELECT を指定すると実行されなかった.
見た目のエラーにはならない?が,API を呼んで FALSE で抜けてくる.
::CommDlgExtendedError で調べると FNERR_INVALIDFILENAME だった.
存在しないファイル名などを与えるとうまくないみたい.
まだ何か足りないみたいで Win3.x 頃の表示になってしまった.
GetOpenFileName  Win3.x
選択したファイル名などもスペースで区切られている.
OFN_ALLOWMULTISELECT を指定する時は OFN_EXPLORER も指定する必要があるみたい.
次の所に書かれていた.
OPENFILENAMEW structure (commdlg.h)
OFN_ALLOWMULTISELECT | OFN_EXPLORER の場合 lpstrFile に存在しないファイル名でも問題なさそう.


複数選択可能な「開く」ダイアログのコードは次の様な感じ.

tstring	GetOpenFile	(LPCTSTR default_name=_T("./"))
{
	HWND	hwnd = ::GetConsoleHwnd() ;
	tstring	str_file = default_name ;
	    	str_file.resize(260*100) ;
	OPENFILENAME	ofn =	{	0	} ;
	{
		ofn.lStructSize	= sizeof(OPENFILENAME) ;
		ofn.hwndOwner	= hwnd ;
		ofn.nMaxFile	= DWORD(str_file.size()) ;
		ofn.lpstrFile	= &str_file[0] ;
		ofn.Flags   	= OFN_ALLOWMULTISELECT | OFN_EXPLORER | OFN_HIDEREADONLY ;
		}
	if (!::GetOpenFileName(&ofn)) {
		DWORD	err = ::CommDlgExtendedError() ;
		std::terr << ::To_tstring(u_32(err),16) << std::endl ;
		return	tstring() ;
		}
	tstring	sel_file ;
	{
		sel_file = ofn.lpstrFile ;
	//	...
		}
	return	sel_file ;
	}

拡張子のフィルタなどは指定していない.また,選択されたファイルを取得するコードもこれから.


選択されたファイルを取得するコード.

tstring	String_Change	(c_tstring& str_,const TCHAR src,const TCHAR dst)
{
	tstring	str = str_ ;
	for (size_t index=0 ; index<str.size() ; index++) {
		TCHAR	ch = str[index] ;
		if (ch == src) {
			str[index] = dst ;
			}
		}
	return	str ;
	}

	tstring	sel_file ;
	{
		sel_file = ofn.lpstrFile ;
		sel_file = str_file ;
		sel_file = ::String_Change(ofn.lpstrFile,_T('\x0'),_T('\n')) ;
		sel_file = ::String_Change(str_file,     _T('\x0'),_T('\n')) ;
		sel_file = ::String_TrimBoth(sel_file) ;
		}

ofn.lpstrFile は ASCIIZ となってしまうので,str_file をそのまま使用する必要がある.
Win3.x 形式の lpstrFile のダンプ.

0x02311F00  0043 003a 005c 0055 0053 0045 0052 0053 005c 0050 0055 0042 004c 0049 0043 005c  C.:.\.U.S.E.R.S.\.P.U.B.L.I.C.\.
0x02311F20  0044 004f 0043 0055 004d 0045 004e 0054 0053 005c 0020 0042 0061 0063 006b 0043  D.O.C.U.M.E.N.T.S.\. .B.a.c.k.C.
0x02311F40  0050 002e 0062 0061 0074 002e 006c 006e 006b 0020 0057 0049 004e 0031 0030 002d  P...b.a.t...l.n.k. .W.I.N.1.0.-.
0x02311F60  007e 0031 002e 004c 004e 004b 0020 005a 0031 0037 0030 0044 004f 007e 0031 002e  ~.1...L.N.K. .Z.1.7.0.D.O.~.1...
0x02311F80  004c 004e 004b 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  L.N.K...........................

区切りがスペースになるため,ファイル名などにスペースが含まれている場合は 8.3 形式 になる.


lpstrFilter を指定.

	tstring	filter ;
		filter	+= _T("Executable Files (*.exe)|*.exe|") ;
		filter	+= _T("All Files (*.*)|*.*|") ;
		filter	+= _T("|") ;
		filter   = ::String_Change(filter,_T('|'),_T('\x0')) ;
	OPENFILENAME	ofn =	{	0	} ;
	{
		ofn.lStructSize	= sizeof(OPENFILENAME) ;
	//	...
		ofn.lpstrFilter	= &filter[0] ;
		}

ここまでのものを WinXP 環境で表示すると
GetOpenFileName WinXP


WFDialog.hxx

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

コンソール AP のウィンドウハンドル

GetOpenFileName を調べていて,コンソール AP のウィンドウハンドルが必要になった.
ofn.hwndOwner の NULL の指定では,モードレスの動作になってしまう.
CFileDialog は DoModal 内で設定していて,通常の AP であればうまく動作する様になっている.
CFileDialog DoModal hwndOwner
コンソール AP ウィンドウハンドル」で検索すると次のものがあった.
How to obtain a Console Window Handle (HWND)
そこにあったサンプルを,関数として抜き出し.
con_wnd.hxx


2023/08/02
2023/03 に ::GetConsoleWindow を使用したので,その関連のまとめ.
VC 7 以降,WinCon.h に ::GetConsoleWindow が追加されている.
VC 7 WinCon.h  ::GetConsoleWindow
それで,con_wnd.h では,VC 6 やそれ以降のものでもうまく通る様に変更している.

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