ホーム » .NET

.NET」カテゴリーアーカイブ

2025年6月
1234567
891011121314
15161718192021
22232425262728
2930  

カテゴリー

アーカイブ

ブログ統計情報

  • 116,144 アクセス


Synology NAS で .NET console

先日から Synlogy NAS 上の .NET に関していろいろとやっている.
今まで Windows 上でコードを書いて run ,NAS 上にコピーして SSH 接続して実行していた.
これをもう少し簡単にできないかと…


NAS 上のコピー先をネットワークドライブとして割り当て.
NAS をネットワークドライブとして割り当て,「コマンドプロンプトを起動」
そこをコマンドプロンプトで開いて,dotnet コマンドなどでいろいろと…
NAS に直接 dotnet コマンドなどで操作


Dotnet Run App
コマンドラインでC#プログラミング
.NET Core で 実行ファイル(exe)を作成する方法

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

Web サーバ C++/CLI

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

Synology NAS で .NET web

Synology NAS で動かす前に,Win11 環境で…
dotnet new web
dotnet run
dotnet new web
localhost:5073

他の PC などから接続可能なように app.Urls.Add("http://0.0.0.0:3000"); を追加.

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.Urls.Add("http://0.0.0.0:3000");
app.MapGet("/", () => "Hello World!");

app.Run();

dotnet run として,動作を確認.
Program.cs などが入ったフォルダ以下を Synology NAS にコピー.
dotnet web1.dll で実行.
dotnet web1.dll で実行
Synology NAS dotnet web Hello


【#3】.NET Core MVC初心者チュートリアル はじめてのMVCアプリ
8 ways to set the URLs for an ASP.NET Core app
シンプルな ASP.NET Core Web API アプリケーションを作成する
ASP.NET Core入門 – Program.cs 解説【.NET 8】

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

Synology NAS で .NET

Synology NAS の「パッケージ センター」を見ていたら,「.NET 9 runtime」に気づいた.
それで,どのようなことができるかを少し試してみた.


DS116 では dotnet コマンドがうまく動作せず,エラーになる.
DS116  dotnet: /lib/libc.so.6: version `GLIBC_2.34' not found (required by dotnet)
dotnet: /lib/libc.so.6: version `GLIBC_2.34′ not found (required by dotnet)
DS220+ の libc.so.6 と比べると GLIBC_2.34 がない?
DS116 と DS220+ の libc.so.6


DS116 はあきらめて,DS220+ の方に「.NET 9 runtime」をインストール.
dotnet コマンドは動作するようになった.
DS220+  dotnet


.NET のサンプルで検索すると,.NET CLI 関係が見つかり,開発環境では次のコマンドで Hello, World! が表示できる.
dotnet new console
dotnet run
Win11 環境ではうまく動作することを確認.


Synology NAS で試すと .NET SDK がないためエラーとなる.
dotnet new console
NAS に .NET SDK を入れる方法がわからなかったので,Win11 で作成したものをそのままコピー.
何とか起動できないものかと試すがよくわからず…


あきらめかけていたが,dotnet ~.dll で実行できる記述を見つけた.
dotnet net2/bin/Debug/net9.0/net2.dll


dotnetコマンドを使って、Visual Studioを起動せずに簡単にプログラムを作成する
ubuntuでc#のサンプルアプリを動かすまでのメモ
Ubuntuリポジトリに取り込まれたパッケージ版.NETで、UbuntuでもC#プログラミングを始めよう!
C#(.NET Framework)で作ったコンソールアプリを .NET Core を使ってLinuxで動かしてみる!【前編】
dotnet new コマンドで使うテンプレートを作成する

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

error D8016 : /clr /RTC1

VC 6 で作成して VC 2022 まで順に上げた MFC プロジェクトで /clr を有効にしてビルド.

22:39 でビルドが開始されました...
1>------ ビルド開始: プロジェクト: GLSmth, 構成: Debug Win32 ------
1>cl : コマンド ライン  error D8016: コマンド ライン オプション '/clr' と '/RTC1' は同時に指定できません
1>プロジェクト "GLSm143.vcxproj" のビルドが終了しました -- 失敗。
========== ビルド: 成功 0、失敗 1、最新の状態 0、スキップ 0 ==========
=========== ビルド は 22:39 で完了し、00.707 秒 掛かりました ==========

通常はプロジェクトの設定で「C/C++」-「コード生成」-「基本ランタイムチェック」で「既定」を選択すれば良い.
「C/C++」-「コード生成」-「基本ランタイムチェック」で「既定」
が,今回はそれだけではエラーのまま.


vcxproj をエディタで開いてみると EnableFastChecks という部分が存在している.

    <ClCompile Include="GLSmth.cpp">
      <BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
    </ClCompile>

「ソリューション エクスプローラー」ですべての cpp を選択して,「既定」などを選択する必要がある.
すべての cpp を選択して,「基本ランタイムチェック」で「既定」に

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

fatal error C1001

MFC SDI プロジェクトを /clr を有効にして,ビルド.
さらに OpenMP を有効にしてビルドすると …

