ホーム » MFC (ページ 4)

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

2024年5月
 1234
567891011
12131415161718
19202122232425
262728293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 81,522 アクセス



SDI exe で変換後ドキュメントを開く

SDI exe で,変換後のデータをそのまま開きたかった.
OnOpenDocument で開くことは可能だが,幾つかうまくない所がある.
CDocument の OnOpenDocument 前後の動作をデバッガで追いかけると,ビューの初期化が足りない.
CView* を求めて OnInitialUpdate で対応.

void CX__Doc::OnConvert() 
{
	if (GetPathName().IsEmpty())	{	return	;	}
	tstring	new_name ;
	{
	//	...
		::G3_to_NEW(...,new_name.c_str()) ;
		}
	{
		OnNewDocument () ;
		OnOpenDocument(new_name.c_str()) ;
		SetPathName   (new_name.c_str()) ;
		{
			CFrameWnd*	frame = (CFrameWnd*)AfxGetMainWnd() ;
			if (frame != NULL) {
				CView*	view = frame->GetActiveView() ;
				if (view != NULL) {
					view->OnInitialUpdate() ;
					}
				}
			}
		}
	}

MFC 変換直後にドキュメントを開く

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

error C1189: #error: Please use /MD

プロジェクトの設定で「スタティック ライブラリで MFC を使用する」から「共有 DLL で MFC を使う」に変更すると,次のエラーになることがある.
—— ビルド開始: プロジェクト: MkCmf, 構成: Release Win32 ——
StdAfx.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.22.27905\atlmfc\include\afxver_.h(77,1): error C1189: #error: Please use the /MD switch for _AFXDLL builds
プロジェクト “MkCmf142.vcxproj” のビルドが終了しました — 失敗。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========


対応方法はエラーメッセージにある様に
「マルチスレッド(/MT)」から「マルチスレッド DLL(/MD)」に変更する.
ランタイムライブラリの設定を「マルチスレッド DLL(/MD)」に変更する


同様に「共有 DLL で MFC を使う」から「スタティック ライブラリで MFC を使用する」に変更した場合.
—— ビルド開始: プロジェクト: AsHVR, 構成: Release Win32 ——
StdAfx.cpp
c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\atlmfc\include\afx.h(24): fatal error C1189: #error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
プロジェクト “AsHVR142.vcxproj” のビルドが終了しました — 失敗。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========
この場合は「マルチスレッド(/MT)」に変更する.


2021/04/01
それぞれの設定に対応するには「<親またはプロジェクトの既定値から継承>」とすれば良さそう.


次のエラーの場合はこちら
fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>

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

Win10 に入っている MFC*.dll

MFC の DLL に関して調べていて,
Win10 では幾つかの MFC DLL がインストールされているという記述を見つけたので調べてみました.


VirtualBox で仮想環境を作成して,Win10 Pro 1903 をインストール.
Win10 Pro 1903
インストールされているものは仮想マシン用のツール.
Win10 Pro プログラムと機能
このような環境で C ドライブを mfc*.dll で検索すると,見つかるのは前から存在するもの.
mfc40.dll mfc40u.dll mfc42.dll mfc42u.dll
Win10 Pro  mfc*.dll で検索した結果
Win10 のバージョンによるのかどうかわかりませんが,
OS のみのインストール状態では mfc140u.dll は入っていないようです.


私の方で MFC dll をダウンロードするページへのリンクをまとめています.
http://i_tools.mish.work/2017/05/
https://jml.mish.work/index.php/cpp/ref-vcredist-xxx-exe.html


2019/06/15
msvc???.dll などは入っていたのでその画面コピーです.
msvcr???.dll
msvcp???.dll
msvc????.dll
msvc????.dll バージョンでソート 1
msvc????.dll バージョンでソート 2


2022/10/06
Win11 に入っている MFC*.DLL

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

C1189 : WINDOWS.H already …

幾つかの,MFC を使用していないプロジェクトをビルドしていると,

--------------------構成: GAtoSTL - Win32 Release--------------------
コンパイル中...
GAtoSTL.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 の実行エラー

