ホーム » VC (ページ 4)
「VC」カテゴリーアーカイブ
簡易 Web サーバ C++/CLI
先日の C# のコードから C++/CLI に書き直したものの 更新版 .
index.html の作成と,ContentType の設定,日本語ファイル名への対応など.
#ifdef __cplusplus_cli
#using <System.dll>
#using <System.Web.dll>
#include <vcclr.h>
#endif
///////////////////////////////////////////////////////////////////////////
#include "S_Exec.hxx"
#include "str_CLI.hxx"
#include "filestat.hxx"
#include "filepath.hxx"
#include "ask_path.hxx"
#include "itls_tmp.hxx"
#include "textfile.hxx"
#include "htmout.hxx"
#include "stringfn.hxx"
///////////////////////////////////////////////////////////////////////////
struct MIME_type {
LPCTSTR FExt ;
LPCTSTR Type ;
} ;
// https://developer.mozilla.org/ja/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
const MIME_type MIME_type_tbl[] =
{
_T("htm" ) , _T("text/html") ,
_T("html") , _T("text/html") ,
_T("txt" ) , _T("text/plain") ,
_T("bmp" ) , _T("image/bmp") ,
_T("jpeg") , _T("image/jpeg") ,
_T("jpg" ) , _T("image/jpeg") ,
_T("png" ) , _T("image/png") ,
_T("svg" ) , _T("image/svg+xml") ,
_T("bin" ) , _T("application/octet-stream") ,
_T("pdf" ) , _T("application/pdf") ,
_T("zip" ) , _T("application/zip") ,
_T(" " ) , _T("") ,
_T("\0" ) , _T("") ,
_T("" ) , _T("") ,
} ;
inline tstring get_MIME_type (LPCTSTR ext_)
{
tstring type = _T("application/octet-stream") ;
tstring ext = ::String_ToLower(ext_) ;
if (ext.empty()) {
return type ;
}
const MIME_type* mm_ty = MIME_type_tbl ;
{
for (size_t index=0 ; index<countof(MIME_type_tbl) ; index++)
{
tstring fext = mm_ty[index].FExt ;
tstring ftyp = mm_ty[index].Type ;
if (fext.length() == 0) { continue ; }
if (fext.length() != ext.length()) { continue ; }
if (ext == fext) {
return mm_ty[index].Type ;
}
}
}
return type ;
}
///////////////////////////////////////////////////////////////////////////
inline tstring HT_Make_index_content (c_tstring& fold)
{
v_tstring sub_folds = ::EnumFolders(fold.c_str()) ;
v_tstring htm_files = ::EnumFiles (fold.c_str(),_T("*.htm*")) ;
tstring foldName = ::Path_GetTitle(fold) ;
tstring htm_str ;
{
Xml_E htm = HtmOut::html() ;
{
Xml_E head(HTM_head) ;
{
head.AddChild(HtmOut::charset_UTF_8()) ;
head.AddChild(HtmOut::meta_viewport()) ;
head.AddChild(HtmOut::title(foldName)) ;
}
{
head.AddChild(HtmOut::comment()) ;
}
htm.AddChild(head) ;
}
{
Xml_E body(HTM_body) ;
{
{
body.AddChild(HtmOut::a_parent()) ;
body.AddChild(HtmOut::hr()) ;
}
{
for (size_t index=0 ; index<sub_folds.size() ; index++) {
tstring fold = sub_folds[index] ;
fold = ::Path_DelLastSP(fold) ;
Xml_E a_fold = HtmOut::a(::Path_GetName(fold)+_T("/")) ;
body.AddChild(a_fold) ;
body.AddChild(HtmOut::br()) ;
}
body.AddChild(HtmOut::hr()) ;
}
{
for (size_t index=0 ; index<htm_files.size() ; index++) {
tstring html = htm_files[index] ;
Xml_E a_html = HtmOut::a(::Path_GetName(html)) ;
body.AddChild(a_html) ;
body.AddChild(HtmOut::br()) ;
}
}
}
htm.AddChild(body) ;
}
htm_str = htm.ToText() ;
}
return htm_str ;
}
tstring Make_index (c_tstring& fold)
{
tstring result = ::HT_Make_index_content(fold) ;
return result ;
}
///////////////////////////////////////////////////////////////////////////
bool web_server (c_tstring& fold,const u_16 port)
{
tstring root_ = fold ;
tstring port_ = ::To_tstring(port) ;
tstring pref_ = _T("http://127.0.0.1:")+port_+_T("/") ;
System::String^ root = ::to_gcString(root_) ;
System::String^ prefix = ::to_gcString(pref_) ;
System::Console::WriteLine(prefix) ;
System::Net::HttpListener^ listener = gcnew System::Net::HttpListener();
listener->Prefixes->Add(prefix);
listener->Start();
while (true) {
System::Net::HttpListenerContext^ context = listener->GetContext();
System::Net::HttpListenerRequest^ req = context->Request;
System::Net::HttpListenerResponse^ res = context->Response;
System::String^ path = root + req->RawUrl->Replace("/", "\\");
path = System::Web::HttpUtility::UrlDecode(path) ;
{
System::Console::WriteLine(req->RawUrl);
System::Console::WriteLine(path) ;
}
if (System::IO::File::Exists(path)) {
}
if (System::IO::File::Exists(path)) {
tstring ext = ::Path_GetExtLow(::to_tstring(path)) ;
array<System::Byte>^ content = System::IO::File::ReadAllBytes(path);
res->ContentType = ::to_gcString(::get_MIME_type(ext.c_str())) ;
res->OutputStream->Write(content, 0, content->Length);
}
else {
tstring cnt_index = ::Make_index (::to_tstring(path)) ;
array<System::Byte>^ content ;
{
static long i_count = 0 ;
i_count++ ;
tstring tmp_path = ::Get_i_Tools_tmp_date() ;
tstring htm_name = ::To_tstring(port) + _T("_") + ::u32to0t(i_count,10,4) + _T(".htm") ;
tstring out_path = ::Path_AddLastSP(tmp_path) + htm_name ;
::SaveUTF8(out_path.c_str(),cnt_index) ;
content = System::IO::File::ReadAllBytes(::to_gcString(out_path.c_str())) ;
}
res->ContentType = ::to_gcString(::get_MIME_type(_T("htm"))) ;
res->OutputStream->Write(content, 0, content->Length);
}
res->Close();
}
return true ;
}
///////////////////////////////////////////////////////////////////////////
bool test (c_tstring& str)
{
tstring fold = str ;
{
if (::File_IsDirectory(fold)) { ; }
else { fold = ::Path_GetDir(fold) ; }
}
std::terr << fold << std::endl ;
{
u_16 tick = u_16(::GetTickCount()) ;
u_16 port = u_16(50000 + (tick&0x1fff)) ;
{
tstring port_ = ::To_tstring(port) ;
tstring pref_ = _T("http://127.0.0.1:")+port_+_T("/") ;
S_Exec se ;
se.SetFile(pref_.c_str()) ;
se.Execute() ;
}
::web_server(fold,port) ;
}
return true ;
}
///////////////////////////////////////////////////////////////////////////
int _tmain (int argc,_TCHAR* argv[])
{
tstring path ;
{
#ifdef OFN_filter_All
path = ::ask_path(false) ;
// path = ::ask_path(true) ;
#else
path = ::ask_cli(_T("folder ... ? =")) ;
#endif
}
if (!path.empty()) {
::test(path) ;
}
return 0;
}
///////////////////////////////////////////////////////////////////////////
#include "messbar.cxx"
* 幾つかのコードが揃っていないため,そのままではビルドできません.
https://jml.mish.work/index.php/i-tools/web-svr.html
2024/11/02
VC 2005 でビルド可能な一式を用意しました.
https://itl.mish.work/i_Tools/Doc/blog/vc/T_h_lstn.zip
C# のコードを C++/CLI に
先日の「簡易 Web サーバ C#」のコードを C++ で.
///////////////////////////////////////////////////////////////////////////////////
// C# -> C++/CLI
///////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <tchar.h>
//using System;
//using System.IO;
//using System.Net;
#using <System.dll>
bool test (void)
{
//
// class SimpleWebServer
// {
// static void Main()
// {
// string root = @"c:\wwwroot\"; // ドキュメント・ルート
// root = @".\";
System::String^ root = "./" ;
// string prefix = "http://*/"; // 受け付けるURL
// prefix = "http://127.0.0.1:65432/" ;
System::String^ prefix = "http://127.0.0.1:55555/" ;
//
// HttpListener listener = new HttpListener();
System::Net::HttpListener^ listener = gcnew System::Net::HttpListener();
// listener. Prefixes. Add(prefix); // プレフィックスの登録
listener->Prefixes->Add(prefix);
// listener. Start();
listener->Start();
//
// while (true) {
while (true) {
// HttpListenerContext context = listener. GetContext();
System::Net::HttpListenerContext^ context = listener->GetContext();
// HttpListenerRequest req = context. Request;
System::Net::HttpListenerRequest^ req = context->Request;
// HttpListenerResponse res = context. Response;
System::Net::HttpListenerResponse^ res = context->Response;
//
// Console. WriteLine(req. RawUrl);
System::Console::WriteLine(req->RawUrl);
//
// // リクエストされたURLからファイルのパスを求める
// string path = root + req. RawUrl. Replace("/", "\\");
System::String^ path = root + req->RawUrl->Replace("/", "\\");
//
// // ファイルが存在すればレスポンス・ストリームに書き出す
// if ( File. Exists(path)) {
if (System::IO::File::Exists(path)) {
// byte[] content = File. ReadAllBytes(path);
array<System::Byte>^ content = System::IO::File::ReadAllBytes(path);
// res. OutputStream. Write(content, 0, content. Length);
res->OutputStream->Write(content, 0, content->Length);
// }
}
// res. Close();
res->Close();
// }
}
// }
// }
//
return true ;
}
int _tmain(int argc, _TCHAR* argv[])
{
::test() ;
return 0;
}
VC 8 で C++/CLI
VC 10 ではある程度確認が取れたので,今度は VC 8 で.
先ず,コンソール AP .ビルドすると,
1>------ ビルド開始: プロジェクト: T_Con_1, 構成: Debug Win32 ------
1>コンパイルしています...
1>T_Con_1.cpp
1>EnumFile.hxx MessageBar No Support
1>C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include\vcclr.h(43) : error C2446: '!=' : 'int' 型から 'cli::interior_ptr<Type>' 型への変換ができません。
1> with
1> [
1> Type=unsigned char
1> ]
1>T:\Develop\_.SRC\_CLI\str_CLI.hxx(41) : error C2446: '==' : 'int' 型から 'System::String ^' 型への変換ができません。
1> 使用可能なユーザー定義された変換演算子がない、または
1> 演算型のボックス化された形式からターゲット型への標準変換は存在しません
1>T:\Develop\_.SRC\_CLI\str_CLI.hxx(61) : warning C4267: '初期化中' : 'size_t' から 'int' に変換しました。データが失われているかもしれません。
1>T:\Develop\_.SRC\_CLI\str_CLI.hxx(64) : warning C4267: '初期化中' : 'size_t' から 'int' に変換しました。データが失われているかもしれません。
1>T_Con_1 - エラー 2、警告 2
========== ビルド: 0 正常終了、1 失敗、0 更新、0 スキップ ==========
vcclr.h 内のエラーは,次の様に cpp の最初で vcclr.h を読み込むことで回避できる.
#ifdef __cplusplus_cli
#include <vcclr.h>
#endif
もう一つのエラーは次の所で,str が nullptr でないかを比較している所.
tstring to_tstring (System::String^ str)
{
if (str == nullptr) { return _T("") ; }
pin_ptr <const wchar_t> pStr = PtrToStringChars(str) ;
tstring tstr = pStr ;
return tstr ;
}
fatal error C1010
昨日から VC6 で開いたままだったプロジェクトをビルドすると,あまり見慣れないエラーが…
--------------------Configuration: AsTrmM - Win32 Debug--------------------
Compiling...
HProRNew.cpp
t:\develop\_.src\...\hprornew.cpp(113) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.
AsTrmM.exe - 1 error(s), 0 warning(s)
他の環境で試そうとプロジェクトを閉じようとすると,保存するかの問合せが入った.
保存された dsp と先日バックアップしたそれと比べると,不要な cpp が追加されていた.
ソースを開いた時,操作ミスで間違ってビルド対象に cpp が追加されてしまったみたい.
不要な cpp をプロジェクトから外して対応.うまくいった.
私の場合,自動生成される以外のソースは,次の様な複数の cpp をプロジェクトに追加して運用しています.
ComUse01.cpp
#include "StdAfx.h"
#include "ComPrj00.hpp"
#include "Point.cxx"
#include "Matrix.cxx"
// ...
ComPrj00.hpp
#include "i3DV.h" // App.h
#include "ColorHSV.hxx"
// ...
高 DPI ペンの幅
引き続きやっているが,なかなか難しい.
左は「非対応.exe」を「プロパティ」で「アプリケーション」にしたもの.
0.2 mm の指定で印刷する場合は問題ないが,27 インチ 4K では 1 ピクセルになり非常に見辛い.
今度は,VC 12 以降で「モニターごとの高い DPI 認識」としたもの.
Win7 では「非対応.exe」でも「アプリケーション」と指定したものの様な動作?
8.1 以降は,「DPI 認識」で指定したものが効いている?
4K 環境の Win10 で「非対応.exe」.
exe のプロパティで「システム(拡張)」としたもの.
0.3 mm の線を表示すると「システム(拡張)」としたものの方がきれい.
AP の作り方にもよると思うが,exe のプロパティで「システム(拡張)」としたものが一番良さそう.
「アプリケーション」にしてしまうと?,他のモニタに移動した時に大きさなどがうまくない.
::GetDpiForWindow
高 DPI 関連でいろいろと調べてみると ::GetDpiForWindow を使う必要がありそう.
ただ使えるのが Win10 1607 以降みたいで,その辺りをどうしたものか?
次の様に呼出せば 指定した hwnd の値が取れることは確認 .
#if (_MSC_VER >= 1900)
{
UINT dpi = ::GetDpiForWindow(hwnd) ;
std::terr << dpi << std::endl ;
}
#endif
ただ,旧 Windows では存在しないため実行時エラーになる.
そのため ::GetProcAddress を 利用した方法に .
// UINT GetDpiForWindow ( [in] HWND hwnd ) ;
typedef UINT (WINAPI* P_GDFW)(HWND) ;
UINT GetDPI (HWND hwnd)
{
UINT dpi = 96/2 ;
HMODULE user32 = ::GetModuleHandle(TEXT("user32.dll")) ;
P_GDFW p_GetDpiForWindow = (P_GDFW)::GetProcAddress(user32,"GetDpiForWindow") ;
if (p_GetDpiForWindow != NULL) {
dpi = p_GetDpiForWindow(hwnd) ;
}
else {
HDC hdc = ::GetDC(hwnd) ;
dpi = ::GetDeviceCaps(hdc,LOGPIXELSX) ;
::ReleaseDC(hwnd,hdc) ;
}
return dpi ;
}
解像度と DPI の関係が,まだうまく理解できていない.
::GetDpiForWindow は,指定した hwnd の DPI が取得できている.
::GetDeviceCaps では,プライマリの情報が取れる.
「非対応」の場合はスケーリングされた値,「モニターごと」の場合は 100% での値?
buf = string ( buf.c_str () )
先日の共通のコードでのバグ.
tstring ask_cli (LPCTSTR msg=_T(""))
{
tstring cli ;
while(true) {
tstring buf ;
buf.resize(1000) ;
std::terr << msg ;
std::tin.getline(&buf[0],std::streamsize(buf.size())) ;
// buf = ::QuotM_Del_All(buf.c_str()) ;
if (buf == _T("q")) { break ; }
else if (buf == _T("Q")) { break ; }
if (buf.empty()) { continue ; }
cli = buf.c_str() ;
break ;
}
return cli ;
}
ループを抜けるために “q” や “Q” と比較している部分が機能しない(break しない).
原因は “q\0\0\0…” と “q\0” を比べているため.
そのため,比較する前に次の様にするとうまく機能する.
{
tstring tmp = buf.c_str() ;
buf = tmp ;
}
MFC であれば CString::ReleaseBuffer(-1) が使えるが…
buf = tstring(buf.c_str()) とすることで対応.
::GetDeviceCaps(dc,HORZRES)
先日のコード を利用して,Windows API の動作のテスト.
#include <clocale>
#include <iostream>
#include "_tdefine.hxx"
#include "cmd_line.hxx"
#include "ask_cli.hxx"
//#include "ask_path.hxx"
#include <Windows.h>
bool test (c_tstring& str)
{
// std::terr << str << std::endl ;
HDC dc = ::GetDC(NULL) ;
if (dc != NULL) {
int hres = ::GetDeviceCaps(dc,HORZRES) ;
int vres = ::GetDeviceCaps(dc,VERTRES) ;
std::terr
<< _T("HORZRES=") << hres << _T("\t")
<< _T("VERTRES=") << vres << _T("\t")
<< std::endl ;
}
return true ;
}
int _tmain (int argc,TCHAR* argv[])
{
_tsetlocale(LC_ALL,_T("")) ;
{
::reg_argv (argc,argv) ;
}
{
// ::call_func(argc,argv) ;
}
{
::test(_T("Test")) ;
}
::ask_wait() ;
return 0 ;
}
::GetDpiForWindow を追加して FHD と 4K 環境で実行.
bool test (c_tstring& str)
{
HWND hwnd = ::GetConsoleHwnd() ;
{
HDC dc = ::GetDC(hwnd) ;
if (dc != NULL) {
int hres = ::GetDeviceCaps(dc,HORZRES) ;
int vres = ::GetDeviceCaps(dc,VERTRES) ;
std::terr
<< _T("HORZRES=") << hres << _T("\t")
<< _T("VERTRES=") << vres << _T("\t")
<< std::endl ;
}
}
// #ifdef DPI_AWARENESS_UNAWARE
{
HWND hwnd = ::GetConsoleHwnd() ;
UINT dpi = ::GetDpiForWindow(hwnd) ;
std::terr << dpi << std::endl ;
}
// #endif
return true ;
}
コンソール AP のための最初のコード
API などをテストするために,個人的に使用している C++ のコード.
#include <clocale>
#include <iostream>
#include "_tdefine.hxx"
#include "cmd_line.hxx"
#include "ask_cli.hxx"
//#include "ask_path.hxx"
bool test (c_tstring& str)
{
std::terr << str << std::endl ;
return true ;
}
inline bool call_func (int argc,TCHAR* argv[])
{
if (argc > 1) {
for (int index=1 ; index<argc ; index++) {
tstring av = argv[index] ;
::test(av) ;
}
}
else {
while(true) {
tstring path ;
{
#ifdef OFN_filter_All
path = ::ask_path(false) ;
#else
path = ::ask_cli(_T("file ... ? =")) ;
#endif
}
if (path.empty()) { break ; }
::test(path) ;
}
}
return true ;
}
int _tmain (int argc,TCHAR* argv[])
{
_tsetlocale(LC_ALL,_T("")) ;
{
::reg_argv (argc,argv) ;
}
{
::call_func(argc,argv) ;
}
{
::test(_T("Test")) ;
}
::ask_wait() ;
return 0 ;
}
//#include "messbar.cxx"
インクルードしているファイルは cpp6_hxx.zip にある.
上のコードを test.cpp などとして保存し,同じ所に zip を展開.
g++ test.cpp などでコンパイル可能.
これらを使用したコード.
https://dev.mish.work/wordpress/?s=reg_argv
Win11 22H2 と VC 6
昨日 Win11 環境に VS 2005 から 2022 をインストール .
その後,幾つかのコードをビルドして動作を確認.
仮想環境の Win11 22H2 で,KB5019509 の更新があった.
幾つか試したいことができたので,ホストの Win11 も 22H2 にしたくなった.
次の所から入って 22H2 をインストール.
https://www.microsoft.com/ja-jp/software-download/windows11/
1 時間程度かかった.
先日インストールした VC 6 を起動してみると…
うまく起動する.ビルドも問題なさそう.仮想マシンで動作していたのは 22H2 だったからか?
ステップ実行できない現象はあるが,何とか使える.
2022/10/23
ステップ実行した場合のメッセージが,仮想マシンと異なる.
仮想マシンは
—————————
Microsoft Visual C++
—————————
ハンドルされていない例外 は i3DV.exe (OLE32.DLL) にあります: 0xC0000005: Access Violation。
—————————
OK
—————————
ホストは
—————————
Microsoft Visual C++
—————————
OLE リモート呼び出しデバッグには管理者権限が必要です: この機能は使用できません。.
—————————
OK
—————————
「Win10 VC6 OLE」で検索すると,次の所が見つかった.
Windows10でVC6を使いたい
どうも「ツール」-「オプション」-「デバッグ」の「OLE RPC デバッグ」のチェックを外す必要があるらしい.
チェックを外す操作は,一度「ジャスト イン タイム デバッグ」にチェックを入れてから操作する必要がある.
RC4005: ‘IDR_MANIFEST’ : redefinition
VC6 から順に更新してきたプロジェクトをビルドしていると,warning RC4005: ‘IDR_MANIFEST’ : redefinition .
...
6>------ ビルド開始: プロジェクト:ClipView, 構成:Debug Win32 ------
6>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include\afxres.h(32): warning RC4005: 'IDR_MANIFEST' : redefinition
6>
6> Clip140.vcxproj -> c:\Temp\MICSTool\ClipView\Debug.140\ClipView.exe
6> Clip140.vcxproj -> c:\Temp\MICSTool\ClipView\Debug.140\ClipView.pdb (Full PDB)
========== ビルド: 6 正常終了、0 失敗、16 更新不要、0 スキップ ==========
resource.h を見ると,確かに IDR_MANIFEST が定義されている.
どのタイミングで追加したのかは覚えてないが,resource.h での定義は不要と思われるので削除.
Win11 に VS 6 のインストール
先日,Win11 環境に VS6 をインストールした.
手順は Win10 の時と同様 で,DB 関係が入らない様に.
VB6 は起動した.
が,VC6 は起動できない.
昨日,Win10 上の仮想マシンの Win11 に VS6 と SP6 をインストール.
この時 VC 6 は起動可能で,ビルド,デバッグなども動作した.
今日,それを確認すると,デバッグができなくなっている.
全くできないわけではないが,ブレークするとその後がうまくない.
何かが更新されて動作しなくなったのか?
Win11 上の仮想マシンとしての Win11 も,起動はできるがデバッグがうまくない.
Win10 の時もそうだったが,何かとの相性? … Win11 21H2 だったため.
2022/10/18
以前使っていた WinXP の VHD があったので,それを Win11 上の仮想マシンとして追加.
最近使ってなかったので,いろいろと問題が…
SMB1 や mklink .
なかなかいい運用が見つからない.
2022/10/23
22H2 に上げて うまく動作する様になった.
2023/10/30
VC 6 は,Win 10 ,11 で特に困ることはなく利用できている.
たまに使用する機能でうまくないのは「コンポーネントギャラリ」くらい?
Win11 はシステムドライブが SSD のため,$(OutDir) は「シンボリック リンク」にしている.
error LNK2019 : … _GdiplusStartup
VC 6 で作成したプロジェクトを VC 8 に上げてビルドすると…
------ ビルド開始: プロジェクト: DocTh, 構成: Debug Win32 ------
リンクしています...
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipCreateSolidFill@8 が関数 "public: __thiscall Gdiplus::SolidBrush::SolidBrush(class Gdiplus::Color const &)" (??0SolidBrush@Gdiplus@@QAE@ABVColor@1@@Z) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipDeleteBrush@4 が関数 "public: virtual __thiscall Gdiplus::Brush::~Brush(void)" (??1Brush@Gdiplus@@UAE@XZ) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipCloneBrush@8 が関数 "public: virtual class Gdiplus::Brush * __thiscall Gdiplus::Brush::Clone(void)const " (?Clone@Brush@Gdiplus@@UBEPAV12@XZ) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipFree@4 が関数 "public: static void __cdecl Gdiplus::GdiplusBase::operator delete(void *)" (??3GdiplusBase@Gdiplus@@SAXPAX@Z) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipAlloc@4 が関数 "public: static void * __cdecl Gdiplus::GdiplusBase::operator new(unsigned int)" (??2GdiplusBase@Gdiplus@@SAPAXI@Z) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipCreateLineBrushI@24 が関数 "public: __thiscall Gdiplus::LinearGradientBrush::LinearGradientBrush(class Gdiplus::Point const &,class Gdiplus::Point const &,class Gdiplus::Color const &,class Gdiplus::Color const &)" (??0LinearGradientBrush@Gdiplus@@QAE@ABVPoint@1@0ABVColor@1@1@Z) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipCreateFromHDC@8 が関数 "public: __thiscall Gdiplus::Graphics::Graphics(struct HDC__ *)" (??0Graphics@Gdiplus@@QAE@PAUHDC__@@@Z) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipDeleteGraphics@4 が関数 "public: __thiscall Gdiplus::Graphics::~Graphics(void)" (??1Graphics@Gdiplus@@QAE@XZ) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipSetSmoothingMode@8 が関数 "public: enum Gdiplus::Status __thiscall Gdiplus::Graphics::SetSmoothingMode(enum Gdiplus::SmoothingMode)" (?SetSmoothingMode@Graphics@Gdiplus@@QAE?AW4Status@2@W4SmoothingMode@2@@Z) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipFillRectangle@24 が関数 "public: enum Gdiplus::Status __thiscall Gdiplus::Graphics::FillRectangle(class Gdiplus::Brush const *,float,float,float,float)" (?FillRectangle@Graphics@Gdiplus@@QAE?AW4Status@2@PBVBrush@2@MMMM@Z) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipFillRectangleI@24 が関数 "public: enum Gdiplus::Status __thiscall Gdiplus::Graphics::FillRectangle(class Gdiplus::Brush const *,int,int,int,int)" (?FillRectangle@Graphics@Gdiplus@@QAE?AW4Status@2@PBVBrush@2@HHHH@Z) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdipFillPie@32 が関数 "public: enum Gdiplus::Status __thiscall Gdiplus::Graphics::FillPie(class Gdiplus::Brush const *,float,float,float,float,float,float)" (?FillPie@Graphics@Gdiplus@@QAE?AW4Status@2@PBVBrush@2@MMMMMM@Z) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdiplusStartup@12 が関数 "public: static int __cdecl UseGdiPlus::Startup(void)" (?Startup@UseGdiPlus@@SAHXZ) で参照されました。
ComNGP01.obj : error LNK2019: 未解決の外部シンボル _GdiplusShutdown@4 が関数 "public: static int __cdecl UseGdiPlus::Shutdown(void)" (?Shutdown@UseGdiPlus@@SAHXZ) で参照されました。
c:\Temp\iShellE\DocTh\Debug.080/DocTh.exe : fatal error LNK1120: 外部参照 14 が未解決です。
DocTh - エラー 15、警告 0
========== ビルド: 0 正常終了、1 失敗、0 更新、0 スキップ ==========
リンク対象に Gdiplus.lib を追加して対応.
VC 2022 ビルドでエラー
VC 2022 でビルドしようとすると,次の様なエラー.
—————————
Microsoft Visual Studio
—————————
オブジェクト参照がオブジェクト インスタンスに設定されていません。
—————————
OK
—————————
プロジェクトの設定などを見直しても特に怪しい部分はなさそう.
ビルド時に生成される幾つかのファイルを手動で削除しても特に変わらない.
さっきまで動作していた VC 2019 も同様のエラーに.
以前うまく動作しているはずのプロジェクトをコピーして,ビルドしようとしても同様.
こうなると,プロジェクトの設定ではなく,環境っぽい.
PC を再起動してうまく動作する様になった.
…\System32\MicrosoftEdgeCP.exe
…\System32\MicrosoftEdgeCP.exe が存在するのに,stat などでうまく読み取れない.
ファイルが存在しているかどうかをチェックするために,CFileStatus などを利用している.
CFileStatus::GetStatus() で,幾つかのファイルが正しくチェックできない.
コードをデバッガで追いかけていくと,::FindFirstFile で INVALID_HANDLE_VALUE となってしまう.
検索 すると次の様なものがあった.
FindFirstFile関数はx64環境においてシステムファイルが検索できない?
x86 の場合次のものを呼出して切替える必要があるみたい.
Wow64DisableWow64FsRedirection
Wow64RevertWow64FsRedirection
File System Redirector
今回 ::GetFileVersionInfo から始まって … いろいろとあったのでメモ.
VC 14 以降での stat.c の場所
VC 14 以降,<sys/stat.h> 関係が大きく変更されている?
CFileStatus でアサート
今回 stat 関数内をデバッグしようとしていて,ソースの場所がすぐにわからなかった.
#ifdef _MSC_VER
#define s_stat struct _stati64
#define TSTAT _tstati64
#else
#define s_stat struct stat
#define TSTAT stat
#endif
VC 12 以前は,(VS)\VC\crt\src\ 以下に存在する.
VC で,#include <sys/stat.h> としている所を「右クリック」-「ドキュメント<sys/stat.h>を開く」.
その位置を幾つか上に行って,Include の並びに Source があり,その対応する所に存在する.
VC 2015 以降のどれかで対応がつくと,それ以外でも対応したもの(10.0.?????.0)が開かれる?
VC 2019 以降の include
%LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props がないとの問い合わせが…
次の所は以前まとめたもの.VC 2010 以降は,これが引き継がれるものと思っていた.
VC include lib のパス
私の環境の VC 2022 で確認すると,ちゃんと引き継がれている.
検索すると VC 2019 から Microsoft.Cpp.Win32.user.props は使用されなくなった?
Microsoft.Cpp.Win32.user.props file missing
Visual Studio プロジェクトの設定を共有または再利用する
今の所は Win32 のみなので,また今度時間がある時に調べる.
VC Linux の include 設定
vector<long> などを文字列に
std::vector<long> の文字列への変換.
何年も前に書いたコードで,使い方を忘れているのでそのまとめ.
次の様な関数を用意している.
template <class VX> tstring Vx_To_tstring(const VX& vx,LPCTSTR sp=_T(" "))
次の様な使い方で long の配列を文字列へ変換できる.
tstring vl_str = ::Vx_To_tstring<v_long>(long_ary) ;
C4995: ‘gets’: 名前が避けられた …
.lnk 関係の ResolveIt をやっていて strsafe.h を使用すると…
1>------ ビルド開始: プロジェクト: T_path_l, 構成: Debug Win32 ------
1>コンパイルしています...
1>T_paht_l.cpp
1>c:\program files (x86)\microsoft visual studio 8\vc\include\cstdio(33) : warning C4995: 'gets': 名前が避けられた #pragma として記述されています。
1>c:\program files (x86)\microsoft visual studio 8\vc\include\cstdio(37) : warning C4995: 'sprintf': 名前が避けられた #pragma として記述されています。
1>c:\program files (x86)\microsoft visual studio 8\vc\include\cstdio(40) : warning C4995: 'vsprintf': 名前が避けられた #pragma として記述されています。
1>c:\program files (x86)\microsoft visual studio 8\vc\include\cstring(20) : warning C4995: 'strcat': 名前が避けられた #pragma として記述されています。
1>c:\program files (x86)\microsoft visual studio 8\vc\include\cstring(21) : warning C4995: 'strcpy': 名前が避けられた #pragma として記述されています。
1>c:\program files (x86)\microsoft visual studio 8\vc\include\cwchar(34) : warning C4995: 'swprintf': 名前が避けられた #pragma として記述されています。
1>c:\program files (x86)\microsoft visual studio 8\vc\include\cwchar(35) : warning C4995: 'vswprintf': 名前が避けられた #pragma として記述されています。
1>c:\program files (x86)\microsoft visual studio 8\vc\include\cwchar(37) : warning C4995: 'wcscat': 名前が避けられた #pragma として記述されています。
1>c:\program files (x86)\microsoft visual studio 8\vc\include\cwchar(39) : warning C4995: 'wcscpy': 名前が避けられた #pragma として記述されています。
1>マニフェストをリソースにコンパイルしています...
1>リンクしています...
1>マニフェストを埋め込んでいます...
1>T_path_l - エラー 0、警告 9
========== ビルド: 1 正常終了、0 失敗、0 更新、0 スキップ ==========
コンパイラの警告 (レベル 3) C4995
ドキュメントにある様に,次を追加して対応.
#pragma warning(disable : 4995)
「ダイアログ バー」の追加
Win10 環境で VC 6 を使えるようにはなったが,「コンポーネントギャラリ」はうまく機能しないみたい.
今回利用しようとしたのは「ダイアログ バー」.ヘルプの内容は次の様なもの.
ダイアログ バー コンポーネント : 挿入結果
ダイアログ バー コンポーネントを挿入すると、プロジェクト コードに次の変更が加えられます。
- プロジェクトのリソース スクリプトにダイアログ テンプレート リソースが追加されます。このダイアログ テンプレートにコントロールを追加するには、Visual C++ のダイアログ エディタを使用できます。
- 指定したフレーム ウィンドウ クラスに、CDialogBar 型のメンバ変数の宣言が追加されます。デフォルトの変数名 m_wndMyDialogBar は変更できます。ダイアログ バーの初期プロパティ (標準では可視、ドッキング可能など) も指定できます。
- フレーム ウィンドウの OnCreate メンバ関数に初期化コードが追加されます。この初期化コードは、CDialogBar::Create を呼び出して、ダイアログ バーのドッキング オプションを設定します。また、ダイアログ バーの表示/非表示に関する初期化もここで行います。
- ダイアログ バーの表示/非表示に関するメニュー項目のサポートが追加されます。
ダイアログ バー コンポーネントを挿入しても、ダイアログ バーの表示/非表示を切り替えるためのメニュー項目はメニュー リソースに追加されません。このメニュー項目はメニュー エディタを使用して手作業で追加する必要があります。コンポーネントは、メニュー項目の追加手順を記述した “TODO” コメントを追加します。このコメントは、ダイアログ バーを追加したフレーム クラスの OnCreate 関数に挿入できます。
- 2 つの関数のハンドラがフレーム ウィンドウ クラスのメッセージ マップに追加されます。
- OnUpdateXXX 関数はメニュー項目の状態を随時更新します。
- 次に、OnBarCheck 関数は、メニュー項目のチェックマークのオン/オフどおりに、ダイアログ バーが表示/非表示になっているかどうかを調べます。
メニュー項目のプロンプト文字列がプロジェクトのストリング テーブル リソースに追加されます。コマンド ハンドラをインプリメントするには、ClassWizard を使用して、次の手順に従います。
- ResourceView で、ダイアログ バーのダイアログ テンプレートを開きます。
- Ctrl キーを押しながら W キーを押して ClassWizard を開きます。[クラスの追加] ダイアログ ボックスが表示されます。
- [クラスを選択] をクリックして、[OK] をクリックします。[クラスの選択] ダイアログ ボックスが表示されます。
- ダイアログ バー コンポーネントを挿入したときに指定したフレーム ウィンドウ クラスの名前をクリックして、[選択] をクリックします。このクラスとダイアログ リソースを関連付けるかどうかを確認するメッセージ ボックスが表示されます。
- [はい] をクリックします。[MFC ClassWizard] ダイアログ ボックスの [メッセージ マップ] タブの [オブジェクト ID] ボックスの一覧に、ダイアログ バーのコントロールの ID が表示されます。
- 通常の方法で、コントロールにコマンド ハンドラを割り当てます。
メモ ActiveX コントロールをダイアログ バーに追加する場合は、プロジェクトが ActiveX コントロール コンテナ機能をサポートしている必要があります。AppWizard でプロジェクトのスケルトンを生成したときに [ActiveX コントロール] オプションを選択していた場合は、ActiveX コントロール コンテナ機能のサポートがプロジェクトに含まれています。サポートがない場合は、[Gallery] の [Visual C++ Components] フォルダから [ActiveX コントロール コンテナ コンポーネント] を選択してプロジェクトに挿入する必要があります。
実際のコードなどの編集は次の様な手順.
ダイアログリソースの追加.
「スタイル」を「チャイルド」に.
「境界線」を「しない」に.
「タイトルバー」のチェックを外す.
CMainFrame に変数を追加.
CDialogBar m_wndDlgBar ;
CMainFrame::OnCreate に追加.
{
if (!m_wndDlgBar.Create(this, IDD_DIALOG_BAR,
CBRS_RIGHT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,
ID_DIALOG_BAR))
{
TRACE0("Failed to create dialog bar m_wndDlgBar\n");
return -1; // fail to create
}
// m_wndDlgBar.EnableDocking(CBRS_ALIGN_RIGHT | CBRS_ALIGN_LEFT);
// EnableDocking(CBRS_ALIGN_ANY);
// DockControlBar(&m_wndDlgBar);
}
Resource.h に ID_DIALOG_BAR を追加.
ダイアログバー上のコントロールに対しての操作は次の様な感じ.
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
if (m_wndDlgBar.GetSafeHwnd() == NULL) { return ; }
CListBox* listBI = (CListBox*)m_wndDlgBar.GetDlgItem(IDC_LIST_BI) ;
FitWindow(&m_wndDlgBar,listBI,3, FALSE, FALSE, FALSE, FALSE) ;
}