ビルドを開始しました...
1>------ ビルド開始: プロジェクト: MBPV, 構成: Release Win32 ------
1>MBPVDc.cpp
1>enumfile.hxx MessageBar  No Support
1>BDocCSV           Draw   No Support
1>_WIN32            1
1>_WINDOWS          1
1>_OPENMP           200203
1>_UNICODE          1
1>_MSC_VER          1929
1>_MSC_FULL_VER     192930157
1>_MFC_VER          0x0E00
1>_ATL_VER          0x0E00
1>__CLR_VER         40809290
1>_MSVC_LANG        201402L
1>WINVER            0x0A00
1>__cplusplus_cli   200406L
1>_AFXDLL           1
1>_M_CEE            001
1>_MANAGED          1
1>__DATE__          "Jan 10 2025"
1>__TIME__          "13:39:57"
1>UndoRedo::UpdateUI       No Support ODMenu
1>T:\Develop\_.SRC\__CPR_\enumfile.hxx(597): fatal error C1001: 内部コンパイラ エラーが発生しました。
1>(コンパイラ ファイル 'D:\a\_work\1\s\src\vctools\Compiler\Utc\src\p2\main.c'、行 213)
1> この問題を回避するには、上記の場所付近のプログラムを単純化するか変更してください。
1>可能な場合、再現手順をこちらに入力してください: https://developercommunity.visualstudio.com
1>詳細については、Visual C++ ヘルプ メニューのサポート情報コマンドを
1>選択するか、サポート情報ヘルプ ファイルを参照してください
1>  CL!RaiseException()+0x62
1>  CL!RaiseException()+0x62
1>  CL!InvokeCompilerPass()+0xc17f1
1>  CL!CloseTypeServerPDB()+0x16cc3
1>プロジェクト "MBPV142.vcxproj" のビルドが終了しました -- 失敗。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========

MFC /clr OpenMP で C1001 内部コンパイラ エラーが発生しました
デバッグビルドは通る.また,/clr や OpenMP を外すと通る.
VC 2017 や 2022 などでは問題ない.
何かの更新で解消されるかもしれないので,このままとする.

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

MFC + System:: … ::ZipFile

先日から作成しているテスト exe で,ZIP に圧縮する動作を…
主要な exe では,izip.exe を呼出したり,シェルの機能を利用している.
ただ,同期のタイミングなど少し時間がかかるので,試しに直接呼出す方法に変更.


プロジェクトの設定で「共通言語ランタイム サポート (/clr)」に.
「共通言語ランタイム サポート (/clr)」に
そのままビルドすると
cl : コマンド ライン error D8016: コマンド ライン オプション ‘/ZI’ と ‘/clr’ は同時に指定できません
cl : コマンド ライン error D8016: コマンド ライン オプション ‘/clr’ と ‘/Gm’ は同時に指定できません
cl : コマンド ライン error D8016: コマンド ライン オプション ‘/clr’ と ‘/RTC1’ は同時に指定できません
T:\…\zip_CLI.hxx(16,9): fatal error C1107: アセンブリ ‘System.IO.Compression.dll‘ がみつかりませんでした: /AI または LIBPATH 環境変数を使用してアセンブリ検索パスを指定してください。
L:\Document\…\ComPrj01.cpp : fatal error C1128: セクションの数がオブジェクト ファイル形式の制限を超えています: /bigobj と共にコンパイルしてください
「プログラム データベース (/Zi)」に.
/Gm と /RTC1 は「<親またはプロジェクトの既定値から継承>」に.
「追加の #using ディレクトリ」を「C:\Windows\Microsoft.NET\Framework\v4.0.30319」に.
「C/C++」-「コマンド ライン」の「追加のオプション」に「 /bigobj 」の追加.


これでビルドはできる様になったが,あまり見慣れない warning が…
ComPrj01.obj : warning LNK4248: 未解決の typeref トークン (0100001B) (‘_TREEITEM’) です。イメージを実行できません。
ComPrj01.obj : warning LNK4248: 未解決の typeref トークン (0100001F) (‘GLUtesselator’) です。イメージを実行できません。
これに関しては,ちょっとわからず.

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

コンパイル時の #define 値の表示

次の様なコードをコンパイル時に表示したくなった.

#ifdef	  _MSC_VER
str = _T("_MSC_VER ") + ::utot(_MSC_VER,10) ;
#endif
std::tout << str ;

以前一度使用しているが,それをもう少しいろいろと...


次の様に _CRT_STRINGIZE とすれば _MSC_VER 1941 と表示される.

#ifdef		  _MSC_VER
#pragma	message	("_MSC_VER " _CRT_STRINGIZE(_MSC_VER) )
#endif

VC 14 以降は vcruntime.h で次の様になっている.

#define _CRT_STRINGIZE_(x) #x
#define _CRT_STRINGIZE(x) _CRT_STRINGIZE_(x)