GAtoSTL.obj - エラー 1、警告 0

MFC アプリでは windows.h をインクルードしてはいけないというエラー.
最近(2019/03)変更したコードで,意図せず Afx.h などを利用するようになってしまった所があると思われる.
今回の場合,デバッグ版や Linux 環境,VC 14 などでは通っている.


次の様な内容を include している部分に挿入して確認すると,
 #pragma message (“message 1”)
Zip.hxx がうまくない.

#ifndef		I_SUPPORT_ZIP			//	ここは個人的なコードです
	#ifdef	_DEBUG
		#include	"i_Zip.hxx"	//	STL と Windows.h
	#else
		#include	"a_Zip.hxx"	//	AfxDisp などを使用
	#endif
#endif

a_Zip.hxx は zip を扱う古い形式(MFC を使用している)のもの.
i_Zip.hxx は MFC を使用しないように変更したもの.
a_Zip.hxx を使用しないように変更.


2019/08/26 追加
このエラーが表示される原因は,
MFC 関連の afx*.h がインクルードされる前に Windows.h が読み込まれているため.
MFC を使用しているプロジェクトで StdAfx.h を使用してない場合は,
ソース内のヘッダのインクルードで最初に #include <afxwin.h> などとすれば良い.
#include <afxwin.h>
2020/02/14
それから,作成したヘッダファイル内では Afx*.h のインクルードはしない方が良さそう.
https://dev.mish.work/wordpress/2020/02/08/lnk2005-operator-delete/


次のエラーの場合はこちら
error C1189: #error: Please use the /MD switch for _AFXDLL builds
fatal error C1189: #error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]


2020/10
コンソール AP で Windows.h を使用する時の hxx を用意した.
コンソール AP での define
_AFXDLL で判断しているため 「MFC のスタティックライブラリを使用」には対応できない


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

ファイルの検索

あるフォルダ内のファイルを列挙するコード 

MFC
v_tstring	EnumFiles_MFC	(c_tstring& path,const bool skipDot=true)
{
	v_tstring	foundFiles ;
	{
		iFileFind	ff ;
		BOOL		isWorking = ff.FindFile((::Path_AddLastSP(path)+_T("*.*")).c_str()) ;
		while	(isWorking)	{
			 	isWorking = ff.FindNextFile() ;
			if (skipDot && ff.IsDots()) {	continue ;	}
			tstring	fileName = ff.GetFileName() ;
			if (ff.IsDirectory()) {
				fileName = ::Path_AddLastSP(fileName) ;
				}
			foundFiles.push_back(::Path_AddLastSP(path)+fileName) ;
			}
		}
	return	foundFiles ;
	}

MSC
v_tstring	EnumFiles_MSC	(c_tstring& path,const bool skipDot=true)
{
	v_tstring	foundFiles ;
	{
		tstring	fffPath = ::Path_AddLastSP(path)+_T("*.*") ;
		WIN32_FIND_DATA	fd ;
		memset(&fd,0,sizeof(WIN32_FIND_DATA)) ;
		HANDLE	hFind = ::FindFirstFile(fffPath.c_str(),&fd) ;
		if (hFind != INVALID_HANDLE_VALUE) {
			while	(TRUE)	{
				tstring	fileName = fd.cFileName ;
				if (skipDot) {
					if (fileName == _T("."))   {	fileName = _T("") ;	}
					if (fileName == _T(".."))  {	fileName = _T("") ;	}
					}
				if (!fileName.empty()) {
					if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
						fileName = ::Path_AddLastSP(fileName) ;
						}
					foundFiles.push_back(::Path_AddLastSP(path)+fileName) ;
					}
				if (!::FindNextFile(hFind,&fd)) {
					break ;
					}
				}
			::FindClose(hFind) ;
			}
		}
	return	foundFiles ;
	}

