![]()
文字コードの説明| 文字コード | BOM | 説明 |
|---|---|---|
| utf-16 | FFFE | 先頭2バイトが BOM です |
| utf-8 | EFBBBF | 先頭3バイトが BOM です |
| utf-8(BOM無し) | BOM は格納されていません |
char str1[80];
LPSTR str2 = "LPSTR で宣言";
|
wchar_t str1[80];
WCHAR str2[80];
LPWSTR str1 = L"LPWSTR で宣言";
|
LPSTR sjis = "Shift JIS code"; WCHAR buf[MAX_PATH]; MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,sjis,-1,buf,MAX_PATH); |
LPWSTR uni = L"uni code String"; LPSTR sjis = "Shift JIS code"; char buf[MAX_PATH]; WideCharToMultiByte(CP_ACP,0,uni,-1,buf,MAX_PATH,NULL,NULL); |
using namespace std; |
char moji = 'A';
char str[10] = "ABCabc123"
|
開発環境
MessageBox(NULL,"Message Box を表示","Message Box Test",MB_OK); |
int id;
id = MessageBox(NULL,(LPCSTR)"終了しますか",
(LPCSTR)"終了確認", MB_OKCANCEL | MB_ICONQUESTION);
if (id==IDOK) DestroyWindow(hWnd);
|
#include <strsafe.h>
void DMsg(char *msg, int n)
{ char str[80];
StringCbPrintf(str,80,"%s[%d]\n",msg,n);
MessageBox(NULL,str,"Debug Message",MB_OK);
}
|
#include <strsafe.h>
void DMsg(WCHAR *msg, int n)
{ WCHAR str[80];
StringCchPrintf(str,80,L"%s[%d]\n",msg,n);
MessageBox(NULL,str,L"Debug Message",MB_OK);
}
|
MessageBox::Show("プログラムを終了します","Message Box");
|
MessageBox.Show("プログラムを終了します","Message Box");
MessageBox.Show("Mouse がクリックされました");
|
DialogResult rc;
rc= MessageBox.Show("終了しますか","選択",
MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (rc == DialogResult.Yes) Application.Exit();
|
Windows::UI::Popups::MessageDialog^ dlg =
ref new Windows::UI::Popups::MessageDialog("Test Message");
dlg->ShowAsync();
|
Windows.UI.Popups.MessageDialog dlg =
new Windows.UI.Popups.MessageDialog("Message Dialog");
dlg.ShowAsync();
|
window.alert("ここまで実行されました");
|
#include <windows.h> //OutputDebugString
OutputDebugString(L"Test Debug Message\r\n");
|
using namespace System;
Console::WriteLine("val={0} str={1}", val,str);
|
void XLoader::Debug(char *str)
{
WCHAR wk[1000];
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,str,-1,wk,1000);
OutputDebugString(wk);
OutputDebugString(L"\r\n");
}
|
#include <windows.h>
#include <vcclr.h>
using namespace System;
void Debug(String^ msg)
{
String^ message = msg + "\r\n";
pin_ptr<const wchar_t> wch = PtrToStringChars(message);
OutputDebugString(wch);
}
|
Platform::String^ msg = L"String Message\n"; OutputDebugString(msg->Data()); |
using namespace Platform;
void Debug(String^ msg)
{ String^ str = "Message[" + msg + "]\n";
OutputDebugString(str->Data());
}
|
void Debug(String^ msg, int n)
{
String^ message = ref new String(msg->Data());
message += " ";
message += n.ToString();
message += "\r\n";
OutputDebugString(message->Data());
}
|
MainPage::MainPage()
{
InitializeComponent();
OutputDebugString(L"★Debug Test\r\n");
Debug(L"Call Degug", 123);
int t[] = { 1, 4, 3, 5, 2 };
Debug(t, 5);
}
void MainPage::Debug(LPWSTR msg, int val)
{
wchar_t str[80];
swprintf(str, 80, L"%s: %d\r\n", msg, val);
OutputDebugString(str);
}
void MainPage::Debug(int *t, int num)
{
Platform::String^ str;
for (int i=0; i<num; i++)
{ str = t[i].ToString();
str += "\r\n";
OutputDebugString(str->Data());
}
}
|
namespace App1
{ public ref class MainPage sealed
{
public:
MainPage();
void Debug(LPWSTR msg, int val);
void Debug(int *t, int num);
};
}
|
using System.Diagnostics;
Debug.Write("\n*** Debug Message ***\n");
|
Vector2 pnt = Input.mousePosition;
Debug.Log("x->" + pnt.x + " y->" + pnt.y);
|
Console.WriteLine("val={0} str={1}", val,str);
|
System.out.println("a の値: " + a);
|
#include <windows.h> //OutputDebugString
#include <string>
using namespace std;
void Debug(string msg)
{ WCHAR wk[1000];
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,msg.data(),-1,wk,1000);
OutputDebugString(wk);
OutputDebugString(L"\r\n");
}
|
void Debug(wstring msg)
{ OutputDebugString(msg.data());
}
|
virtual void OnMouseDown(MouseEventArgs^ e) override
{ cnt++;
this->Text = "cnt=" + cnt;
}
|
void VarMsg(String^ msg, int x, int y)
{ String^ message = msg + " " + x + " " + y;
this->Text = message;
}
|
// Title Var Message
void VarMsg(HWND hwnd, char *chr)
{ SetWindowText(hwnd,(LPCSTR)str);
}
|
// Title Var Message
public void VerMsg(string str, int val)
{ string wstr;
wstr = str + val.ToString();
this.Text = wstr;
}
//VarMsg() 関数の呼び出し方
VerMsg("CNT= ", CNT);
|
base.Window.Title = "Title Bar に表示";
|
// Title Var Message
public void VerMsg(string str, int iv, float fv)
{ string wstr;
wstr = str + "iv=" + iv.ToString() + " fv=" + fv.ToString();
base.Window.Title = wstr;
}
//VarMsg() 関数の呼び出し方
VerMsg("int 型と float 型 ",ival,fval);
|
var a = 3;
var b = 5;
document.write("a=", a, ": b=", b, "<br>");
window.alert("a=" + a);
|
print "Hello PHP";
print "<IMG SRC=\"img/jewel.gif\">\r\n";
print("first:$first :last:$last\r\n");
print "'AB' not found" . "\r\n";
print_r($ary);
|
$a = 'hoge'; var_dump($a); var_dump($ary); |
$v1= 2; $v2= $v1+3; print "$v1,$2\n"; print "v1=" . $v1 . "\n"; |
@data= (3,1,4,5,2); print @data; |
| 動作 | キー | ツールマーク |
|---|---|---|
| HELP | F1 | 関数にポイントしておくと説明が表示される |
| 実行 | Ctrl+F5 | 赤いビックリマーク |
| ステップ | F5 | 文章+↓ |
| ブレーク設定 | F9 | 手のひら |
| ブレーク解除 | F9 | 手のひら |
| Step 実行 | F10 | |
| カーソルまで実行 | Ctrl+F10 | |
| Step In | F11 | |
| Step Out | Shift+F11 | |
| Debug 中止 | Shift+F5 | |
| MemoryWindow | Alt+F6 |





