ホーム » VC (ページ 10)

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

2024年4月
 123456
78910111213
14151617181920
21222324252627
282930  

カテゴリー

アーカイブ

ブログ統計情報

  • 79,632 アクセス



VC 6 MFC サポートのコンソール AP で,C4786

c:\program files\microsoft visual studio\vc98\include\utility(123) :
warning C4786: ‘std::vector<std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >,std::allocator<std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > > >’ :
デバッグ情報で識別子が 255 文字に切り捨てられました。
StdAfx.h の #include <iostream> より前に,以下を追加して対応.

    #pragma warning (disable : 4786 )
    #include <utility>
//  #pragma warning (default : 4786 )
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

MFC DLL → Static – 2

VC 6 などで生成したプロジェクトを,VC 7 ~ VC 11 まで順に変換して利用してきたもの.
「共有 DLL で MFC を使う」から「スタティック ライブラリで MFC を使用する」に変更してビルドすると,
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\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]
プロジェクトの「プロパティページ」-「構成プロパティ」-「C/C++」-「コード生成」-「ランタイム ライブラリ」を
  「マルチスレッド DLL (/MD)」から「マルチスレッド (/MT)」に変更.


ビルドは通る様になったが,起動時メインフレーム表示直後にアプリケーションエラー.
  プロジェクトのプロパティで,「リンカ」-「デバッグ」-「デバッグ情報の生成」で「はい (/DEBUG)」に.
  ビルドして実行すると,
  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\mfc\docsingl.cpp
    CSingleDocTemplate::SetDefaultTitle(CDocument* pDocument) の
       ENSURE(strDocName.LoadString(AFX_IDS_UNTITLED));
アプリケーション エラー
プロジェクトのプロパティ,「リソース」-「プリプロセッサの定義」に “_AFXDLL;” があったので削除.


2021/02/17
VC 7 以降に変換した段階で,ソースの「プリプロセッサの定義」が引き継がれてしまう?
そのため,それは削除した方が良さそう.
VC 8 「ソース」のプリプロセッサの定義
* 間違ってプロジェクトの「プリプロセッサの定義」を削除しないこと.
VC 12 LNK1104 , VC 14.2 LNK2019

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

VC 11 , 12