GNUC
v_tstring	EnumFiles_GNUC	(c_tstring& path_,const bool skipDot=true)
{
	tstring 	path = path_ ;
	v_tstring	foundFiles ;
	{
		DIR*	dp = ::opendir(path.c_str()) ;
		struct	dirent*	dent = NULL ;
		do	{
			dent = readdir(dp) ;
			if (dent != NULL)	{
				tstring	fileName = dent->d_name ;
				if (skipDot) {
					if (fileName == _T("."))   {	continue ;	}
					if (fileName == _T(".."))  {	continue ;	}
					}
				if (dent->d_type & DT_DIR) {
					fileName = ::Path_AddLastSP(fileName) ;
					}
				foundFiles.push_back(::Path_AddLastSP(path)+fileName) ;
				}
			}	while (dent != NULL) ;
		::closedir(dp) ;
		}
	return	foundFiles ;
	}

MFC 版で,iFileFind としているのは,VC 6 MFC MBCS 版でのバグのため.

class	iFileFind	:	public	CFileFind	{
	public:
		virtual	CString GetFilePath() const	{
			ASSERT(m_hContext != NULL);
			ASSERT_VALID(this);
			CString strResult = m_strRoot;
			#ifdef	____VC_6_______MBCS_BUG___
			{
				if (strResult[strResult.GetLength()-1] != '\\' &&
					strResult[strResult.GetLength()-1] != '/')	{
					strResult += m_chDirSeparator;
					}
				}
			#else
			{
				LPCTSTR pszResult;
				LPCTSTR pchLast;
				pszResult = strResult;
				pchLast = _tcsdec( pszResult, pszResult+strResult.GetLength() );
				VERIFY(pchLast!=NULL);
				if ((*pchLast != _T('\\')) && (*pchLast != _T('/')))	{
					strResult += m_chDirSeparator;
					}
				}
			#endif
			strResult += GetFileName();
			return strResult;
			}
		} ;

MFC 7 以降であれば,CFileFind として利用可能.


i_FileF.hxx
enumfile.hxx

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

システムメニューに項目の追加

あまり使用しないので,メモ.
「ダイアログベース」の AP に「設定」メニューの追加.
コードのサンプルなどは以下の所や,CXxxDlg::OnInitDialog .
MSDN CWnd::GetSystemMenu


IDS_… と IDM_… のリソースを追加.

	pSysMenu->AppendMenu(MF_SEPARATOR);
	pSysMenu->AppendMenu(MF_STRING, IDM_SETTING, _T("設定(&S)...")) ;	

今回は,面倒だったのでメニュー名は文字列として直接指定.


IDM_… の値は 0x0020 など.
メニューの「編集」-「リソース シンボル」で表示されるダイアログで追加する.
メニュー項目の IDM_... を追加する
CXxxxDlg::OnSysCommand でイベントを受け取る.

	if ((nID & 0xFFF0) == IDM_ABOUTBOX)	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
		}
	else if ((nID & 0xfff0) == IDM_SETTING) {
		OnSetting() ;
		}
	else 	{
		CDialog::OnSysCommand(nID, lParam);
		}	
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

MAPI の MapiFileDesc の配列

MFC を使用している方法では,

    LateDelete	ld ;    //  MultiByte の必要があるようなので,UNICODE の時のバッファをここに登録
    //	添付ファイルの準備
    CArray<MapiFileDesc,MapiFileDesc>	fileDescA ;
    int	fileCount = 0 ;
    int	index = 0 ;
    for (index=0 ; index<PathNames.GetSize() ; index++) {
        CString	    pathName = PathNames[index] ;
        if (::FileIsNothing  (pathName))	{	continue ;	}
        if (::FileIsDirectory(pathName))	{	continue ;	}
        MapiFileDesc	fileDesc ;
        memset(&fileDesc,0,sizeof(MapiFileDesc)) ;
        fileDesc.nPosition		= (ULONG)-1 ;
    #ifdef	_UNICODE
        fileDesc.lpszPathName	= SendMail__ChangeMultiByte(PathNames[index],&ld) ;
        fileDesc.lpszFileName	= SendMail__ChangeMultiByte(FileNames[index],&ld) ;
    #else
        fileDesc.lpszPathName	= LPSTR(LPCTSTR(PathNames[index])) ;
        fileDesc.lpszFileName	= LPSTR(LPCTSTR(FileNames[index])) ;
    #endif
        fileDescA.Add(fileDesc) ;
        fileCount++ ;
        }