C:\DATA\C#\BAT\Prog1>csc Hello.cs 'csc' は、内部コマンドまたは外部コマンド、 操作可能なプログラムまたはバッチ ファイルとして認識されていません。 |
hello.cpp(5) : fatal error C1190: マネージ ターゲット コードには '/clr' が必要です。 |
| cl /clr hello.cpp |
| cl gcm.cpp |
| cl /clr gcm.cpp |
Gcm.cs(14,19): error CS0120: 静的でないフィールド、メソッド、またはプロパティ
'console.gcm(int, int)' で、オブジェクト参照が必要です。
|
| グローバルまたは静的変数は、マネージ型 「・・・」 を含むことはできません |
| ref クラス または値型の内部で、スタティック データ メンバのみ初期化することができます |
| static String^ wt = "日月火水木金土"; |
エラー 1 型または名前空間名 'ArrayList' が見つかりませんでした。 using ディレクティブまたはアセンブリ参照が不足しています。 C:\DATA\C#\02Console\15ArrayList\01ListInt\Prog.cs 11 9 Prog |
Recycle.cs(8,29): error CS0234: 型または名前空間名 'FileIO' は名前空間 'Microsoft.VisualBasic' に存在しません。 アセンブリ参照が不足しています。 |
| csc /r:Microsoft.VisualBasic.dll Recycle.cs |
エラー 1 型または名前空間名 'Drawing' は名前空間 'System' に存在しません。 アセンブリ参照が不足しています。 C:\DATA\C#\01テンプレート\03MyForm\Test\Console.cs 5 14 Console エラー 2 型または名前空間名 'Windows' は名前空間 'System' に存在しません。 アセンブリ参照が不足しています。 C:\DATA\C#\01テンプレート\03MyForm\Test\Console.cs 6 14 Console エラー 3 型または名前空間名 'Form' が見つかりませんでした。 using ディレクティブまたはアセンブリ参照が不足しています。 C:\DATA\C#\01テンプレート\03MyForm\Test\Console.cs 9 23 Console |
'C:\DATA\C#\DLL\Hello.dll' への参照を追加できませんでした。 ファイルにアクセスできて、有効なアセンブリであること、または COM コンポーネントであることを確認してください。 |
エラー 1 インスタンス参照で静的メンバ 'Wrapper.Wrap.func()' にアクセスできません。 typename を代わりに使用してください。 C:\DATA\C#\10DLL\CS_CLI\01Hello\Console.cs 12 9 Console |
エラー 1 fatal error C1107: アセンブリ 'Microsoft.DirectX.dll' がみつかりませんでした: /AI または LIBPATH 環境変数を使用してアセンブリ検索パスを指定してください。 |
#pragma warning(disable: 4995) |
#pragma warning(disable:4786 4788) |
#pragma warning(push) #pragma warning(disable: 4192) #pragma warning(disable: 4278) // ここでインクルード等のコードを記述します。 #pragma warning( pop ) |
/out:Test.exe Test.obj LINK : fatal error LNK1561: エントリー ポイントを定義しなければなりません。 |

