ホーム » 2013 » 8月

月別アーカイブ: 8月 2013

2013年8月
 123
45678910
11121314151617
18192021222324
25262728293031

カテゴリー

アーカイブ

ブログ統計情報

  • 79,652 アクセス



sh でエラー

sh を作成して実行すると,
  iwao@VB-Ubuntu:~/Documents$ sh mount_error.sh
  mount_error.sh: 1: mount_error.sh: sudo: not found
以前作成したものと比較したが,Ubuntu 上では見分けがつかなかった.
Windows 環境にコピーして,MIFES で開くとそれぞれで文字コードが異なる.
エラーになる sh をバイナリで開くと,EF BB BF が付加されていた.
どうも Ubuntu 上で利用したツールで,保存時に UTF-8 BOM 付としてしまったみたい.

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

Xcode でのデバッグ?

Xcode でのデバッグ
::To_tstring_rz で,str[index] = sp としていたため.
  sp はデフォルトでは _T(‘\0’) で,_T(‘ ‘) なども指定できるようにしている.
  対応としては,return する前に c_str() とすることにした.

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

ostrstream の利用でメモリリーク

次の様なコードでメモリリーク.freeze(false) がなかったのが原因.


tstring To_tstring (const double v,const int w=0,const int p=6,const long f=0) {
  tstring str ;
  std::ostrstream strBuf ;
  if (f != 0) {
    strBuf.flags(f) ;
    }
  {
    strBuf.width(w) ;
    strBuf.precision(p) ;
    }
  {
    strBuf << v ;
    strBuf << std::ends ;
    }
  {
    str = strBuf.str() ;
  // strBuf.rdbuf()->freeze(false) ;
    }
  return str ;
  }


Detected memory leaks!
Dumping objects ->
{385} normal block at 0x00038168, 512 bytes long.
Data: < 1.05 > 20 20 31 2E 30 35 00 CD CD CD CD CD CD CD CD CD
{363} normal block at 0x00037F20, 512 bytes long.
Data: <233.50 > 32 33 33 2E 35 30 00 CD CD CD CD CD CD CD CD CD
{339} normal block at 0x00037C70, 512 bytes long.
Data: < 967 > 20 20 20 39 36 37 00 CD CD CD CD CD CD CD CD CD
{315} normal block at 0x00037A28, 512 bytes long.
Data: < 875 > 20 20 20 38 37 35 00 CD CD CD CD CD CD CD CD CD
{291} normal block at 0x000377E0, 512 bytes long.
Data: < 997 > 20 20 20 39 39 37 00 CD CD CD CD CD CD CD CD CD
{269} normal block at 0x00037598, 512 bytes long.
Data: < 1.08 > 20 20 31 2E 30 38 00 CD CD CD CD CD CD CD CD CD
{245} normal block at 0x00037350, 512 bytes long.
Data: < 955 > 20 20 20 39 35 35 00 CD CD CD CD CD CD CD CD CD
{223} normal block at 0x00037108, 512 bytes long.
Data: < 1.15 > 20 20 31 2E 31 35 00 CD CD CD CD CD CD CD CD CD
{201} normal block at 0x00036EC0, 512 bytes long.
Data: < 1.02 > 20 20 31 2E 30 32 00 CD CD CD CD CD CD CD CD CD
{169} normal block at 0x000369B8, 512 bytes long.
Data: < 1.06 > 20 20 31 2E 30 36 00 CD CD CD CD CD CD CD CD CD
{143} normal block at 0x00036770, 512 bytes long.
Data: < 1003 > 20 20 31 30 30 33 00 CD CD CD CD CD CD CD CD CD
Object dump complete.
スレッド 0xDEC 終了、終了コード 0 (0x0)。
プログラム ‘C:\…\DmpFS\Debug\DmpFS.exe’ はコード 0 (0x0) で終了しました。


MSDN strstreambuf::freeze


2013/08/26
上のコードを Xcode でビルドすると,strBuf.flags(f) の所で
    /Volumes/…/t_string.hxx:47:10: No matching member function for call to ‘flags’
  利用する前に fmtflags 型にして利用する様に変更.
    std::ios_base::fmtflags f = std::ios_base::fmtflags(f_) ;