文字列化演算子 (#)


まだ途中だが,CPP ソースのどこでインクルードしてもそれなりに動作する様にする予定.
コンパイル時の #define 値の表示

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

3MF データが開けない?

3D データを 3MF 出力したものが開けなくなったと問い合わせが入った.
3MF が開けない  0x80004003
開発環境では現象がなかなか確認できなかったが,自前の iZIP.exe 版の影響とわかった.
Shell の ZIP 機能を使用していた 2022/12 いっぱいぐらいはうまく動作する.
.net を使用した iZIP.exe にしてからの 3MF がうまく開けない


自前で作成している 3D ビューアなどではうまく開ける.
それぞれの 3MF を展開して,テキストエディタなどで比較しても特に違いはない.
また 3MF をバイナリで比較すると,少し異なる所があることはわかる.


まだはっきりしていないが,バイナリを見た限りではディレクトリ区切りの影響か?


2024/05/16
iZIP.exe が影響していることはわかったが,その違いがなかなかわからなかった.
iZIP.exe を起動して 3MF を展開したイメージのフォルダをドロップして確認.
3MF を展開した(ZIP 圧縮前の)データ
iZIP.exe をビルドしている VC が 2022 でないとうまくないみたい.


関連しそうなのは次の情報か?
軽減策:ZipArchiveEntry.FullName パスの区切り文字
.NET Framework 4.6.x への移行に関する変更の再ターゲット


試しに ZipFile::CreateFromDirectory に渡すファイル名を ‘/’ にしてみたが,効果はなかった.
ZipFile::CreateFromDirectory  '/'

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

DirectoryNotFoundException

以前作成した .NET の ZipFile クラス使用した exe
この iZIP.exe で System.IO.DirectoryNotFoundException .


原因は,ある環境でユーザ名に半角スペースが含まれていた.
ユーザ名に半角スペースを含む環境を作成して ZipFold.exe で同じ様な操作を行ったが,再現できない.
いろいろと調べていると,iZIP.exe に渡す時の入力のフォルダ名に半角スペースが含まれていると現象が発生する.

C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\test>Q:\C_Temp\i_Tools\ZIP\iZIP\Release.140\iZIP.exe a "C:\Users\Iwao\AppData\Local\Temp\Send.tmp\20240416\09 22 39\" abc.zip

ハンドルされていない例外: System.IO.DirectoryNotFoundException: パス 'C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\zip_CLI\20240416\154459\a' の一部が見つかりませんでした。
   場所 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   場所 System.IO.FileSystemEnumerableIterator`1.CommonInit()
   場所 System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   場所 System.IO.DirectoryInfo.EnumerateFileSystemInfos(String searchPattern, SearchOption searchOption)
   場所 System.IO.Compression.ZipFile.DoCreateFromDirectory(String sourceDirectoryName, String destinationArchiveFileName, Nullable`1 compressionLevel, Boolean includeBaseDirectory, Encoding entryNameEncoding)
   場所 ZipFile_create(Char* fld_file, Char* zip_name) 場所 c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring:行 1017
   場所 zip_create(basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> >* , Char* zip_root) 場所 t:\develop\_.src\__mlt_\zip_func.hxx:行 47
   場所 zip_create(Char* fld_file, Char* zip_name) 場所 t:\develop\_.src\__mlt_\zip_func.hxx:行 143
   場所 call_func(Int32 argc, Char** argv) 場所 c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring:行 521
   場所 wmain(Int32 argc, Char** argv) 場所 l:\document\develop\tools\_free\ziptools\izip\izip.cpp:行 168
   場所 _wmainCRTStartup()

C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\test>Q:\C_Temp\i_Tools\ZIP\iZIP\Release.140\iZIP.exe a "C:\Users\Iwao\AppData\Local\Temp\Send.tmp\20240416\09 22 39\" ".\20240416\1545\abc.zip"

ハンドルされていない例外: System.IO.DirectoryNotFoundException: パス 'C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\zip_CLI\20240416\154602\a' の一部が見つかりませんでした。
   場所 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   場所 System.IO.FileSystemEnumerableIterator`1.CommonInit()
   場所 System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   場所 System.IO.DirectoryInfo.EnumerateFileSystemInfos(String searchPattern, SearchOption searchOption)
   場所 System.IO.Compression.ZipFile.DoCreateFromDirectory(String sourceDirectoryName, String destinationArchiveFileName, Nullable`1 compressionLevel, Boolean includeBaseDirectory, Encoding entryNameEncoding)
   場所 ZipFile_create(Char* fld_file, Char* zip_name) 場所 c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring:行 1017
   場所 zip_create(basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> >* , Char* zip_root) 場所 t:\develop\_.src\__mlt_\zip_func.hxx:行 47
   場所 zip_create(Char* fld_file, Char* zip_name) 場所 t:\develop\_.src\__mlt_\zip_func.hxx:行 143
   場所 call_func(Int32 argc, Char** argv) 場所 c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring:行 521
   場所 wmain(Int32 argc, Char** argv) 場所 l:\document\develop\tools\_free\ziptools\izip\izip.cpp:行 168
   場所 _wmainCRTStartup()