AtlGetCommCtrlVersion が,GetCommCtrlVersion になっている.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlbase.h 7505:
   inline HRESULT AtlGetCommCtrlVersion(
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\mfc\winutil.cpp 243:
   HRESULT GetCommCtrlVersion(


VC 12 の標準のインストールでは MBCS.exe が作成できない.
MSDN マルチバイト文字セット (MBCS) のサポート


—— ビルド開始: プロジェクト:ccVer, 構成:Debug Win32 ——
ccVer.cpp
_WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
c:\program files\windows kits\8.1\include\um\winnt.h(340):
  error C2146: 構文エラー : ‘;’ が、識別子 ‘PVOID64’ の前に必要です。
c:\program files\windows kits\8.1\include\um\winnt.h(340):
  error C4430: 型指定子がありません – int と仮定しました。メモ: C++ は int を既定値としてサポートしていません
c:\program files\windows kits\8.1\include\um\winnt.h(12333):
  error C2146: 構文エラー : ‘;’ が、識別子 ‘Buffer’ の前に必要です。
c:\program files\windows kits\8.1\include\um\winnt.h(12333):
  error C4430: 型指定子がありません – int と仮定しました。メモ: C++ は int を既定値としてサポートしていません
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========
DX90SDK\Include が含まれていたのが原因.


c:\program files\microsoft visual studio 12.0\vc\include\xtgmath.h(206):
  warning C4003: マクロ ’round’ に指定された実引数の数が少なすぎます。
c:\program files\microsoft visual studio 12.0\vc\include\xtgmath.h(206):
  error C2059: 構文エラー : ‘(‘
c:\program files\microsoft visual studio 12.0\vc\include\xtgmath.h(206):
  error C2062: 型 ‘double’ は不要です。
c:\program files\microsoft visual studio 12.0\vc\include\xtgmath.h(224):
  fatal error C1070: ソース ファイル ‘c:\…\vc\include\xtgmath.h’ 中で #if と #endif が対応していません。
Scale.hxx 等に定義されている #define round(v,p) … が影響していると思われる.
C99 になったことによる影響?


_MSC_VER はソースの先頭でも定義されているが,_MFC_VER は Afx.h の後でないと正しく取れない?
  よく考えれば当然のこと?


MFC 11 で CFileStatus が変更された.

  MFC 10 では,
    struct CFileStatus
    {
      CTime m_ctime;          // creation date/time of file
      CTime m_mtime;          // last modification date/time of file
      CTime m_atime;          // last access date/time of file
      ULONGLONG m_size;       // logical size of file in bytes
      BYTE m_attribute;       // logical OR of CFile::Attribute enum values
      BYTE _m_padding;        // pad the structure to a WORD
      TCHAR m_szFullName[_MAX_PATH]; // absolute path name
    #ifdef _DEBUG
      void Dump(CDumpContext& dc) const;
    #endif
    };

  MFC 11
    struct CFileStatus
    {
      CTime m_ctime;          // creation date/time of file
      CTime m_mtime;          // last modification date/time of file
      CTime m_atime;          // last access date/time of file
      ULONGLONG m_size;       // logical size of file in bytes
      DWORD m_attribute;      // logical OR of CFile::Attribute enum values
      TCHAR m_szFullName[_MAX_PATH]; // absolute path name
    #ifdef _DEBUG
      void Dump(CDumpContext& dc) const;
    #endif
    };

Visual Studio 2012 の更新プログラムの概要
Visual Studio 2012 の更新プログラム 4
Download Center Visual Studio 2012 Update 4


VC 2012 で作成した exe は,Win XP で実行できない?
Visual Studio 2012 で Windows XP をターゲットとする Visual C++ アプリケーションを作成する方法
Wikipedia Microsoft Visual C++


Visual Studio 2012 更新プログラム 4 の Visual C++ 再頒布可能パッケージ
Visual Studio 2013 の Visual C++ 再頒布可能パッケージ


プロジェクトをサーバにコピーして,VC 8 でビルドすると
  cl : コマンド ライン error D8022 : ‘\\devs\…\ArcEdit\Debug.080\RSP0000264523920.rsp’ を開けません
ローカルのプロジェクトは OK.
また,VC 6 なども C2039 はあるが,それなりに通る.
  \\devs\…\helpvsty.hxx(57) : error C2039: ‘AtlGetCommCtrlVersion’ :
     ‘`global namespace” のメンバではありません。
  これは,#define GetCommCtrlVersion AtlGetCommCtrlVersion としている所を,関数にして回避.
    … GetCommCtrlVersion (…) { return AtlGetCommCtrlVersion (…) ; }


VC 7.1 と VC 8 で,ネットワーク上のプロジェクトをビルドするとうまくない様なので,中間ファイルの指定を変更.
  .\$(ConfigurationName) を c:\Temp\$(ProjectName)\$(ConfigurationName) としてみた.
  これにより,rsp や obj などが C:\Temp\…\Debug\ 以下になりうまく通る.
検索すると,.\$(ConfigurationName)\ の様に最後に ‘\’ を付ければ通るとのこと.
  Error D8022 – can’t open .RSP file


2014/04/17
今までバックアップを取ったりする時に不要なファイルを消していたが,プロジェクトの設定などを変更してみた.
中間ディレクトリとデバッグ版の出力ディレクトリを c:\Temp\$(ProjectName)\$(ConfigurationName)\ に.
VC 10 以降で,フォールバック位置を指定(sdf , ipch の位置の指定).


VC 11 で,
  LibHasp_Windows.lib(wurzl37.obj) : error LNK2026: モジュールは SAFESEH イメージには安全ではありません。
    「リンカ」-「詳細設定」-「安全な…」の「はい (/SAFESEH)」をクリア.

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

C2582

ちょっとわかりにくいエラーメッセージだったので,…
——————–構成: Read_3D – Win32 Debug——————–
コンパイル中…
c:\…\p_a_3ds.hxx(101) : error C2582: ‘operator ‘entry’ 関数は ” 内では使用できません。
cl.exe の実行エラー
Read_3D.exe – エラー 1、警告 0


MSDN では,
コンパイラ エラー C2582
‘identifier’ : 代入演算子 ‘operator =’ が、指定されたクラスに定義されていません。
 
指定されたクラスには、代入演算子 operator=() が定義されていません。
 
クラスを引数とする代入演算子を定義している場合は、コンパイラはデフォルトの代入演算子を生成しません。
代入演算子は、各クラスに対して明示的に定義しなければなりません。代入演算子は派生クラスに継承されません。

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

typedef … BOOL ;

iOS のプロジェクトでビルドすると,BOOL の定義(typedef int BOOL ;)で,
  /…/i_Define.hxx:30:18: Typedef redefinition with different types (‘int’ vs ‘signed char’)
iPhoneSimulator6.1/usr/include/objc/objc.h に以下が定義されている.
  typedef signed char BOOL;


以下の様に OBJC_BOOL_DEFINED で振り分け.
  #ifdef OBJC_BOOL_DEFINED
  #else
    typedef int BOOL ;
  #endif


i_define.hxx


他にも,Mac 64-bit でビルドすると,long のビット長の問題で幾つかワーニングになる.
いい対応方法が思いつかないので,ひとまず幾つかはそのままとする.

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

C2061

既存のプロジェクトで,::To_tstring(const P2&…) を追加したら,
——————–構成: BLCombi – Win32 Debug——————–
コンパイル中…
ComPrj01.cpp
c:\…\vc98\include\memory(16) : error C2061: 構文エラー : 識別子 ‘THIS_FILE’ がシンタックスエラーを起こしました。
c:\…\vc98\include\memory(17) : error C2091: 関数は関数を返せません。
c:\…\vc98\include\memory(17) : error C2809: ‘operator new’ に仮引数リストがありません。
c:\…\vc98\include\memory(20) : error C2954: テンプレートの定義はネストできません。
c:\…\…..\blocklsv.cpp(398) : error C2678: 二項演算子 ‘+’ : 型 ‘class std::basic_string …’ の
  左オペランドを扱う演算子は定義されていません。(または変換できません)(新しい動作; ヘルプを参照)
cl.exe の実行エラー
ComPrj01.obj – エラー 5、警告 0


本来の対応は別の所にありそうだが,ComPrj01.cpp の先頭に #include <memory> を追加した.
  #include “StdAfx.h”
  #include “ComPrj00.hpp”
  #include <memory>
  …

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

VC 6 で _UNICODE

VC 6 コンソール AP で,_UNICODE を付加してビルドすると
——————–構成: T_F_Stat – Win32 ReleaseU——————–
コンパイル中…
T_F_Stat.cpp
C:\…\VC98\INCLUDE\winnt.h(195) : error C2371: ‘LPTSTR’ : 再定義されています。異なる基本型です。
  C:\…\Develop\_.SRC\__CPR_\tstring.hxx(33) : ‘LPTSTR’ の宣言を確認してください。
C:\…\VC98\INCLUDE\winnt.h(196) : error C2371: ‘LPCTSTR’ : 再定義されています。異なる基本型です。
  C:\…\Develop\_.SRC\__CPR_\tstring.hxx(34) : ‘LPCTSTR’ の宣言を確認してください。
C:\…\Develop\_.SRC\__Mlt_\Get_Path.hxx(64) : error C2664: ‘GetCurrentDirectoryA’ :
  2 番目の引数を ‘unsigned short *’ から ‘char *’ に変換できません。 (新しい機能 ; ヘルプを参照)
  指示された型は関連がありません; 変換には reinterpret_cast、 C スタイル キャストまたは関数スタイルのキャストが必要です。
C:\…\Develop\_.SRC\__Mlt_\Get_Path.hxx(91) : error C2664: ‘GetLongPathNameA’ :
  1 番目の引数を ‘const unsigned short *’ から ‘const char *’ に変換できません。 (新しい機能 ; ヘルプを参照)
  指示された型は関連がありません; 変換には reinterpret_cast、 C スタイル キャストまたは関数スタイルのキャストが必要です。
C:\…\Develop\_.SRC\__Mlt_\Get_Path.hxx(114) : error C2664: ‘GetTempPathA’ :
  2 番目の引数を ‘unsigned short *’ から ‘char *’ に変換できません。 (新しい機能 ; ヘルプを参照)
  指示された型は関連がありません; 変換には reinterpret_cast、 C スタイル キャストまたは関数スタイルのキャストが必要です。
C:\…\Develop\_.SRC\__Win\HelpWAPI.hxx(107) : error C2664: ‘GetModuleFileNameA’ :
  2 番目の引数を ‘unsigned short *’ から ‘char *’ に変換できません。 (新しい機能 ; ヘルプを参照)
  指示された型は関連がありません; 変換には reinterpret_cast、 C スタイル キャストまたは関数スタイルのキャストが必要です。
C:\…\Develop\_.SRC\__Win\HelpWAPI.hxx(143) : error C2664: ‘GetComputerNameA’ :
  1 番目の引数を ‘unsigned short *’ から ‘char *’ に変換できません。 (新しい機能 ; ヘルプを参照)
  指示された型は関連がありません; 変換には reinterpret_cast、 C スタイル キャストまたは関数スタイルのキャストが必要です。
C:\…\Develop\_.SRC\__Win\HelpWAPI.hxx(163) : error C2664: ‘GetUserNameA’ :
  1 番目の引数を ‘unsigned short *’ から ‘char *’ に変換できません。 (新しい機能 ; ヘルプを参照)
  指示された型は関連がありません; 変換には reinterpret_cast、 C スタイル キャストまたは関数スタイルのキャストが必要です。
cl.exe の実行エラー
T_F_Stat.exe – エラー 8、警告 0


tstring.h で LPxTSTR の定義は次の様にしていた.
#ifdef _MSC_VER
typedef TCHAR* LPTSTR ;
typedef const TCHAR* LPCTSTR ;
#else
typedef char* LPTSTR ;
typedef const char* LPCTSTR ;
#endif


対応方法がわからず,#include <Afx.h> を追加すると通る様にはなった.


_UNICODE だけでなく UNICODE も追加すると,Afx.h なしでも通る様になった.


2020/09 コンソール AP での define

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

fopen と sopen

_tfopen と _tsopen の mode の関係がわからなかったので,コードを抜粋
(VS8)\VC\crt\src\_open.c より
  /* First mode character must be ‘r’, ‘w’, or ‘a’. */
  switch (*mode) {
    case _T(‘r’):
      modeflag = _O_RDONLY;
      streamflag |= _IOREAD;
      break;
    case _T(‘w’):
      modeflag = _O_WRONLY | _O_CREAT | _O_TRUNC;
      streamflag |= _IOWRT;
      break;
    case _T(‘a’):
      modeflag = _O_WRONLY | _O_CREAT | _O_APPEND;
      streamflag |= _IOWRT;
      break;
    default:
      _VALIDATE_RETURN((“Invalid file open mode”,0), EINVAL, NULL);
    }


openfile.hxx
vchrfile.hxx

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

C2146

次の様なコードで,C2146 , C2065


  private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
    Size cr = this->ClientSize ;
    Point lt = Point(cr.Width/3*1,cr.Height/3*1) ;
    Point rb = Point(cr.Width/3*2,cr.Height/3*2) ;
    array<Point>^ pts = gcnew array<Point>(5) ;
    {
      pts->SetValue(gcnew Point(lt.X,lt.Y),0) ;
      pts->SetValue(gcnew Point(lt.X,rb.Y),1) ;
      pts->SetValue(gcnew Point(rb.X,rb.Y),2) ;
      pts->SetValue(gcnew Point(rb.X,lt.Y),3) ;
      pts->SetValue(gcnew Point(lt.X,lt.Y),4) ;
      }
    e->Graphics->DrawLines(gcnew Pen(Color::Red),pts) ;
    }
  private: System::Void Form1_SizeChanged(System::Object^ sender, System::EventArgs^ e) {
    this->Invalidate() ;
    }


—— ビルド開始: プロジェクト: DrwLines, 構成: Debug Win32 ——
コンパイルしています…
DrwLines.cpp
c:\…\drwlines\Form1.h(75) : error C2146: 構文エラー : ‘;’ が、識別子 ‘cr’ の前に必要です。
c:\…\drwlines\Form1.h(75) : error C2065: ‘cr’ : 定義されていない識別子です。
c:\…\drwlines\Form1.h(76) : error C2228: ‘.Width’ の左側はクラス、構造体、共用体でなければなりません
型は ”unknown-type” です。
c:\…\drwlines\Form1.h(76) : error C2228: ‘.Height’ の左側はクラス、構造体、共用体でなければなりません
型は ”unknown-type” です。
c:\…\drwlines\Form1.h(77) : error C2228: ‘.Width’ の左側はクラス、構造体、共用体でなければなりません
型は ”unknown-type” です。
c:\…\drwlines\Form1.h(77) : error C2228: ‘.Height’ の左側はクラス、構造体、共用体でなければなりません
型は ”unknown-type” です。
ビルドログは “file://c:\…\DrwLines\Debug\BuildLog.htm” に保存されました。
DrwLines – エラー 6、警告 0
========== ビルド: 0 正常終了、1 失敗、2 更新、0 スキップ ==========


Drawing::Size とすることにより通る様になるが,イマイチどの様に書くべきかが理解できてない.
DrawLines についても,よくわかってない.array<Point>^ の array って何?
ここの説明がわかりやすい.


pts->SetValue(gcnew Point(lt.X,lt.Y),0) ; の gcnew はいらない?
関数の引数の const ~ & はどこへ?


printf や CString::Format の “%10.3f” の様な形式
  String::Format で “{0,10:F3}”


C:\…\HelpPnt.hxx(72) : error C3083: ‘Drawing’: ‘::’ の左側のシンボルには、型を指定しなければなりません
C:\…\HelpPnt.hxx(72) : error C2039: ‘Point’ : ‘System’ のメンバではありません。
C:\…\HelpPnt.hxx(72) : error C2065: ‘Point’ : 定義されていない識別子です。
#using <System.Drawing.dll> を追加

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

CLI

今度は,C++/CLI .
以前作成した MFC プロジェクト MemStt を変更.
  Release 版プロジェクトのプロパティで,
    「構成プロパティ」-「全般」-「共通言語ランタイム…」を「/clr」に.
      ビルドすると確かにファイルサイズは大きくなる.
  Debug 版だと,
    cl : コマンド ライン error D8016 : コマンド ライン オプション ‘/RTC1’ と ‘/clr’ は同時に指定できません
      正しい対応方法はわからないが,vcproj をエディタで開いて,BasicRuntimeChecks=”3″ を削除.


Form クラスに MemoryStatusAry を確保すると,
  c:\~\Form1.h(26) : error C4368: ‘MemSA’ をマネージ ‘MemSF::Form’ のメンバとして定義できません。
    MemoryStatusAry* MemSA とすることで対応?

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

VC 7 で error C2664 std::vector

VC 6 では通っていたが,VC 7 でエラーとなってそのままだったコード.
std::vector <void*> voidPtrs(1024,NULL) ;


c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\vector(124) : error C2664:
‘std::vector >::_Construct_n’ : 2 番目の引数を ‘int’ から ‘void *const & ‘ に変換できません。
理由: ‘int’ から ‘void *const ‘ へは変換できません。
整数型からポインタ型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\vector(109) :
コンパイルされたクラスのテンプレートのインスタンス化 ‘void std::vector<_Ty,_Ax>::_Construct(_Iter,int,std::_Int_iterator_tag)’ の参照を確認してください
with
[
_Ty=void *,
_Ax=std::allocator,
_Iter=int
]
c:\~\~.cpp(206) : コンパイルされたクラスのテンプレートのインスタンス化
‘std::vector<_Ty,_Ax>::vector(_Iter,int)’ の参照を確認してください
with
[
_Ty=void *,
_Ax=std::allocator,
_Iter=int
]


(void*) とすることで通るみたい.
std::vector <void*> voidPtrs(1024,(void*)NULL) ;

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

MFC と STL – 2

Xml_E で,MFC を使用しない様に変更中.
XML のデータを用意して,以下の様に単純に 100 個の配列にコピーする時間を計測しようとした.
   ElapseTick et ;
   CArray xmlAry ;                   // std::vector xmlAry ;
   for (int index=0 ; index<100 ; index++) {
     xmlAry.Add(Xml_Data) ;           // xmlAry.push_back(Xml_Data) ;
     }
   CString etStr = ::ToString(et.GetElapse()/1000.0) ;
   m_CtrlResult.SetWindowText(etStr) ;
データによっては期待した結果(MFC 版と同等またはそれより高速)が出たが,
この SVG を使用してメモリが少ない環境では極端に遅くなってしまった.
そこで,それぞれのサイズを調べてみた.

VC 6 VC 7 VC 8 VC 9 VC 10 VC 8 Debug VC 9 Debug VC 10 Debug VC 8 x64 VC 9 x64 VC 10 x64 VC 9 x64 Debug VC10 x64 Debug Xcode 64 Debug
CString 4 4 4 4 4 4 4 4 8 8 8 8 8
CArray 20 20 20 20 20 20 20 20 40 40 40 40 40
tstring 16 28 28 28 28 32 32 32 40 40 40 48 48 8
vector 16 16 16 24 16 20 20 20 32 48 32 40 40 24
Xml_E 68 92 92 108 92 108 108 108 152 184 152 184 184 72

tstring は,std::string または std::wstring .
vector は, <int> のサイズ.sizeof (std::vector<bool>) は vector<int> などより大きくなることがあるみたい.
Xml_E の MFC 版のデータメンバは,
CString Name , CString Text , CArray<Xml_Attribute,Xml_Attribute> Attribute , CArray<Xml_E,Xml_E> Child .
STL 版は tstring と std::vector に置換えた.

MFC Xml_Attribute 12 4 + 4*2
MFC Xml_E 52 4 + 4*2 + 20*2
STL Xml_Attribute 36 4 + 16*2
STL Xml_E 68 4 + 16*2 + 16*2

2013/04/22
SVG の全要素数は 5,557 ,属性は 19,103 .MFC 版では 518,200 ,STL 版では 1,065,584 となる.
つまり 50 M ~ 100 M 位が一時的に必要となってしまっていた(200 個にした時もあり).


ループ部分を 2 重ループとして,内側を 10 で 10 個の配列が必要となる様に改良.
時間を計測すると環境にもよるがほぼ同等の結果が得られた,
T5400 では MFC 6 秒と STL 3 秒.

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

MFC と STL

MFC STL
CString::Right など string::substr
LPCTSTR string::c_str
LPTSTR CString::GetBuffer()    -
CString::ReverseFind() string::rfind
   - string::find_last_not_of

Xcode で,#include “..\Test\Test.h” は通らない?
バックスラッシュではなく通常のスラッシュ ‘/’ とすれば OK (VC 6 でも通る).


2013/03/04
CString::GetBuffer() にあたる部分を,string::begin() とすると VC 6 では通る(たまたま通っているだけ).
  #ifdef _MBCS
  {
    // tstring tmpStr = str + _T(“”) ;
    // _tcsrev(tmpStr.begin()) ;
    std::vector tmpStr ;
    tmpStr.resize(str.length()+1) ;
    _tcscpy(&tmpStr[0],str.c_str()) ;
    _tcsrev(&tmpStr[0]) ;
    // ….
    }
  #endif
昨日立ち読みした方法に改良.確かこんなんだったと思う.

2013/03/07
VC 7 でコンパイルすると,
  c:\…\Test.cpp(45) : error C2664: ‘_tcsrev’ :
    1 番目の引数を ‘std::basic_string::iterator’ から ‘char *’ に変換できません。

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

_T(‘C’)

_T(“String”) の様な文字列の場合の動作は理解していたつもりでいたが,…
文字の場合も,同様に _T(‘C’) とはすぐ思いつかなかった.
7 bit の文字範囲で処理している時はあまり関係ないが,半角カナなどを扱う所でちょっと引っかかったので.
当然と言えば当然だが,ちょっと勘違いしてた.

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

error C2065 _lpa

T2OLE を利用したら,
——————–構成: Test – Win32 Debug——————–
コンパイル中…
Test.cpp
C:\…\Test.cpp(81) : error C2065: ‘_lpa’ : 定義されていない識別子です。
C:\…\Test.cpp(81) : error C2440: ‘=’ : ‘char *’ から ‘int’ に変換することはできません。(新しい動作 ; ヘルプを参照)
この変換には reinterpret_cast, C スタイル キャストまたは関数スタイルのキャストが必要です。
C:\…\Test.cpp(81) : error C2065: ‘_convert’ : 定義されていない識別子です。
cl.exe の実行エラー
Test.exe – エラー 3、警告 0

USES_CONVERSION; の指定がないとこれらのエラーが出力される.
テクニカル ノート 59


他に,今回テストに利用したサンプルで IID_PPV_ARGS が未定義となった.
動作確認が目的なので,c:\…\v7.0A\Include\ObjBase.h より対象部分の数行をコピーして利用.
COM のコーディング プラクティス

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

operator[]

以下の様なコードで,配列の要素として書き戻す部分がうまく機能してなかった.
BOOL d3D_PgonsA::SetUniqueName (void) {
  { // 空の場合 “Pgons_0x” を設定
    for (int index=0 ; index<this->GetCount() ; index++) {
      d3D_Pgons1 pgons = (*this)[index] ;
      CString name = pgons.GetName().c_str() ;
      if (name.IsEmpty()) {
        name.Format(_T(“Pgons1_%03d”),index+1) ;
        pgons.SetName(name) ;
        (*this)[index] = pgons ;
        continue ;
        }
      }
    }
  // …
  }
原因は, d3D_Pgons1& operator[] (const int index) が定義されてなかったためだが,未だによくわかってない.

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

MemStat.hxx

Xcode や VC , W Mobile で可能な様にコードを書いてみた.


#ifndef MemStat_hxx
#define MemStat_hxx
//
#ifdef _WIN32
  typedef __int64 i64 ;
  typedef unsigned __int64 ui64 ;
#else
  typedef long long i64 ;
  typedef unsigned long long ui64 ;
#endif
//
#ifdef __APPLE_CC__
  #include <mach/mach.h>
#endif
#ifdef _WIN32
  #include <Windows.h>
  #include <WinBase.h>
#endif
//
class MemoryStatus {
public:

} ;
//

{
  P_Free = P_Total = 0 ;
  #ifdef __APPLE_CC__
  {
    unsigned int count = 0 ;
    mach_port_t host_port = ::mach_host_self() ;
    host_basic_info_data_t hb_info;
    {
      count = HOST_BASIC_INFO_COUNT ;
      ::host_info(host_port,HOST_BASIC_INFO,(host_info_t)&hb_info,&count) ;
      }
    vm_statistics_data_t vm_info;
    {
      count = HOST_VM_INFO_COUNT;
      ::host_statistics(host_port,HOST_VM_INFO,(host_info_t)&vm_info,&count) ;
      }
    P_Free = vm_info.free_count * vm_page_size ;
    P_Total = hb_info.max_mem ;
    }
  #endif
  #ifdef _WIN32
  #if !defined(_WIN32_WCE) && (_MFC_VER >= 0x700)
  {
    MEMORYSTATUSEX memStat ;
    memset(&memStat,0,sizeof(MEMORYSTATUSEX)) ;
    memStat.dwLength= sizeof(MEMORYSTATUSEX) ;
    ::GlobalMemoryStatusEx(&memStat) ;
    P_Free = memStat.ullAvailPhys ;
    P_Total = memStat.ullTotalPhys ;
    }
  #else
  {
    MEMORYSTATUS memStat ;
    memset(&memStat,0,sizeof(MEMORYSTATUS)) ;
    memStat.dwLength= sizeof(MEMORYSTATUS) ;
    ::GlobalMemoryStatus(&memStat) ;
    P_Free = memStat.dwAvailPhys ;
    P_Total = memStat.dwTotalPhys ;
    }
  #endif
  #endif
  }
//
#endif


ファイルは,UTF-8 と言うか,シフトJIS の設定で,7 bit の範囲の文字のみ使用.
改行は,CR+LF としている.

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

C1083

—— ビルド開始 : プロジェクト : CalAxByC, 構成 : Debug Win32 ——
コンパイルしています…
StdAfx.cpp
c1xx : fatal error C1083: コンパイラの中間生成物 ファイルを開けません。’ .\Debug.070/CalAxByC.pch’: No such file or directory
CalAxByC – エラー 1、警告 0
———————- 終了 ———————-
ビルド : 0 正常終了、1 失敗、0 スキップ

出力ディレクトリなどの指定で .\$(ConfigurationName).070 の前にスペースが入っていた.


「UNICODE 文字セットを使用する」にすると,
—— ビルド開始 : プロジェクト : CalAxByC, 構成 : Debug Win32 ——
コンパイルしています…
CalAxByC.cpp
リンクしています…
LINK : warning LNK4075: /EDITANDCONTINUE は /INCREMENTAL:NO の指定によって無視されます。
msvcrtd.lib(wcrtexew.obj) : error LNK2019: 未解決の外部シンボル _wWinMain@16 が関数 _wWinMainCRTStartup で参照されました。
.\Debug.070/CalAxByC.exe : fatal error LNK1120: 外部参照 1 が未解決です。
CalAxByC – エラー 2、警告 1
———————- 終了 ———————-
ビルド : 0 正常終了、1 失敗、0 スキップ

この対応方法は vcproj を編集

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

コード分析による修正

VC 9

~\CharFnc.hxx(155) : warning C6284: オブジェクトがパラメータ '3' として渡されました。
~\CharFnc.hxx(155) : warning C6284: オブジェクトがパラメータ '5' として渡されました。
  str.Format(_T("(%*s,%*s)"),width,        ToString(value.x) ,width,        ToString(value.y) ) ;
  str.Format(_T("(%*s,%*s)"),width,LPCTSTR(ToString(value.x)),width,LPCTSTR(ToString(value.y))) ;
  間違って LPCSTR としてしまうと,_UNICODE では
    error C2440: '' : 'CString' から 'LPCSTR' に変換できません。
  LPSTR としてしまうと,
    error C2440: '' : 'CString' から 'LPSTR' に変換できません。
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

VC 7.1 メモリウィンドウ

VC71 Memory UNICODE

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