2013/08/28
_UNICODE に対応できなかったので,ostringstream を利用する様に変更.
  tstring To_tstring (const double v,const int w=0,const int p=6,const unsigned f_=std::ios::fixed) {
    tstring str ;
  #ifdef _UNICODE
    std::wostringstream strBuf ;
  #else
    std::ostringstream strBuf ;
  #endif
    std::ios_base::fmtflags f = std::ios_base::fmtflags(f_) ;
    if (f != 0) { strBuf.flags(f) ; }
    strBuf.width(w) ;
    strBuf.precision(p) ;
    strBuf << v ;
    str = strBuf.str() ;
    return str ;
    }

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

MFC 追加でメモリリーク

MFC を利用しないコードを VC 6 でテストしていて,
  コンソール AP として作成したスケルトンに,::oGetFileSize を追加.
  MFC を利用した,::GetFileSize と動作を比べるために,
    プロジェクトの設定を変更(共有 DLL で MFC を使用).
    main 関数が存在するソースに Afx.h などの include を追加.
  ビルドして実行すると,メモリリークが発生するようになった.
  main 関数内を全てコメントにしてもあまり変わらない.


MFC サポートありで,コンソール AP を作成.
  同様に oGetFileSize と GetFileSize を追加.
  ビルド,実行すると特に問題ない.
  StdAfx.h 内の Afx.h などを tmain のソース内に移動.
  リビルドすると,メモリリーク発生.
どうも,Afx.h より前の iostream などが関係している.
また,リビルドしないと現象が変わらない.


StdAfx.h に iostream の include を追加
  #define VC_EXTRALEAN
  #include <iostream>
  #include <afx.h>


Detected memory leaks!
Dumping objects ->
{51} normal block at 0x00032440, 33 bytes long.
 Data: < C              > 00 43 00 CD CD CD CD CD CD CD CD CD CD CD CD CD 
{50} normal block at 0x00034F68, 40 bytes long.
 Data: < |L             > 14 7C 4C 10 16 00 00 00 00 00 00 00 00 00 00 00 
Object dump complete.
スレッド 0x1218 終了、終了コード 0 (0x0)。
プログラム 'C:\...\T_Con2\Debug\T_Con2.exe' はコード 0 (0x0) で終了しました。

iostream のインクルードを afx.h より後にすることで対応.

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

open で errno = 13

ファイルにより,open で errno に 13 EACCES Permission denied が設定される.
  bool Get_fstat (LPCTSTR name,struct stat* fs) {
    if (fs == NULL) { return false ; }
    int fh = _topen(name,O_RDONLY) ;
    if (fh < 0) { i_Dump(errno) ; }
    if (fh < 0) { return false ; }
    memset(fs,0,sizeof(struct stat)) ;
    int ret = fstat(fh,fs) ;
    _close(fh) ;
    return (ret == 0) ;
    }
__FILE__ などは期待した動作だが,c:\pagefile.sys でエラーとなった.


VC 6 では,~\VC98\CRT\SRC\OPEN.C で CreateFile を呼出している.
その時の値は,
fileaccess 0x80000000
fileattrib 0x00000080
filecreate 0x00000003
fileshare 0x00000003
osfh 0x0013fef0
+ path 0x000326d1 “c:\pagefile.sys”
+ &SecurityAttributes 0x0013fdbc

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

circle.svg の Load で…

circle.svg の Load で,
‘System.Xml.XmlException’ の初回例外が System.Xml.dll で発生しました。
‘System.Xml.XmlException’ のハンドルされていない例外が System.Xml.dll で発生しました。
追加情報: セキュリティ上の理由から、DTD はこの XML ドキュメントでは使用できません。
DTD 処理を有効にするには、XmlReaderSettings の ProhibitDtd プロパティを False に設定し、XmlReader.Create メソッドにその設定を渡してください。
circle.svg load
<?xml version=”1.0″ standalone=”no”? >
<!DOCTYPE svg PUBLIC “-//W3C//DTD SVG 1.1//EN” “http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd” >
<svg width=”320pt” height=”224pt” viewBox=”0 0 100 70″ xmlns=”http://www.w3.org/2000/svg” >
<circle cx=”30″ cy=”25″ r=”20″ fill=”orange”/>
<circle cx=”50″ cy=”35″ r=”20″ stroke-width=”4″ stroke=”brown” fill=”coral”/>
<circle cx=”70″ cy=”45″ r=”20″ stroke-width=”4″ stroke=”chocolate” fill=”none”/>
</svg>