C:\Users\Iwao\AppData\Local\Temp\i_Tools.tmp\test>

iZIP.exe  System.IO.DirectoryNotFoundException
入力のフォルダ名の “…\20240416\09 22 39\” の “09 22 39” 直後の ‘\’ を削除するとうまくいく.


デバッガで iZIP.exe に渡されるコマンドラインを確認.
iZIP.exe コマンドライン引数
デバッグ時,ダンプする様にコードを書換え.
iZIP.exe コマンドライン引数のダンプ
やはり argv がうまく解釈されていない.
argv[2]が「…\17 53 06″ c:\…」となってしまっている.
“…\17 53 06\\” の様にすれば通ることは確認できた.
perse_commandline では ‘\”‘ がダブルクォーテーションと解釈され,’\\’ はバックスラッシュ?


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

WebGL での 3D データ表示

さらに,以前作成した Web サーバ を利用して WebGL での表示に

bool	test	(void)
{
	Vd2A	pts ;
	{
		pts.push_back(Vd2(  0,  0)) ;
		pts.push_back(Vd2( 70,  0)) ;
		pts.push_back(Vd2( 90, 50)) ;
		pts.push_back(Vd2(100,100)) ;
		pts.push_back(Vd2( 50,100)) ;
		pts.push_back(Vd2( 30, 70)) ;
		pts.push_back(Vd2( 40, 30)) ;
		pts.push_back(Vd2(  0,  0)) ;
		}
	vv_PLF	vvplf ;
	{
		Vd3A	v3a = ::ToVd3A(pts) ;
		Vd4A	v4a = ::ToVd4A(v3a) ;
		PLF	plf_l(PLF::line,v4a) ;
		PLF	plf_f(PLF::face,v4a) ;
		v_PLF	v_plf ;
			v_plf.push_back(plf_l) ;
			v_plf.push_back(plf_f) ;
			vvplf.push_back(v_plf) ;
		}
	{
		tstring	tmp_path = ::Get_i_Tools_tmp_date() ;
		tstring	out_name = ::Path_AddLastSP(tmp_path) + ::Now_Format(_T("%H%M%S")) + _T("__.htm") ;
		tstring	outtname = ::Path_AddLastSP(tmp_path) + ::Now_Format(_T("%H%M%S")) + _T("_t.htm") ;
		tstring	outnname = ::Path_AddLastSP(tmp_path) + ::Now_Format(_T("%H%M%S")) + _T("_n.htm") ;
		{
			GonsA	gnsa = ::PLF_ToGonsA(vvplf) ;
			::GonsA_ToWGL(gnsa,out_name.c_str()) ;
				gnsa = ::GonsA_Triangulation(gnsa) ;
			::GonsA_ToWGL(gnsa,outtname.c_str()) ;
				gnsa = ::GonsA_CalcNormal   (gnsa) ;
			::GonsA_ToWGL(gnsa,outnname.c_str()) ;
			}
		{
			::start_web_server(tmp_path) ;
			}
		}
	tstring	g3_d_exe = ::get_g3_d_exe() ;
	if (!g3_d_exe.empty()) {
		tstring	tmp_path = ::Get_i_Tools_tmp_date() ;
		tstring	ipl_name = ::Path_AddLastSP(tmp_path) + ::Now_Format(_T("%H%M%S")) + _T(".ipl") ;
		::To_ipl  (vvplf,ipl_name.c_str()) ;
		::start_g3_d(ipl_name.c_str()) ;
		}
	return	true ;
	}

簡易 Web サーバで WebGL

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

.NET ZipFile C++/CLI

ZipFile クラスのサンプル を VC 2012 C++/CLI で.
Win32 コンソール AP としてプロジェクトを作成.
CPP を次の様に変更.

#include	<stdio.h>
#include	<tchar.h>

//	using	System;
//	using	System.IO.Compression;
#using  	<System.dll>
#using		<System.IO.Compression.FileSystem.dll>

//	class Program
//	{
//		static void Main(string[] args)
//		{

int _tmain(int argc, _TCHAR* argv[])
{
//			string  startPath	= @"./start";
//			string  zipPath  	= @"./result.zip";
//			string  extractPath	= @"./extract";
		System::String^	startPath	= _T("./start") ;
		System::String^	zipPath  	= _T("./result.zip") ;
		System::String^	extractPath	= _T("./extract") ;

//		                         ZipFile. CreateFromDirectory(startPath, zipPath);
		System::IO::Compression::ZipFile::CreateFromDirectory(startPath, zipPath);

//		                         ZipFile. ExtractToDirectory(zipPath, extractPath);
		System::IO::Compression::ZipFile::ExtractToDirectory(zipPath, extractPath);

	return 0;
	}

//			}
//		}

そのままビルドすると…

1>------ ビルド開始: プロジェクト: T_ZIP_C, 構成: Debug Win32 ------
1>  T_ZIP_C.cpp
1>d:\document\vs\vs\2012\t_clr\t_zip_c\t_zip_c.cpp(6): fatal error C1190: マネージ ターゲット コードには '/clr' が必要です。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========