MFC を使用しないコードは,

    std::vector<MapiFileDesc>	fileDescA ;
    std::vector<std::string>	pathNameA ;
    std::vector<std::string>	fileNameA ;
    int	index = 0 ;
    {
        for (index=0 ; index<PathNames.GetSize() ; index++) {
            {
                tstring	pathName = PathNames[index] ;
                if (::File_IsNothing  (pathName))	{	continue ;	}
                if (::File_IsDirectory(pathName))	{	continue ;	}
                }
            std::string	pathName= ::To__string(PathNames[index]) ;
            std::string	fileName= ::To__string(FileNames[index]) ;
            pathNameA.push_back(pathName) ;
            fileNameA.push_back(fileName) ;
            }
        {
            for (size_t index=0 ; index<pathNameA.size()&&index<fileNameA.size() ; index++) {
                MapiFileDesc	fileDesc ;
                memset(&fileDesc,0,sizeof(MapiFileDesc)) ;
                fileDesc.nPosition	= (ULONG)-1 ;
                fileDesc.lpszPathName	= &(pathNameA[index])[0] ;
                fileDesc.lpszFileName	= &(fileNameA[index])[0] ;
                fileDescA.push_back(fileDesc) ;
                }
            }
        }

詳しくは見てないが,幾つかの方法が書かれていたので
Sending Email with MAPI


MapiRecipDesc.lpszAddress の “smtp:”
以前コードを直したのが 2002/4 であまり情報がなかった様に思う.
個人的に書いた内容が「Outlook で配信不能になる
参考になりそうな所
Email mit Dateien perWinAPI versenden??
MAPISendMail
MSDN MapiRecipDesc structure
Sending email using MAPI causes error on ‘ResolveName’ function in Window7


MAPI を使用した複数ファイルの送信
S_Mail.hxx

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

VC 6 LNK2001 __beginthreadex

空のコンソール AP プロジェクトで,Afx.h を追加でインクルードしてビルドすると,

--------------------構成: MkBG_up - Win32 Debug--------------------
リンク中...
nafxcwd.lib(thrdcore.obj) : error LNK2001: 外部シンボル "__endthreadex" は未解決です
nafxcwd.lib(thrdcore.obj) : error LNK2001: 外部シンボル "__beginthreadex" は未解決です
c:\Temp\Test_3D\MkBG_up\Debug.060/MkBG_up.exe : fatal error LNK1120: 外部参照 2 が未解決です。
link.exe の実行エラー
MkBG_up.exe - エラー 3、警告 0

プロジェクトの設定で「共有 DLL で MFC を使用」などに変更.


2018/06/29 追記
エラーが出た直後の場合は,リビルドが必要.

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

CObArray <--> CObList

CObList の形式のデータを配列として処理したかったので,その相互変換(Sort_ind.hxx 内).


#ifdef		_MFC_VER
//*******************************************************************************
//	ObList	->	ObArray
//	Create	:	2017/10/30
//*******************************************************************************
inline	bool	To_ObArray	(const CObList& src,CObArray* dstAry)
{
	if (dstAry == NULL)		{	return	false ;		}
	dstAry->RemoveAll() ;
	{
		POSITION pos = src.GetHeadPosition();
		while (pos != NULL)	{
			CObject*	pObj = src.GetNext(pos);
			dstAry->Add(pObj) ;
			}
		}
	return	true ;
	}

//*******************************************************************************
//	ObArray	->	ObList
//	Create	:	2017/10/30
//*******************************************************************************
inline	bool	To_ObList	(const CObArray& src,CObList* dstLst)
{
	if (dstLst == NULL)		{	return	false ;		}
	dstLst->RemoveAll() ;
	{
		for (INT_PTR index=0 ; index<src.GetSize() ; index++) {
			CObject*	pObj = src[index] ;
			dstLst->AddTail(pObj) ;
			}
		}
	return	true ;
	}