これは,MSXML.dll を利用した場合も正しく読み込めていない(Xml_Import で対応).
Xml_Fnc.hxx の Xml_Import を MFC を利用しない様に書き直した時にもう一度考える.
現状の XmlI_MS や Xml_CLI は,DTD などが付加された xml には対応していない(Xml_Import では可能).

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

C4793 , C4279

Win 32 コンソール AP で MFC サポートのプロジェクトを作成.
/clr を有効にして,以下のコードで,


// L_xml_K.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
#include "StdAfx.h"
#include "L_xml_K.h"
#include "Xml_CLI.hxx"
#include "XmlOut.hxx"
#include "Xml_MS_.hxx"
#undef GetTempPath
#using <System.dll>
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
// 唯一のアプリケーション オブジェクトです。
CWinApp theApp;
using namespace std;
 
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
  int nRetCode = 0;
  if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
    _tprintf(_T("致命的なエラー: MFC の初期化ができませんでした。\n"));
    nRetCode = 1;
    }
  else {
    System::String^ tmp = System::IO::Path::GetTempPath() ;
    System::String^ url = tmp + "211626.svg" ;
    tstring inXml = ::to_tstring(url) ;
    Xml_E xe_CLI = XmlI_CLI::Import(inXml.c_str()) ;
    Xml_E xe_MFC = XmlI_MS ::Import(inXml.c_str()) ;
    tstring outCLI = inXml + _T("_CLI.svg") ;
    tstring outMFC = inXml + _T("_MFC.svg") ;
    XmlOut::Export(xe_CLI,outCLI.c_str()) ;
    XmlOut::Export(xe_MFC,outMFC.c_str()) ;
    }
  return nRetCode;
  }

—— すべてのリビルド開始: プロジェクト: L_xml_K, 構成: Debug Win32 ——
プロジェクト ‘L_xml_K’、構成 ‘Debug|Win32’ の中間出力ファイルを削除しています。
コンパイルしています…
StdAfx.cpp
コンパイルしています…
L_xml_K.cpp
c:\…\CRT_MBWC.hxx(179) : warning C4793: ‘vararg’ : 関数 ‘BOOL StPrintF(LPTSTR,size_t,LPCTSTR,…)’ 用に
  ネイティブ コードの生成が発生します
  c:\…\CRT_MBWC.hxx(149) : ‘StPrintF’ の宣言を確認してください。
C:\…\Xml_MS_.hxx(14) : warning C4279: ‘value’: タイプ ライブラリ ‘msxml.dll’ の識別子はキーワードです。
  ’rename’ 修飾子を使用してください。
C:\…\Xml_MS_.hxx(14) : warning C4279: ‘value’: タイプ ライブラリ ‘msxml.dll’ の識別子はキーワードです。…
C:\…\Xml_MS_.hxx(14) : warning C4279: ‘value’: タイプ ライブラリ ‘msxml.dll’ の識別子はキーワードです。…
C:\…\Xml_MS_.hxx(14) : warning C4279: ‘value’: タイプ ライブラリ ‘msxml.dll’ の識別子はキーワードです。…
C:\…\Xml_MS_.hxx(14) : warning C4279: ‘value’: タイプ ライブラリ ‘msxml.dll’ の識別子はキーワードです。…
C:\…\Xml_MS_.hxx(14) : warning C4279: ‘value’: タイプ ライブラリ ‘msxml.dll’ の識別子はキーワードです。…
C:\…\Xml_MS_.hxx(14) : warning C4279: ‘value’: タイプ ライブラリ ‘msxml.dll’ の識別子はキーワードです。…
リソースをコンパイルしています…
リンクしています…
マニフェストを埋め込んでいます…
L_xml_K – エラー 0、警告 8
========== すべてリビルド: 1 正常終了、0 失敗、0 スキップ ==========