|
ThredStateException はハンドルされませんでした。 OLE が呼び出される前に、現在のスレッドが Single Thread Apartment(STA) モードに設定されていなければなりません。 |
| アプリケーションのコンポーネントで、ハンドルされていない例外が発生しました。 |
| InvalidOperationException はハンドルされませんでした。 |
ReadOnly.exe は動作を停止しました。 ハンドルされていない例外: System.IO.FileNotFoundException: ファイル 'C:\TMP\work.txt' が見つかりませんでした。 |
FileNotFoundException はハンドルされませんでした。 ファイル 'C:\TMPコピー ~ Work.txt がみつかりませんでした。 |
MSVCR80.dll がないため、プログラムを開始できません。 |
マネージ デバッグ アシスタント 'LoaderLock' では 'c:\data\cli\directx\11dxform\debug\DXForm.exe' に問題を検出しました。 |
using namespace Platform; String^ msg = ref new String(L"Windows8 String Message"); |
Platform::String^ msg = ref new Platform::String(L"Windows8 String Message"); |
Windows.UI.Xaml.Media.Imaging.BitmapImage bi;
bi = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///ffx2s.jpg"));
imgout.Source = bi;
|
Windows::UI::Xaml::Media::Imaging::BitmapImage^ bi;
Uri^ ui = ref new Uri("ms-appx:///ffx2s.jpg");
bi = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(ui);
imgout->Source = bi;
|
DirectX::XMMATRIX dummy;
|