#endif	//	_MFC_VER
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

CHttpFile を使用したアップロード

CHttpFile を使用したアップロードのコードを整理.
サーバ側は先日の php と同様.
https://jml.mish.work/index.php/i-tools/upload-htm-php.html


//*******************************************************************************
//	send request define
//	Create	:	2017/08/28
//*******************************************************************************
#define	C_CRLF			_T("\r\n") ;
#define	CT_ct_mp_fd_b_		_T("Content-Type: multipart/form-data; boundary=")
#define	CT_boundary__		_T("--")
#define	CD_cd_f_d_n_		_T("Content-Disposition: form-data; name=")
#define	CD_cd__fn_		_T("; filename=") ;
#define	CT_ct_a_o_s		_T("Content-Type: application/octet-stream")

//*******************************************************************************
//	make send data
//	Create	:	2017/08/28
//*******************************************************************************
inline	v_char	Make_send_data	(LPCTSTR upFile,LPCTSTR ___boundary)
{
	v_char	up_Data = v_c_Load (upFile) ;
	v_char	sndData ;
	{
		tstring	ct_boundary	= ___boundary ;
		tstring	file_img	= ::QuotM_Add(_T("file_img")) ;
		tstring	fileName	= ::QuotM_Add(::Path_GetName(upFile)) ;
		tstring	dataPre ;
		tstring	dataPst ;
		dataPre+=	CT_boundary__	+	ct_boundary				+	C_CRLF ;
		dataPre+=	CD_cd_f_d_n_	+	file_img	+	CD_cd__fn_	;
		dataPre+=							fileName	+	C_CRLF ;
		dataPre+=	T_ct_a_o_s								C_CRLF ;
		dataPre+=										C_CRLF ;
		dataPst+=										C_CRLF ;
		dataPst+=	CT_boundary__	+	 ct_boundary	+	CT_boundary__		C_CRLF ;
		v_char	vc_pref = ::To_v_char(::To__string(dataPre.c_str())) ;
		v_char	vc_post = ::To_v_char(::To__string(dataPst.c_str())) ;
		sndData.insert(sndData.end(),vc_pref.begin(),vc_pref.end()) ;
		sndData.insert(sndData.end(),up_Data.begin(),up_Data.end()) ;
		sndData.insert(sndData.end(),vc_post.begin(),vc_post.end()) ;
		}
	#ifdef	_DEBUG
	{
		::i_Dump(sndData,(::Path_GetName(upFile)+_T(".txt")).c_str()) ;
		}
	#endif
	return	sndData ;
	}