C4793 は,可変個引数リストの関数のため.
  コンパイラの警告 (レベル 1 および 3) C4793
C4279 は検索すると,
  having MSXML warnings
  Why warning C4279 happens?


C4279 は,今回のプロジェクトのみの問題となると思われる.
  MSXML.dll と,System.Xml.dll を同一プロジェクトでは利用しない様にするため.
  今回は,それぞれで読込み,単純に書き込む動作のデバッグのためにプロジェクトを作成した.

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

C++ System::Xml::XmlReader

Visual C++ を使用して、ファイルから XML データを読み取る
Netting C++ XML による構成
XmlNode メンバ
  XmlNode.Attributes プロパティ
  XmlNode.ChildNodes プロパティ


System::Xml を利用した読込のコードを作成していて,テスト用のコードで
—— ビルド開始: プロジェクト: L_xml_I, 構成: Debug Win32 ——
コンパイルしています…
L_xml_I.cpp
.\L_xml_I.cpp(182) : error C2039: ‘GetTempPathW’ : ‘System::IO::Path’ のメンバではありません。
c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : ‘System::IO::Path’ の宣言を確認してください。
.\L_xml_I.cpp(182) : error C2660: ‘GetTempPathW’ : 関数に 0 個の引数を指定できません。
L_xml_I – エラー 2、警告 0
========== ビルド: 0 正常終了、1 失敗、0 更新、0 スキップ ==========
  Windows.h をインクルードしてはいけない?
  使用する前?に以下を追加.
    #undef GetTempPath


2020/07 https://jml.mish.work/index.php/cpp/xml.html


2019/01 C++ と STL の範囲で書き直し
リンク先に msxml.dll などを使用しない C++ で書いたコードを置いています.


2019/08 System.Xml.dll と msxml.dll を使用したコードへのリンクを追加
xml_base.hxx
Str_CLI.hxx
Xml_CLI.hxx
Xml_MS_.hxx
Xml_In.hxx

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

tlbimp

今度は「COM 相互運用機能」ってやつ.
Tlbimp.exe を利用して,AsFile.tlb を ISFile.dll として出力.
  SDK コマンドプロンプトを開き,~\ReleaseU のフォルダに移動.
  tlbimp AsFile.tlb ISFile.dll
C# フォームアプリケーションを作成して,ボタンを配置.
  参照の追加で,iSFile.dll を追加.
    using iSFile; を追加.
    private void button1_Click(object sender,EventArgs e) {
      iSFile.SearchF srchF = new iSFile.SearchF() ;
      string selFile = srchF.BrowseFile(“%Temp%\\”,””) ;
      MessageBox.Show(selFile) ;
      }
同様の動作の vbs での呼び出しは,
  dim oFSch : set oFSch = CreateObject(“AsFile.SearchF”)
  selFile = oFSch.BrowseFile(“%Temp%\”,””) ;
  MsgBox x
以前聞いた時には,もっと面倒なイメージがあったがそれ程でもない.
  ただ COM の部分が確定していない(平行してコードを書いている)時は面倒なのかも.


同様に AsHVR.exe をやってみたら,実行時エラー.
型 ‘AsHVR.AsHVRClass’ の COM オブジェクトをインターフェイス型 ‘AsHVR.IAsHVR’ にキャストできません。
IID ‘{1625D8E7-B67B-4592-878F-ECFAD1227734}’ が指定されたインターフェイスの COM コンポーネント上での QueryInterface 呼び出しのときに次のエラーが発生したため、この操作に失敗しました:
インターフェイスがサポートされていません (HRESULT からの例外: 0x80004002 (E_NOINTERFACE))。
0x80004002 (E_NOINTERFACE)
これが面倒だったのかも?


他にも,T54W7U64 環境で,DevXP\~\CSCallL\bin\Debug\CSCallL.exe を起動して,「ボタン 1」 もエラーとなる.
  これは,AsFile.dll の 64 ビット版がないことによるものと思うが,…
  うまい方法がよくわからない.


2013/08/06
既存の AsHVR.exe などがうまく動作しないのは変わらないが,
  VC 8 で新規に MFC ダイアログベースのプロジェクト TstComE を作成.オートメーションを有効に.
  メソッド GetTmpPath を追加して実行するとうまくいった.