Failed create the Direct3D device |
![]()
/*********************************/
/*★ Unicode を使う 前田 稔 ★*/
/*********************************/
#include <windows.h>
WCHAR str1[80] = L"WCHAR[] で宣言";
wchar_t str2[80] = L"wchar_t[] で宣言";
//★ Windows Main 関数
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow)
{
MessageBox(NULL,str1,L"Message Box",MB_OK);
MessageBox(NULL,str2,L"Message Box",MB_OK);
return 0;
}
|
/***********************************/
/*★ MultiByte を使う 前田 稔 ★*/
/***********************************/
#include <windows.h>
#include <tchar.h>
LPSTR str1 = "LPSTR で宣言";
LPSTR str2 = _T("LPSTR で宣言");
//★ Windows Main 関数
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow)
{
MessageBox(NULL,_T("MultiByte / Unicode Program"),_T("Message Box"),MB_OK);
MessageBox(NULL,str1,str2,MB_OK);
return 0;
}
|
/*********************************/
/*★ Unicode を使う 前田 稔 ★*/
/*********************************/
#include <windows.h>
#include <tchar.h>
LPWSTR str3 = L"LPWSTR で宣言";
LPWSTR str4 = _T("LPWSTR で宣言");
//★ Windows Main 関数
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow)
{
MessageBox(NULL,_T("MultiByte / Unicode Program"),_T("Message Box"),MB_OK);
MessageBox(NULL,str3,str4,MB_OK);
return 0;
}
|
|
C:\DATA\TEST\WK.TXT C:\HTML\PUBLIC\Windows.html |
| "C:\\DATA\\TEST\\WK.TXT" |
| "\"TEXT DATA\"" |
|
"TEXT DATA\r\n" "TEXT DATA\n" |
| 文字 | 16進数 |
|---|---|
| \ | 5C |
| ソ | 835C |
| 構 | 8D5C |
| 表 | 955C |
| c:\TMP\ソース\テスト.TXT |
int g_Width = 1920; // ウインドウの幅 int g_Height = 1080; // ウインドウの高さ |
// strsafe Program File
#include <windows.h> //LPSTR
#include <stdio.h>
#include <strsafe.h>
#include <conio.h>
void main()
{
char str1[32] = "Unicode の文字列長を調べる";
LPSTR str2 = "LPWSTR で宣言";
size_t leng;
if (StringCbLength(str1, 32, &leng) != 0)
printf("str1 Error\r\n");
else printf("str1= %d\r\n", leng);
if (StringCbLength(str2, 24, &leng) != 0)
printf("str2 Error\r\n");
else printf("str2= %d\r\n", leng);
_getch();
}
|
// strsafe Program File
#include <windows.h> //LPSTR
#include <stdio.h>
#include <strsafe.h>
#include <conio.h>
void main()
{
LPSTR sou = "LPSTR で宣言";
char des[13];
if (StringCbCopy(des, 13, sou) != 0)
MessageBox(NULL,"Cb Copy Error","Error",MB_OK);
else MessageBox(NULL,des,"Copy",MB_OK);
}
|
// strsafe Program File
#include <windows.h> //MessageBox
#include <stdio.h>
#include <strsafe.h>
#include <conio.h>
void main()
{
char des[30] = "LPSTR で宣言\r\n";
char work[64];
size_t leng;
if (StringCbCat(des, 30, "連結文字列\r\n") != 0)
MessageBox(NULL,"CbCat Error","Error",MB_OK);
else
{
StringCbLength(des, 30, &leng);
if (StringCbPrintf(work, 64, "%s (%d)\r\n", des, leng) != 0)
MessageBox(NULL,"CbPrintf Error","Error",MB_OK);
else
{
OutputDebugString(work);
MessageBox(NULL,work,"CbCat",MB_OK);
}
}
}
|
// strsafe Program File
#include <windows.h>
#include <stdio.h>
#include <strsafe.h>
#include <conio.h>
void main()
{
WCHAR str1[24] = L"Unicode の文字列長を調べる";
LPWSTR str2 = L"LPWSTR で宣言";
size_t leng;
if (StringCchLength(str1, 24, &leng) != 0)
printf("str1 Error\r\n");
else printf("str1= %d\r\n", leng);
if (StringCchLength(str2, 24, &leng) != 0)
printf("str2 Error\r\n");
else printf("str2= %d\r\n", leng);
_getch();
}
|
// strsafe Program File
#include <windows.h>
#include <stdio.h>
#include <strsafe.h>
#include <conio.h>
void main()
{
LPWSTR sou = L"LPWSTR で宣言";
WCHAR des[12];
if (StringCbCopy(des, 12, sou) != 0)
MessageBox(NULL,L"Cb Copy Error",L"Error",MB_OK);
else MessageBox(NULL,des,L"Copy",MB_OK);
if (StringCchCopy(des, 12, sou) != 0)
MessageBox(NULL,L"Cch Copy Error",L"Error",MB_OK);
else MessageBox(NULL,des,L"Copy",MB_OK);
}
|
// strsafe Program File
// 連結後の長さ19文字
#include <windows.h>
#include <stdio.h>
#include <strsafe.h>
#include <conio.h>
void main()
{
WCHAR des[32] = L"LPWSTR で宣言\r\n";
WCHAR work[64];
size_t leng;
if (StringCchCat(des, 32, L"連結文字列\r\n") != 0)
MessageBox(NULL,L"CchCat",L"Error",MB_OK);
else
{
OutputDebugString(des);
StringCchLength(des, 32, &leng);
if (StringCchPrintf(work, 64, L"%s (%d)", des, leng) != 0)
MessageBox(NULL,L"CchPrintf Error",L"Error",MB_OK);
else MessageBox(NULL,work,L"Cat",MB_OK);
}
}
|
for (int i=0; i != j; i++)
{
・・・
}
for (i=10; i != k; i--)
{
・・・
}
|
for (int i=0; i != j; i++)
{
・・・
}
for (int i=10; i != k; i--)
{
・・・
}
|
FILE *FI; //FILE の定義 if (!(FI= fopen(file,"rb"))) オープンエラー |
FILE *FI; //FILE の定義 if (fopen_s(&FI,file,"rb")!=0) オープンエラー |
| GetDIBits(hdc,hbm,0,bm.bmHeight,imgbuf,(LPBITMAPINFO)&g_Bi,DIB_RGB_COLORS); |
| シンボル | 値 |
|---|---|
| TRUE | 1 |
| FALSE | 0 |
/*******************************/
/*★ BOOL type 前田 稔 ★*/
/*******************************/
#include <windows.h>
char buf[128];
BOOL aGTb(int a,int b)
{ if (a>b) return TRUE;
return FALSE;
}
//★ Windows Main 関数
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow)
{ BOOL rc;
rc= aGTb(3,8);
wsprintf(buf,"BOOL[%d] ",rc);
if (rc==TRUE) strcat(buf,"3>8 TRUE");
else strcat(buf,"3>8 FALSE");
MessageBox(NULL,buf,"BOOL",MB_OK);
rc= aGTb(8,3);
wsprintf(buf,"BOOL[%d] ",rc);
if (rc) strcat(buf,"8>3 TRUE");
else strcat(buf,"8>3 FALSE");
MessageBox(NULL,buf,"BOOL",MB_OK);
return 0;
}
|
| シンボル | 値 |
|---|---|
| TRUE | 1 |
| FALSE | 0 |
| S_OK | 0 |
| S_FALSE | 1 |
/**********************************/
/*★ LRESULT type 前田 稔 ★*/
/* S_OK==0 S_FALSE==1 */
/**********************************/
#include <windows.h>
char buf[128];
LRESULT func(HINSTANCE hInst)
{ if (LoadIcon(hInst,IDI_APPLICATION)==NULL) return S_OK;
return S_FALSE;
}
//★ Windows Main 関数
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow)
{ LRESULT rc;
rc= func(NULL);
wsprintf(buf,"LRESULT[%d] ",rc);
if (rc==S_OK) strcat(buf,"NULL S_OK");
else strcat(buf,"NULL S_FALSE");
MessageBox(NULL,buf,"LRESULT",MB_OK);
rc= func(hInst);
wsprintf(buf,"LRESULT[%d] ",rc);
if (rc==S_OK) strcat(buf,"hInst S_OK");
else strcat(buf,"hInst S_FALSE");
MessageBox(NULL,buf,"LRESULT",MB_OK);
return 0;
}
|
/**********************************/
/*★ HRESULT type 前田 稔 ★*/
/**********************************/
#include <windows.h>
char buf[128];
HRESULT func(int n)
{ switch(n)
{ case 0: return FALSE; //0
case 1: return TRUE; //1
case 2: return S_OK; //0
case 3: return S_FALSE; //1
case 4: return NULL; //0
}
return -1L;
}
//★ Windows Main 関数
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow)
{ HRESULT rc;
int i;
for(i=0; i<5; i++)
{ rc= func(i);
wsprintf(buf,"HRESULT[%d] ",rc);
MessageBox(NULL,buf,"HRESULT",MB_OK);
}
return 0;
}
|
☆SUCCEEDED, FAILED #define SUCCEEDED(Status) ((HRESULT)(Status) >= 0) #define FAILED(Status) ((HRESULT)(Status) < 0) |
| シンボル | 値 |
|---|---|
| FALSE | 0 |
| TRUE | 1 |
| S_OK | 0 |
| S_FALSE | 1 |
| NULL | 0 |
| E_FAIL | 0x80004005 |
/***************************************/
/*★ HRESULT type FAILED 前田 稔 ★*/
/***************************************/
#include <windows.h>
char buf[128];
HRESULT func(int n)
{ switch(n)
{ case 0: return FALSE; //NO(0)
case 1: return TRUE; //YES(1)
case 2: return S_OK; //成功(0)
case 3: return S_FALSE; //失敗(1)
case 4: return NULL; //空のポインタ
case 5: return E_FAIL; //失敗(0x80004005)
case 6: return 0XFFFF;
case 7: return -10L;
}
return -1L;
}
//★ Windows Main 関数
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow)
{ HRESULT hr;
int i;
for(i=0; i<9; i++)
{ hr= func(i);
wsprintf(buf,"NULL HRESULT[%d(%x)] ",hr,hr);
if (FAILED(hr)) strcat(buf,"失敗");
if (SUCCEEDED(hr)) strcat(buf,"成功");
MessageBox(NULL,buf,"HRESULT",MB_OK);
}
return 0;
}
|