fatal error C1190: マネージ ターゲット コードには '/clr' が必要です。
プロジェクトの設定で「/clr」に.

1>------ ビルド開始: プロジェクト: T_ZIP_C, 構成: Debug Win32 ------
1>  T_ZIP_C.cpp
1>T_ZIP_C.cpp(7): fatal error C1107: アセンブリ 'System.IO.Compression.FileSystem.dll' がみつかりませんでした: /AI または LIBPATH 環境変数を使用してアセンブリ検索パスを指定してください。
========== ビルド: 0 正常終了、1 失敗、3 更新不要、0 スキップ ==========

「追加の #using ディレクトリ」に dll の場所を指定して通る様にはなったが,これで良いかがわからない.
fatal error C1107: アセンブリ 'System.IO.Compression.FileSystem.dll' がみつかりませんでした:


ほとんど何も入っていない環境で実行すると,

---------------------------
T_ZIP_C.exe - システム エラー
---------------------------
MSVCR110.dll が見つからないため、コードの実行を続行できません。プログラムを再インストールすると、この問題が解決する可能性があります。 
---------------------------
OK   
---------------------------

MSVCR110.dll が見つからないため、コードの実行を続行できません。
VC 2013 や 2015 でビルドしたものも試してみたが,この環境では実行できなかった.
対応するものを入れる必要があるのか?
https://jml.mish.work/index.php/cpp/ref-vcredist-xxx-exe.html


zip_CLI.hxx


2024/07/05
VC のバージョン(実際は .NET のバージョン?)により,微妙に zip の内容が異なるみたい.
3MF データが開けない?

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

.NET ZipFile C#

今まで Windows で zip を扱う部分で Shell を利用 してきた.
その時,存在は知っていたが,手を付けてなかった .NET を利用したものを調べることに…


サンプルは次の所にある.
ZipFile クラス
.NET Framework 4.5 以降なので VS 2012 で C# のプロジェクトを作成.
Program.cs をサンプルの様に変更してビルドすると…

1>------ ビルド開始: プロジェクト: T_ZIP, 構成: Debug Any CPU ------
1>D:\Document\VS\VS\2012\T_CLR\T_ZIP\Program.cs(12,9,12,16): error CS0103: 名前 'ZipFile' は現在のコンテキスト内に存在しません。
1>D:\Document\VS\VS\2012\T_CLR\T_ZIP\Program.cs(14,9,14,16): error CS0103: 名前 'ZipFile' は現在のコンテキスト内に存在しません。
========== ビルド: 0 正常終了、1 失敗、1 更新不要、0 スキップ ==========

ZipFile のビルドで error CS0103
そこにも書かれているが System.IO.Compression.FileSystem を追加する必要がある.
「 System.IO.Compression.FileSystem 」の追加
…\bin\…\start\ に,幾つかのファイルをコビー.
exe を実行すると,result.zip と …\extract\ 以下にファイルが解凍される.
再度実行する場合は result.zip と extract\ を削除する必要がある.
'result.zip' は既に存在します


ディレクトリ区切りの ‘\’ を ‘/’ に変更する必要があるが,Ubuntu でも同様に実行可能.
Ubuntu 環境で ZipFile クラスのサンプルを実行

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

簡易 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"

* 幾つかのコードが揃っていないため,そのままではビルドできません.
簡易 Web サーバ   C++/CLI
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

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

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;
	}

Web サーバ   C++/CLI

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

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 ;
	}

検索すると System::String::Empty を使えば良さそうたが,str が 0 との比較は必要ないのか?
VC 8 で  C++/CLI

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

MFC AP で .NET の利用

MFC ダイアログ AP を C++/CLI に.
VC 2010 で,MFC ダイアログベースのスケルトンを作成.
リストボックスを追加して,コントロールの変数を割り当て.
プロジェクトの「プロパティ」で「共通言語ランタイム サポート(/clr)」に変更.
ダイアログのソースに次のものを追加.

#include	"enumfile.hxx"
#include	"vtst_MFC.hxx"
#include	"str_CLI.hxx"

#using		<System.dll>
#using		<mscorlib.dll>

OnInitDialog に次のコードを追加.

	{
		v_tstring	files = ::EnumFiles(_T("./"),_T("*.*")) ;
		::ToListBox(files,&m_CtrlListFiles) ;
		}
	{
		array<System::String^>^ gfile = System::IO::Directory::GetFiles(_T("./"));
		v_tstring	files ;
		for (int i = 0; i<gfile->Length; i++) {
			tstring	file = ::to_tstring(gfile[i]) ;
			files.push_back(file) ;
			}
		::ToListBox(files,&m_CtrlListFiles) ;
		}

MFC AP に「共通言語ランタイム サポート(/clr)」追加


「共通言語ランタイム サポート(/clr)」とすることで良いならば,コンソール AP ではどうなのか?
空のコンソール AP を作成して,次の様なコード.