C++/CLI コンソール AP として作成.
// CPCallL.cpp : メイン プロジェクト ファイルです。
#include "stdafx.h"
using namespace System;
using namespace System::Windows::Forms;
int main(array<System::String ^> ^args)
{
  {
    iSFile::SearchF^ srchF = gcnew iSFile::SearchF();
  // String^ selFile = srchF->BrowseFile("%Temp%\\","") ;
  // MessageBox::Show(selFile) ;
    }
  {
    AsHVR::AsHVR^ hmpvr = gcnew AsHVR::AsHVR();
  // String^ key = hmpvr->GetKeySP();
  // MessageBox::Show(key);
    }
  {
    TstComE::TstComE^ tce = gcnew TstComE::TstComE() ;
    String^ tmpFile = tce->GetTmpPath() ;
    MessageBox::Show(tmpFile) ;
    }
  return 0;
  }
今度は TstComE 以外うまく動作しない.

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

CLI MSDN のサンプルなど

連載! とことん VC++
  第 8 回 C++/CLI を利用した相互運用 ~ネイティブ C++ から .NET の利用~
  第 9 回 C++/CLI を利用した相互運用 ~.NET からのネイティブ C++ 資産の再利用~


VC++ 2010 Express などが対象となっている.
インストールなしで用意できた環境が VS 2008 だったが,特に問題なく進められた.


メニューの「プロジェクト」-「参照の追加」は,VC 2003 以降?
VC 2005 , VC 2008 では,ソリューションエクスプローラのプロジェクトの下に「参照設定」がない?
  VC 2003 には存在するので.
VC 2002 では,プログラミング VisualC++.NET Vol.2 429 ページで
  #using <..\Ex32a\Debug\Ex32a.dll> となっている.


さまざまな文字列型間で変換する
Visual C++ で System::String* から char* に変換する方法
System::String を wchar_t* または char* に変換する
BUG: The VC++ .NET or VC++ 2005 debugger cannot display std::string and std::wstring variables correctly


2013/08/05
C++/CLI を用いて、.NET 対応アプリケーションから MFC 対応クラスを使用する
  慣れかもしれないが,ちょっと面倒に感じる.

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

Ubuntu で include

プラットフォームに依存しない C++ コードのコンパイルのテストなどを目的に,Ubuntu 環境に設定中…
MonoDevelop で,プロジェクトごと?のインクルードパスの設定は見つけた.
  メニューの「プロジェクト」の一番下に「~のオプション」.
  「ビルド」-「コード生成方法」-「パス」のタブ.
テストしたい(共通の)コードはネットワーク上にあるので,WinXP 上の Eclipse では,環境変数を利用していた.
  DEVXP_SRC=\\DevXP\C_Drive\~\Develop\_.SRC
  C_INCLUDE_PATH=%DEVXP_SRC%\__CPR_:~
  CPLUS_INCLUDE_PATH=%C_INCLUDE_PATH%
Mac では(Xcode では),設定がよくわからず,main.cpp にフルパスで書いていた.
  #include “/Volumes/C_Drive/~/_.SRC/Test/TestMem.cpp”


Linux ではマウントする必要があるみたいでここを参考にさせてもらって設定.
  この時,sudo mount -t smbfs //devxp/c_drive /mnt/~ で
    mount error: could not resolve address for devxp: Unknown error
  sudo mount -t smbfs //192.168.0.10/c_drive ~ で通る様になった.
MonoDevelop で,/mnt/DevXP/C_Drive/~ を指定してコンパイルが通る様になった.
また,Eclipse でもメニューの「プロジェクト」-「プロパティ」,「C/C++ 一般」-「パスおよびシンボル」に設定がある.


環境変数としての設定はちょっとわからず.やったとこまで.
  DEVXP_SRC=”/mnt/DevXP/C_Drive/Documents and Settings/~/_.SRC”
  ” または ‘ でくくる必要がある?
  ls などの時は,ls “$DEVXP_SRC”  (シングルクォーテーションではうまくないみたい).


2019/09/09
Linux から Windows 環境への接続
g++ インクルードパスの設定

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