//*******************************************************************************
//	upload
//	Create	:	2017/08/28
//*******************************************************************************
inline	bool	UploadFile	(LPCTSTR svrName,LPCTSTR php,LPCTSTR upFile)
{
	{
		if (::File_IsNothing(upFile))			{	return	false ;		}
	//	if (::File_GetSize  (upFile) > 2048*1024)	{	return	false ;		}
		}
	tstring	head ;
	v_char	sndData ;
	{
		tstring	___boundary = _T("-----UpFile__2017_08_30") ;
			___boundary = _T("-----") + ::Path_GetName(_T(__FILE__)) + _T("__") + ::Now_Format(_T("%H%M%S")) ;
		head	= CT_ct_mp_fd_b_	+ ___boundary ;
		sndData = Make_send_data(upFile,  ___boundary.c_str()) ;
		}
	tstring	serverN = svrName ;
	tstring	portStr ;
	{
		v_tstring	strAry = ::String_Split(svrName,false,_T(":")) ;
		if (strAry.size() >= 2) {
			serverN = strAry[0] ;
			portStr = strAry[1] ;
			}
		}
	INTERNET_PORT	nPort = 0 ;
			nPort = ::ttou2(portStr) ;
	tstring		userAgent = _T("drop_up") ;
			userAgent = ::Path_GetName(_T(__FILE__)).c_str() ;
	#ifdef	_WIN32
	{
		userAgent = ::Path_GetName(::i_GetModuleFileName()) ;
		{
			tstring	osVer	= _T("Windows NT ") + ::To_tstring_rz(::GetWinVer_exe()) ;
				osVer	+=  tstring(_T(" "))+ Bracket_Add(::GetWinVerStr_exe(),_T('(')).c_str() ;
			userAgent += _T(" ") + osVer ;
			userAgent += EXE_AddVerBuildStr() ;
			}
		}
	#endif
	CInternetSession	session(userAgent.c_str()) ;
	CHttpConnection*	pServer = NULL ;
	CHttpFile*		pFile = NULL ;
	DWORD			dwStatus = 0 ;
	try	{
				pServer = session.GetHttpConnection(serverN.c_str(),nPort) ;
				if (pServer == NULL)				{	return	false ;		}
			{
				CString	headStr = head.c_str() ;
				pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,	php) ;
				if (pFile == NULL)				{	return	false ;		}
				pFile->SendRequest(headStr,(LPVOID)(&sndData[0]),DWORD(sndData.size())) ;
				pFile->QueryInfoStatusCode(dwStatus) ;
				}
			{
				delete	(pFile) ;
				delete	(pServer) ;
				}
		}
	catch	(CInternetException* e) {
		CString	errMsg ;
		e->GetErrorMessage(errMsg.GetBuffer(1024),1024) ;
		errMsg.ReleaseBuffer() ;
		std::tout << LPCTSTR(errMsg) << std::endl ;
		return	false ;
		}
	session.Close() ;
	return	true ;
	}

//*******************************************************************************
//	upload files
//	Create	:	2017/08/29
//*******************************************************************************
inline	bool	UploadFiles	(c_v_tstring& upFiles)
{
	v_tstring	svr_php = ::UF_get_server_php() ;
	tstring		serverN = svr_php[0] ;
	tstring		phpName = svr_php[1] ;
	for (size_t index=0 ; index<upFiles.size() ; index++) {
		tstring	upFile = upFiles[index] ;
		if (::File_IsNothing(upFile))		{	continue ;		}
		if (!::UploadFile(serverN.c_str(),phpName.c_str(),upFile.c_str()))	{
			return	false ;
			}
		}
	return	true ;
	}

UploadFile


これらを使用したツールは以下にあります.
http://i_tools.mish.work/2019/10/up-htm.html


2020/09
日本語を含むファイル名のアップロード

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

データ送信 CHttpFile

送信するデータの中身をどの様に指定するかわかってないので,CHttpFile でもう一度やり直し.
MSDN CHttpFile クラスにあるサンプルのコードで,前回と同様にデータが送れることは確認.


content.txt を用意して,あればそれを読込んで送る様に変更.
   CString strData = _T(“Some very long data to be POSTed here!”);
   {
     CString dataFile = _T(“./content3.txt”) ;
     if (::File_IsExist(dataFile)) {
       strData = ::LoadText(dataFile).c_str() ;
       }
     }


Content-Type: multipart/form-data; boundary=—-WebKitFormBoundaryHQUnqULNgae5Y5HW
——WebKitFormBoundaryHQUnqULNgae5Y5HW
Content-Disposition: form-data; name=”file_imo”; filename=”up_Cube.imo”
Content-Type: application/octet-stream

v 0 0 -5
v 0 0 0
v 0 5 0
v 0 5 -5
v 5 0 -5
v 5 5 -5
v 5 0 0
v 5 5 0
f 1 2 3 4
f 5 1 4 6
f 7 5 6 8
f 2 7 8 3
f 3 8 6 4
f 2 1 5 7

——WebKitFormBoundaryHQUnqULNgae5Y5HW
Content-Disposition: form-data; name=”file_htm”; filename=”up_Cube.htm”
Content-Type: application/octet-stream
 
