ホーム » 2017 » 3月

月別アーカイブ: 3月 2017

2017年3月
 1234
567891011
12131415161718
19202122232425
262728293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,386 アクセス



コンソール AP で MFC

コンソール AP で,MFC(AfxWin.h など)に依存したコードを利用


新しく書いたものは,次の様なコードで可能.

  #include	"EnhMetaF.hxx"
  #include	"i_trace.hxx"
  
  int _tmain(int argc, TCHAR* argv[])
  {
    	_tsetlocale(LC_ALL,_T("")) ;
    	{
      		EnhMetaF	emf ;
      		CMetaFileDC*	mfdc = emf.GetDC() ;
      		mfdc->Rectangle(10,10,30,20) ;
    		}
    	return 0 ;
    	}

古いコードは,うまく対応できてないので…

  #undef  	_CONSOLE
  #include	<AfxWin.h>
  #include	<AfxExt.h>
  #include	<AfxCmn.h>
  #ifdef	_WIN32
  #define  	_WINDOWS
  #endif
  #include	"MessCon.hxx"
  #include	"MessBar.hxx"
  #ifdef	MessageBar
    #undef	MessageBar
    #define	MessageBar	MessageCon
    #undef	I_SUPPORT_MESSAGE_MFC
  #endif
  #include	"MessWrap.hxx"
  // ...
  int _tmain(int argc, TCHAR* argv[])
  {
    	#ifdef	_MFC_VER
    	if (!::AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0)) {
      		return	1 ;
      		}
    	#else
    	_tsetlocale(LC_ALL,_T("")) ;
    	#endif
    //	...
    	}

undef の幾つかは,自コードの対応のために必要.

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

ubuntu 環境の再設定

mac 上の仮想マシンに入れた ubuntu
暫く使ってなかったので,LAN 環境などが当時の古いまま.
ubuntu は昨日更新して 16.04 LTS .
外にアクセスするルートは DHCP が使えるが,もう一つの LAN はDHCP サーバがない.
Win PC や mac からは特に問題なく使えてたが,ubuntu は安定しない?
IP を固定することで対応.
「接続を編集する…」-「編集」-「IPv4設定」で,169.254.xx.xx ,255.255.0.0 と指定.


WSS,WD Cloud,DS115j などにアクセス可能となった.
IIS など Web サーバは,IP でないと接続できないものもあり.

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

Xcode include

MFC や Windows に依存しないコードのテスト.
今 mac に入っているのは,Xcode Version 6.4.


Project Navigator で,対象のプロジェクトを選択.
検索の所に Search と入力して絞り込み.
Header Search Paths の /Applications/… となっている所をダブルクリック.
「+」で,/Users/Iwao/Public/Dropbox/Develop/_.SRC/__CPR_ などを追加.


VC では,「アクティブプロジェクトに設定」や「スタートアッププロジェクトの設定」にあたるもの.
ビルドや実行対象の変更は,メニューの「Product」-「Scheme」にある.
 以前と変わった?

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

EnumFilesTree で無限ループ

フォルダ以下の全てのファイルを列挙する関数

v_tstring	EnumFilesTree	(LPCTSTR path)
{
	v_tstring	foundFiles = ::EnumFiles(path) ;
	v_tstring	foundFolds = ::ExtractFolders(foundFiles) ;
	for (size_t index=0 ; index<foundFolds.size() ; index++) {
		tstring		subFold = foundFolds[index] ;
		v_tstring	chFiles = ::EnumFiles(subFold.c_str()) ;
		v_tstring	chFolds = ::ExtractFolders(chFiles) ;
		foundFolds.insert(foundFolds.end(),chFolds.begin(),chFolds.end()) ;
		foundFiles.insert(foundFiles.end(),chFiles.begin(),chFiles.end()) ;
		}
	return	foundFiles ;
	}

今まで特に問題なく動作していたが,
先週末 VC 14 i3DV のデバッグ版を実行すると無限ループに.
Release 版や,VC 12 のデバッグ版などでは OK .


昨日は,別の PC 環境だったため再現せず.


今日デバッガを使用して調査すると,
 フォルダの「作成日時」が正しくない.
 /wordpress/dev/2016/09/15/
そのため,_wstat64 が正しく帰ってこない.


v_tstring	EnumFiles	(LPCTSTR path_,const bool skipDot=true)
{
	tstring	path = ::Path_DelLastSP(path_) ;
	if (!File_IsDirectory(path.c_str()))	{
		path = ::Path_GetDir(path) ;
		}
	v_tstring	foundFiles ;
	#if		defined	__GNUC__
		foundFiles = ::EnumFiles_GNUC	(path,skipDot) ;
	#elif	defined	_MFC_VER
		foundFiles = ::EnumFiles_MFC	(path,skipDot) ;
	#elif	defined	_MSC_VER
		foundFiles = ::EnumFiles_MSC	(path,skipDot) ;
	#endif
	return	foundFiles ;
	}

ここの,File_IsDirectory(…) で,stat を利用している.


次の様に ::GetFileAttributes(…) の判断を追加.

	if (!::File_IsDirectory(path.c_str()))	{
		#if	(_MSC_VER == 1900)
		{
			if (!::FA_Is_Directory(path)) {
				path = ::Path_GetDir(path) ;
				}
			}
		#else
		{
			path = ::Path_GetDir(path) ;
			}
		#endif
		}

enumfile.hxx

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

CString , tstring

typedef std::basic_string  <TCHAR,std::char_traits<TCHAR>,std::allocator<TCHAR> >  tstring ;

CString tstring
Left (count) substr (0,count)
Mid (first) substr (first)
Mid (first,count) substr (first,count)
Right (count)
IsEmpty empty
Empty clear

CString , std::string , …
tstring.hxx

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

vector 要素の削除

MSDN vector::erase
MFC の CArray::RemoveAt(index,count=1)
 先頭要素の削除
  v1.erase( v1.begin( ) );
 [1] の削除
  v1.erase( v1.begin( )+1 );

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

VC 6 getline

先日のキー入力の動作を c++ で書き直し.
 while (_ftprintf(stderr,_T(“%s=”),_T(“入力?”)) ,
  _fgetts(buf,sizeof(buf),stdin) != NULL) { … }


最初次の様にしたが,
 while (std::terr << _T(“入力?=”) ,
  std::getline(std::tin,buf))
buf に一つずれて入ってくる.
次の方法では OK.
 while (std::terr << _T(“入力?=”) ,
  std::tin.getline(&buf[0],buf.size()))


VC 6 の問題の様で,VC 7 以降では上の方法で動作する.

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

コンマ演算子

古いデバッグ用のコードを見ていたら,こんなのがあった.
 while (_ftprintf(stderr,_T(“%s=”),_T(“入力してください”)) ,
  _fgetts(buf,sizeof(buf),stdin) != NULL) { … }


最近あまりこの様なコードを書くことがなく忘れていた.
 while の条件式の括弧の中に複数の文.コンマで区切られている.
 for ではインクリメントなどの変化式で使う.


MSDN コンマ演算子: ,
 次の様にすると,i には c が代入されるらしい.
   i = ( b , c ) ;
 括弧がないと b .
   i = b , c ;


MSDN コンマ演算子 (,) (JavaScript)
JavaScript でも同じ様な動作なら,今やっている所で使えそう.

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