#include	"enumfile.hxx"
#include	"str_CLI.hxx"

#using  	<System.dll>

bool	test	(c_tstring& str)
{
	tstring	fold_ = str ;
	{
		if (::File_IsDirectory(fold_))	{	;				}
		else				{	fold_ = ::Path_GetDir(fold_) ;	}
		}
	std::terr << fold_ << std::endl ;
	{
		v_tstring	files = ::EnumFiles(fold_,_T("*.*")) ;
		for (size_t index=0 ; index<files.size() ; index++) {
			std::terr << files[index] << std::endl ;
			}
		}
	{
		System::String^	fold = ::to_gcString(fold_) ;
		array<System::String^>^ gfile = System::IO::Directory::GetFiles(fold);
		for (int i = 0; i<gfile->Length; i++) {
			System::String^	file = gfile[i] ;
			System::Console::WriteLine(file) ;
			}
		}
	return	true ;
	}

int _tmain(int argc, _TCHAR* argv[])
{
	::test(_T("./")) ;
	return 0;
	}

Win32 コンソール AP C++  /clr に
::GetOpenFileName使用 した 方法 も可能だったが…
C++/CLI コンソール AP で GetOpenFileName を使用
::SHBrowseForFolder では,止まってしまう?


プロジェクトの作成で「CLR コンソール アプリケーション」として,main 関数を次の様にしたもの.

int main(array<System::String ^> ^args)
{
	{
	//	::call_func(argc,argv) ;
		::call_func() ;
		}
	{
		::test(_T("Test")) ;
		}
	::ask_wait() ;
	return 0;
	}

これは,ビルドするとよくわからないエラー.