<!DOCTYPE html>
<html lang=”ja” >
<head >
<meta charset=”UTF-8″ />
< script src=”/_lib/js/webgl/threejs/r84/build/three.js”> </script>
< script src=”/_lib/js/webgl/threejs/r84/examples/js/Detector.js”> </script>
< script src=”/_lib/js/webgl/threejs/r84/examples/js/controls/OrbitControls.js”> </script>
< script src=”/_lib/js/webgl/threejs/r84/examples/js/loaders/MTLLoader.js”> </script>
< script src=”/_lib/js/i_lib/threejs/r84/IMOLoader.js”> </script>
< script src=”/_lib/js/i_lib/threejs/r84/c_3js_4.js”> </script>
< script src=”/_lib/js/i_lib/2017.03/filePath.js”> </script>
</head>
<body>

var imoFile=’up_Cube.imo’;
ThreeStart3 (imoFile,5,5,5) ;

</body>
</html>
 
——WebKitFormBoundaryHQUnqULNgae5Y5HW–
 


データは送られているが,PHP の $_FILES にうまく設定されていない.
   $str = var_export($_FILES,true) ;
ヘッダ部分の指定が間違っていたみたいで,
   CString strHead ;
   {
     CString dataFile = _T(“./content3.txt”) ;
     if (::File_IsExist(dataFile)) {
       strData = ::LoadText(dataFile).c_str() ;
       {
         v_tstring strAry = ::String_SplitLine(strData) ;
         if (strAry.size() > 0) {
           strHead = strAry[0].c_str() ;
           strAry.erase(strAry.begin()) ;
           strData = ::String_Join_Line(strAry).c_str() ;
           }
         }
       }
     }
送信部分も,SendRequestEx から SendRequest に変更.
   pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, _T(“/…/t_mfc_h/t_mfc_h.php”)) ;
   pFile->SendRequest(strHead,(LPVOID)LPCTSTR(strData),strData.GetLength()) ;
   pFile->QueryInfoStatusCode(dwStatus) ;


2017/09/04 CHttpFile を利用したアップロード
UpFile.hxx
UpFile.hxx

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

ダイアログバーに CCheckListBox

通常のダイアログに CCheckListBox を追加するには,次のような手順.
  CCheckListBox の使い方
ダイアログバーでは,次の様にしてもデータが表示されない.

CCheckListBox*  clb = (CCheckListBox*)m_wndDlgBar.GetDlgItem(IDC_CHECK_LB) ;
clb->AddString("....") ;

以前作成した,オーナー描画のドロップダウンを思い出しコードを見ると,

CMainFrame に変数を追加して,サブクラス化している.
CMainFrame::OnCreate でダイアログバーを Create した後,
 m_ODCB.SubclassDlgItem(IDC_COMBO,&m_wndDlgBar) ;

このコードの最初は,2004/07.
手元にある幾つかの本を見たが見つからなかった.
何を参考にしたかは今となっては不明.


LBN_SELCHANGE で選択された状態がイマイチ.
 内容を更新(PostMessage)するとインデックス 0 の項目に薄い点線が付く.
SendMessage として更新後,選ばれていた項目を SetCurSel することで対応.

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

コンソール 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.

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.

HICON -> DIB

i_DIB	GetIcon_DIB	(LPCTSTR filePath,const long size=300)
{
    i_DIB	dib ;
    HICON	hIcon  = ::DImageS_GetIcon(filePath) ;
    if (hIcon != NULL)	{
        MemoryDC	memDC ;
        memDC.Init(CSize(size,size),32) ;
        CDC*		mem_dc = memDC.GetMemoryDC() ;
        mem_dc->FillSolidRect(CRect(0,0,size,size),RGB(240,240,255)) ;
        ::Icon_Draw(mem_dc->GetSafeHdc(),CRect(10,10,size-10,size-10),hIcon,TRUE,TRUE) ;
        dib = ::ToDIB(memDC) ;
        memDC.Term() ;
        ::DestroyIcon(hIcon) ;
        }
    return	dib ;
    }
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

CFileStatus でアサート

ファイルの作成日時が正しくない?と CFileStatus でうまく動作しない.