1>------ ビルド開始: プロジェクト: T_CLR_2, 構成: Debug Win32 ------
1>  T_CLR_2.cpp
1>  EnumFile.hxx MessageBar  No Support
1>  .NETFramework,Version=v4.0.AssemblyAttributes.cpp
1>T_CLR_2.obj : error LNK2028: 未解決のトークン (0A000665) "extern "C" unsigned long __stdcall CommDlgExtendedError(void)" (?CommDlgExtendedError@@$$J10YGKXZ) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl FD_GetOpenFile(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *)" (?FD_GetOpenFile@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PAUHWND__@@PB_W11@Z) で参照されました。
1>T_CLR_2.obj : error LNK2028: 未解決のトークン (0A000695) "extern "C" int __stdcall SHGetPathFromIDListW(struct _ITEMIDLIST const *,wchar_t *)" (?SHGetPathFromIDListW@@$$J18YGHPBU_ITEMIDLIST@@PA_W@Z) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl SH_GetPathFromIDList(struct _ITEMIDLIST const *)" (?SH_GetPathFromIDList@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PBU_ITEMIDLIST@@@Z) で参照されました。
1>T_CLR_2.obj : error LNK2028: 未解決のトークン (0A00069F) "extern "C" void __stdcall CoTaskMemFree(void *)" (?CoTaskMemFree@@$$J14YGXPAX@Z) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl Browse_Folder(struct HWND__ *,wchar_t const *,wchar_t const *)" (?Browse_Folder@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PAUHWND__@@PB_W1@Z) で参照されました。
1>T_CLR_2.obj : error LNK2028: 未解決のトークン (0A0006B0) "extern "C" struct HWND__ * __stdcall FindWindowW(wchar_t const *,wchar_t const *)" (?FindWindowW@@$$J18YGPAUHWND__@@PB_W0@Z) が関数 "struct HWND__ * __cdecl GetConsoleHwnd(void)" (?GetConsoleHwnd@@$$FYAPAUHWND__@@XZ) で参照されました。
1>T_CLR_2.obj : error LNK2028: 未解決のトークン (0A00070A) "extern "C" struct _ITEMIDLIST * __stdcall SHBrowseForFolderW(struct _browseinfoW *)" (?SHBrowseForFolderW@@$$J14YGPAU_ITEMIDLIST@@PAU_browseinfoW@@@Z) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl Browse_Folder(struct HWND__ *,wchar_t const *,wchar_t const *)" (?Browse_Folder@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PAUHWND__@@PB_W1@Z) で参照されました。
1>T_CLR_2.obj : error LNK2028: 未解決のトークン (0A000710) "extern "C" int __stdcall GetOpenFileNameW(struct tagOFNW *)" (?GetOpenFileNameW@@$$J14YGHPAUtagOFNW@@@Z) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl FD_GetOpenFile(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *)" (?FD_GetOpenFile@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PAUHWND__@@PB_W11@Z) で参照されました。
1>T_CLR_2.obj : error LNK2028: 未解決のトークン (0A000741) "extern "C" long __stdcall SendMessageW(struct HWND__ *,unsigned int,unsigned int,long)" (?SendMessageW@@$$J216YGJPAUHWND__@@IIJ@Z) が関数 "extern "C" long __cdecl SendMessage(struct HWND__ *,unsigned int,unsigned int,long)" (?SendMessage@@$$J0YAJPAUHWND__@@IIJ@Z) で参照されました。
1>T_CLR_2.obj : error LNK2019: 未解決の外部シンボル "extern "C" long __stdcall SendMessageW(struct HWND__ *,unsigned int,unsigned int,long)" (?SendMessageW@@$$J216YGJPAUHWND__@@IIJ@Z) が関数 "extern "C" long __cdecl SendMessage(struct HWND__ *,unsigned int,unsigned int,long)" (?SendMessage@@$$J0YAJPAUHWND__@@IIJ@Z) で参照されました。
1>T_CLR_2.obj : error LNK2019: 未解決の外部シンボル "extern "C" int __stdcall SHGetPathFromIDListW(struct _ITEMIDLIST const *,wchar_t *)" (?SHGetPathFromIDListW@@$$J18YGHPBU_ITEMIDLIST@@PA_W@Z) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl SH_GetPathFromIDList(struct _ITEMIDLIST const *)" (?SH_GetPathFromIDList@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PBU_ITEMIDLIST@@@Z) で参照されました。
1>T_CLR_2.obj : error LNK2019: 未解決の外部シンボル "extern "C" void __stdcall CoTaskMemFree(void *)" (?CoTaskMemFree@@$$J14YGXPAX@Z) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl Browse_Folder(struct HWND__ *,wchar_t const *,wchar_t const *)" (?Browse_Folder@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PAUHWND__@@PB_W1@Z) で参照されました。
1>T_CLR_2.obj : error LNK2019: 未解決の外部シンボル "extern "C" struct _ITEMIDLIST * __stdcall SHBrowseForFolderW(struct _browseinfoW *)" (?SHBrowseForFolderW@@$$J14YGPAU_ITEMIDLIST@@PAU_browseinfoW@@@Z) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl Browse_Folder(struct HWND__ *,wchar_t const *,wchar_t const *)" (?Browse_Folder@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PAUHWND__@@PB_W1@Z) で参照されました。
1>T_CLR_2.obj : error LNK2019: 未解決の外部シンボル "extern "C" unsigned long __stdcall CommDlgExtendedError(void)" (?CommDlgExtendedError@@$$J10YGKXZ) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl FD_GetOpenFile(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *)" (?FD_GetOpenFile@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PAUHWND__@@PB_W11@Z) で参照されました。
1>T_CLR_2.obj : error LNK2019: 未解決の外部シンボル "extern "C" int __stdcall GetOpenFileNameW(struct tagOFNW *)" (?GetOpenFileNameW@@$$J14YGHPAUtagOFNW@@@Z) が関数 "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl FD_GetOpenFile(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *)" (?FD_GetOpenFile@@$$FYA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PAUHWND__@@PB_W11@Z) で参照されました。
1>T_CLR_2.obj : error LNK2019: 未解決の外部シンボル "extern "C" struct HWND__ * __stdcall FindWindowW(wchar_t const *,wchar_t const *)" (?FindWindowW@@$$J18YGPAUHWND__@@PB_W0@Z) が関数 "struct HWND__ * __cdecl GetConsoleHwnd(void)" (?GetConsoleHwnd@@$$FYAPAUHWND__@@XZ) で参照されました。
1>D:\Document\VS\VS\2010\T_CLI\Debug\T_CLR_2.exe : fatal error LNK1120: 外部参照 14 が未解決です。
========== ビルド: 0 正常終了、1 失敗、4 更新不要、0 スキップ ==========

どこかを設定を設定すれば良いのかもしれないが,ちょっとわからない.

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

Linux VS Code インストール

Fedora 環境に VS Code のインストール.
Fedora Linux に Visual Studio Code をインストールする方法
最初の次のコマンドで,時間がかかっている.
sudo dnf upgrade –refresh
それで調べているともっと簡単と思われる情報が…
Visual Studio Code – Fedora Project Wiki
次のコマンドでインストール.
flatpak install https://flathub.org/repo/appstream/com.visualstudio.code.flatpakref
何とか入った.
Fedora に VS Code のインストール
が,どうやって使うのか…


Ubuntu 環境は OS が古く,20.04 への更新から.
さらに flatpak をインストールする必要があった.
sudo apt install flatpak
そして,
flatpak install https://flathub.org/repo/appstream/com.visualstudio.code.flatpakref
Ubuntu 環境に VS Code のインストール
こちらの方は「日本語化」のインストールの案内が自動で出てきた.
Fedora 環境では,手動で追加.
VS Code  日本語化パッケージのインストール
「言語拡張機能の参照」をクリック.すると,左に「C#」などがリストされる.
VC Code に C# のインストール


.NET のインストール.
Linux に .NET をインストールする
dotnet と入力すると,sudo snap install dotnet-sdk と出てきた.
Ubuntu に dotnet-sdk をインストール
これは違った?


次の所にある C# のコードを作成して VS Code で「デバッグなして実行」.
コンソール アプリ
すると,また同じ所に.
Ubuntu に .NET SDK または .NET ランタイムをインストールする
順に入れたが…

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