このファイルは,プログラミング Windows 第5版の CD を Mac でコピーしたもの.
このファイルを CFile::GetStatus とすると,アサートなど.
VC 8 の場合,ATLTime.inl CTime コンストラクタの 200 行目付近で
  if(m_time == -1)
  {
    AtlThrow(E_INVALIDARG);
    }


—————————
TsHBMP
—————————
パラメータが間違っています。
—————————
OK
—————————


CFileStatus を使わずに,stat を使用する様に書換えてある程度は動作する様になった.
VC 14 では,stat がエラーで帰ってくる.この対応方法は不明.
CFileStatus を使用している所はかなりあるため,すべてに対応するにはしばらくかかる.
今回は Shell Extension でダウンしたため,その部分のみ対応.

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

高 DPI – 2

CMetaFileDC::CreateEnhanced の lpBounds を指定していたが,うまくなかった様で NULL に.
また,これとは異なるが再生デバイスが異なる場合うまくなかったので,
 ENHMETAHEADER の rclFrame ではなく rclBounds に変更.


何を参考にしたのか不明だが,幅を求めるのに TEXTMETRIC だけを使用していた.幾つかあり.
CComboBox::SetDroppedWidth
CListBox::SetHorizontalExtent
CDC::GetTextExtent


高 DPI – 1
高 DPI – 3

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

error LNK2005 LNK2001

プロジェクト生成時に「MFC を使用しない」としたコンソール AP で Afx.h をインクルードした場合


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

nafxcwd.lib(thrdcore.obj) : error LNK2001: 外部シンボル “__endthreadex” は未解決です
nafxcwd.lib(thrdcore.obj) : error LNK2001: 外部シンボル “__beginthreadex” は未解決です


プロジェクトの設定で「共有 DLL で MFC を使う」などに変更.

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

tstring Unit::ToName の呼び出し後エラー

もともと CString Unit::ToName(…) だった関数の戻り値を tstring に変更した.
利用している所の多くは,コンパイルエラーとなり Unit::ToName(…).c_str() と修正したが...
次の様な可変引数の修正が漏れていた.
CString unitStr ; unitStr.Format(_T(“%d_%s”),…,Unit::ToName(…)) ;

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

VC 8 で _ATL_VER が定義される?

先日書いたコードを MFC ダイアログベースの AP で利用してみると,CRegKey の未定義エラー.
コードは,次の様に「_ATL_VER が定義されていれば…」としている.
  #ifdef _ATL_VER
     CRegKey reg ;
     …
  #endif


—— ビルド開始: プロジェクト: SmpMG, 構成: Debug Win32 ——
コンパイルしています…
SmpMGDlg.cpp
…\i_RegGet.hxx(36) : error C2065: ‘CRegKey’ : 定義されていない識別子です。
…\i_RegGet.hxx(36) : error C2146: 構文エラー : ‘;’ が、識別子 ‘reg’ の前に必要です。
…\i_RegGet.hxx(36) : error C2065: ‘reg’ : 定義されていない識別子です。
…\i_RegGet.hxx(37) : error C2228: ‘.Open’ の左側はクラス、構造体、共用体でなければなりません
…\i_RegGet.hxx(39) : error C2228: ‘.QueryDWORDValue’ の左側はクラス、構造体、共用体でなければなりません
SmpMG – エラー 5、警告 0
========== ビルド: 0 正常終了、1 失敗、0 更新、0 スキップ ==========


VC 6 や,VC 8 のコンソール AP としての利用はうまくいっている.
自分で書いた部分では,_ATL_VER が定義される様なインクルードは追加してない.
_ATL_VER は (VS8)\VC\atlmfc\include\AtlDef.h にある.


StdAfx.h でインクルードしているものを順に追いかけていくと,
AfxDisp.h 内で Atlナントカ.h がインクルードされている.
同様の部分の VC 6 の方では Atl~.h はなさそう.


どの様にするのがベターなのかわからないが,AtlBase.h をインクルードする様にした.
  #ifdef _ATL_VER
  #include <AtlBase.h>
  #endif

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