sudo apt-get update &&   sudo apt-get install -y dotnet-sdk-6.0

よくわからない.


次の所を参考にコマンドで…
Linux での開発用に C# を設定する
次のコマンドを入力すると…
dotnet new console
そして,
dotnet run
dotnet new console と dotnet run
何とか,コンパイル,実行できることは確認できた.


今度は Fedora 環境に.
Fedora に .NET SDK または .NET ランタイムをインストールする
sudo dnf install dotnet-sdk-6.0
dotnet new console と dotnet run
Fedora で dotnet new console と dotnet run


2022/11/25
Windows 環境だと…
dotnet new winforms
dotnet new <テンプレート>


VS Code はエディタとして使用する程度?
チュートリアル: Visual Studio Code を使用して .NET コンソール アプリケーションを作成する
うまく動作しない.ターミナルからでは dotnet コマンドへのパスが通っていない?

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

「.NET なんとか」

「.NET なんとか」のメモ.
.NET Framework
.NET (.NET Core)
.NET MAUI
.NET CLI


VS などが入っている環境だと,次のコマンドで SDK バージョンを確認できる.
dotnet –list-sdks
dotnet --info


Visual C++ で基本的なファイル I/O を実行する
C++/CLI プロジェクトを .NET Core または .NET 5 に移植する方法


C++/CLI
C++/CX
C++/WinRT


C++/CLI
「プロジェクト テンプレート」で「CLR 空のプロジェクト(.NET Framework)」を選択.
CLR .NET Framework
次の様な内容のソースを追加.

//#include "pch.h"

using namespace System;

int main(array<System::String^>^ args)
{
    Console::Write("test");
    return 0;
    }

VC 2022  CLR  プロパティ


次の所のコードと std::cin との混在.
ファイル処理と I/O (C++/CLI)

// file_info.cpp
// compile with: /clr

using namespace System;
using namespace System::IO;

#include	"ask_cli.hxx"

#include	"str_CLI.hxx"

bool	Draw_FileInfo	(c_tstring& file_name)
{
	String^		file = ::to_gcString(file_name) ;

	FileInfo^ fi = gcnew FileInfo(file) ;

	Console::WriteLine("file size: {0}", fi->Length);

	Console::Write    ("File creation date:  ");
	Console::Write    (        fi->CreationTime.Month.ToString());
	Console::Write    (".{0}", fi->CreationTime.Day.ToString());
	Console::WriteLine(".{0}", fi->CreationTime.Year.ToString());

	Console::Write    ("Last access date:  ");
	Console::Write    (        fi->LastAccessTime.Month.ToString());
	Console::Write    (".{0}", fi->LastAccessTime.Day.ToString());
	Console::WriteLine(".{0}", fi->LastAccessTime.Year.ToString());

	return	true ;
	}

int main()
{
	array<String^>^ args = Environment::GetCommandLineArgs();
	if (args->Length > 1) {
		tstring	file_name = ::to_tstring(args[1]) ;
		::Draw_FileInfo(file_name) ;
		}
	else {
		while(true)	{
			tstring	path = ::ask_cli(_T("file ... ? =")) ;
			if (path.empty())	{	break ;		}
			::Draw_FileInfo(path) ;
			}
		}
	return 0;
	}
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

簡易 Web サーバ C#

System.Net.HttpListener.dll で比較的簡単にできるみたいなので,ちょっと調べてみた.


最初に見つけたのは次の所.
.NET TIPS 簡易Webサーバを実装するには?[2.0のみ、C#、VB]
Win10 C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe でコンパイルして問題なく動作する.
そのままのコードでは,管理者として起動しなければならないのと,ルートが固定のため少し変更.

	string	root = @"c:\wwwroot\";	// ドキュメント・ルート
		root = @".\";
	string	prefix = "http://*/";	// 受け付けるURL
		prefix = "http://localhost:65432/" ;

これで exe を対象のルートにコピーして,起動させることができる.
HttpListener  C#


localhost ではなく 127.0.0.1 を指定すると //localhost:65432/… としてもアクセス可能.
prefix = "http://127.0.0.1:65432/" ;


参考にさせてもらった所.
https://yryr.me/programming/local-http-server.html
https://www.3ace-net.co.jp/blog/201304151845.html
https://d01tsumath.hatenablog.com/entry/2019/08/16/190000


これらをテストしていて,WebGL のページを表示すると,極端に遅くなる.
以前は FHD 環境だったが,先日から 4K でいろいろと…
そのため WebGL などのページを表示すると,GPU のメモリを大量に使用するみたい.
タスクマネージャの「専用 GPU メモリ」は 10 GB 程度になっているが,どこを使用しているの?
設定にもよるかもしれないが Firefox で次の所を表示すると「専用 GPU メモリ」の使用量が増えていく.
https://threejs.org/examples/#webgl_instancing_performance


C# のコードを C++/CLI に
簡易 Web サーバ C++/CLI
https://jml.mish.work/index.php/i-tools/web-svr.html

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