VC#2008 型 DLL対応について
C#の変数のDLL対応について記述します。
[Windows] : [C] : [C#] : [.NET]
-----------------------------------------
BOOL : long : bool : System.Boolean
BYTE : unsigned char : byte : System.Byte
--- : --- : sbyte : System.SByte
CHAR : char : char : System.Char
--- : --- : decimal : System.Decimal
DOUBLE : double : double : System.Double
FLOAT : float : float : System.Single
SHORT : short : short : System.Int16
INT : int : int : System.Int32
LONG : long : long : System.Int32
UINT : unsigned int : uint : System.UInt32
ULONG : unsigned long : uint : System.UInt32
WORD : unsigned short : ushort : System.UInt16
LPSTR : char* : --- : System.Text.StringBuilder
LPCSTR : const char* : string : System.String
2008年6月25日水曜日
2008年6月18日水曜日
VC#2008 型 .NETの関係について
VC#2008 型 .NETの関係について
C#と.NETの変数の型について記述します。
[C#] [.NET]
bool → System.Boolean
byte → System.Byte
sbyte → System.SByte
char → System.Char
decimal → System.Decimal
double → System.Double
float → System.Single
short → System.Int16
int → System.Int32
long → System.Int64
ushort → System.UInt16
uint → System.UInt32
ulong → System.UInt64
string → System.String
C#と.NETの変数の型について記述します。
[C#] [.NET]
bool → System.Boolean
byte → System.Byte
sbyte → System.SByte
char → System.Char
decimal → System.Decimal
double → System.Double
float → System.Single
short → System.Int16
int → System.Int32
long → System.Int64
ushort → System.UInt16
uint → System.UInt32
ulong → System.UInt64
string → System.String
2008年6月11日水曜日
>Form1 にツールボックスの以下のコントロールを配置のやり方がわかりません
2008年5月27日火曜日
SQL Server データベースの作り方
SQL Server データベースの作り方
■以下のソフトがインストールされていることを確認する。なければインストールする。
スタート -> すべてのプログラム -> Microsoft SQL Server 2005 を確認する。
1) SQL構成マネージャー(SQL Server Configuration Manager)
2) Microsoft SQL Server Management Studio Express
■SQL Serverの認証を許可する
1)SQL構成マネージャー(SQL Server Configuration Manager)を起動する。
2)SQL Server 2005 ネットワークの構成 -> SQLEXPRESS のプロトコル -> 名前付きパイプ を「有効」にする
■データベースを作成する
1)Microsoft SQL Server Management Studio Express を起動する。
2)[新しいクエリ]で 以下を貼り付けて実行する。
------ 貼り付けるテキスト ------
CREATE DATABASE [TestDB] ON (NAME = 'TestDB_Data', FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\TestDB_Data.MDF') LOG ON (NAME = 'TestDB_Log', FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\TestDB_Log.LDF')
GO
use [TestDB]
GO
CREATE TABLE [dbo].[顧客] (
[ID] [int] PRIMARY KEY ,
[姓] [ntext] ,
[名] [ntext] ,
[姓かな] [ntext] ,
[名かな] [ntext] ,
[性別] [int] ,
[自宅パソコンメール] [bit] ,
[携帯メール] [bit] ,
[職場パソコンメール] [bit] ,
[その他メール] [bit] ,
[その他メールの説明] [ntext] ,
[メールアドレス] [ntext] ,
[誕生日] [datetime] ,
[電話番号] [ntext]
)
GO
CREATE TABLE [dbo].[性別] (
[ID] [int] PRIMARY KEY ,
[名称] [ntext]
)
GO
------ 貼り付けるテキスト ------
■以下のソフトがインストールされていることを確認する。なければインストールする。
スタート -> すべてのプログラム -> Microsoft SQL Server 2005 を確認する。
1) SQL構成マネージャー(SQL Server Configuration Manager)
2) Microsoft SQL Server Management Studio Express
■SQL Serverの認証を許可する
1)SQL構成マネージャー(SQL Server Configuration Manager)を起動する。
2)SQL Server 2005 ネットワークの構成 -> SQLEXPRESS のプロトコル -> 名前付きパイプ を「有効」にする
■データベースを作成する
1)Microsoft SQL Server Management Studio Express を起動する。
2)[新しいクエリ]で 以下を貼り付けて実行する。
------ 貼り付けるテキスト ------
CREATE DATABASE [TestDB] ON (NAME = 'TestDB_Data', FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\TestDB_Data.MDF') LOG ON (NAME = 'TestDB_Log', FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\TestDB_Log.LDF')
GO
use [TestDB]
GO
CREATE TABLE [dbo].[顧客] (
[ID] [int] PRIMARY KEY ,
[姓] [ntext] ,
[名] [ntext] ,
[姓かな] [ntext] ,
[名かな] [ntext] ,
[性別] [int] ,
[自宅パソコンメール] [bit] ,
[携帯メール] [bit] ,
[職場パソコンメール] [bit] ,
[その他メール] [bit] ,
[その他メールの説明] [ntext] ,
[メールアドレス] [ntext] ,
[誕生日] [datetime] ,
[電話番号] [ntext]
)
GO
CREATE TABLE [dbo].[性別] (
[ID] [int] PRIMARY KEY ,
[名称] [ntext]
)
GO
------ 貼り付けるテキスト ------
2008年5月17日土曜日
VC++2005/2008 get() set() を property で実現する
VC++2005/2008 get() set() を property で実現する
クラスのメンバ変数をアクセスするのに get() set() メソッドを用意するのは一般的ですが、property を利用すればすっきり記述できます。
■property を使ったクラス
public ref class pro
{
private: Byte tbl_; // プライベート宣言
public: property Byte tbl // get() set() の tblパブリック宣言
{
void set(Byte val)
{
tbl_ = val;
}
Byte get()
{
return tbl_;
}
}
};
■呼出側
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
pro^ pp = gcnew pro();
pp->tbl = 10;
}
クラスのメンバ変数をアクセスするのに get() set() メソッドを用意するのは一般的ですが、property を利用すればすっきり記述できます。
■property を使ったクラス
public ref class pro
{
private: Byte tbl_; // プライベート宣言
public: property Byte tbl // get() set() の tblパブリック宣言
{
void set(Byte val)
{
tbl_ = val;
}
Byte get()
{
return tbl_;
}
}
};
■呼出側
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
pro^ pp = gcnew pro();
pp->tbl = 10;
}
VC++2005/2008 配列を array でマネージ化
VC++2005/2008 配列を array でマネージ化
配列をマネージ化したとき以下のようになります。
■ネイティブ
unsigned char aaa[3];
aaa[0] = 1;
aaa[1] = 2;
aaa[2] = 3;
unsigned char bbb[3];
memcpy( bbb , aaa , sizeof(bbb) );
■マネージ
array<Byte>^ aaa = gcnew array<Byte>(3);
aaa[0] = 1;
aaa[1] = 2;
aaa[2] = 3;
array<Byte>^ bbb = gcnew array<Byte>(3);
aaa->CopyTo(bbb, 0);
■ちなみに文字数を調べるには sizeof() 以下のようにします。
Int32 len = aaa->Length;
配列をマネージ化したとき以下のようになります。
■ネイティブ
unsigned char aaa[3];
aaa[0] = 1;
aaa[1] = 2;
aaa[2] = 3;
unsigned char bbb[3];
memcpy( bbb , aaa , sizeof(bbb) );
■マネージ
array<Byte>^ aaa = gcnew array<Byte>(3);
aaa[0] = 1;
aaa[1] = 2;
aaa[2] = 3;
array<Byte>^ bbb = gcnew array<Byte>(3);
aaa->CopyTo(bbb, 0);
■ちなみに文字数を調べるには sizeof() 以下のようにします。
Int32 len = aaa->Length;
2008年5月15日木曜日
VC++2005/2008 マネージ 線形リスト クラス
VC++2005/2008 マネージ 線形リスト クラス
マネージで線形リストが扱えるクラス(List.h)を作りました。マネージでは new の代わりに gcnew を使用するため、関数のスコープが外れたときでも gcnew で確保した内容が消えないようにしなければなりません。
以下は、線形リストで追加と削除ができるクラスです。先入れ先出のみの対応で、リストの真ん中に対して挿入・削除は対応しておりません。
**** List.h ****
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///------------------------------------------------
/// ■リストタイプクラスの先頭
///------------------------------------------------
ref class CListType
{
public: Int32 no; // リスト番号
public: array<unsigned char>^ buff; // 格納データ
public: Int32 len; // 文字数
public: CListType^ next; // 次の要素へのポインタ
///------------------------------------------------
/// コンストラクタ
///------------------------------------------------
public: CListType(Int32 length)
{
buff = gcnew array<unsigned char>(length);
len = length;
next = nullptr;
}
///------------------------------------------------
}; // ■クラスの最後
///------------------------------------------------
///------------------------------------------------
/// ■リストクラスの先頭
///------------------------------------------------
ref class CList
{
///------------------------------------------------
/// テーブル宣言
///------------------------------------------------
public: CListType^ head; // リストの先頭要素(ダミー)
public: CListType^ p;
public: CListType^ q;
public: CListType^ newcell;
public: CListType^ output;
public: Int32 No;
///------------------------------------------------
/// コンストラクタ
///------------------------------------------------
public: CList()
{
head = gcnew CListType(1); // リストヘッダー宣言
No = 0;
}
///------------------------------------------------
/// 追加
///------------------------------------------------
public: bool addlist(CListType^ input)
{
p = head->next; // 先頭要素の次の要素のアドレス
q = head; // 先頭要素のアドレス
while( p != nullptr )
{
q = p; // 追加位置の直前の要素のnextを後で設定するために、追加位置の直前の要素のアドレスを記憶しておく
p = p->next; // 次の要素へ進む
}
newcell = gcnew CListType(input->len); // 新しく追加する要素のためのメモリ領域を確保する
if( newcell == nullptr ){
return false; // メモリ不足
}
input->no = ++No;
for(Int32 ii=0; ii<(input->len); ii++){
newcell->buff[ii] = input->buff[ii]; // 新しい要素のデータを設定
}
newcell->len = input->len; // 文字数設定
newcell->next = p; // 新しい要素の次の要素へのアドレスを設定
q->next = newcell; // 新しい要素の直前の要素のnextに、新しい要素のアドレスを設定
return true;
}
///------------------------------------------------
/// 削除
///------------------------------------------------
public: CListType^ deletelist(void)
{
p = head->next; // 先頭要素の次の要素のアドレス
q = head; // 先頭要素のアドレス
if( p == nullptr ){ // リストの末尾
return nullptr;
}
else{
output = gcnew CListType(p->len); // 取出領域確保
output->no = --No;
for(Int32 ii=0; ii<(p->len); ii++){
output->buff[ii] = p->buff[ii]; // 新しい要素のデータを設定
}
output->len = p->len;
q->next = p->next; // 削除する要素の直前の要素のnextポインタを再設定
delete p;
}
return output;
}
///------------------------------------------------
}; // ■クラスの最後
///------------------------------------------------
マネージで線形リストが扱えるクラス(List.h)を作りました。マネージでは new の代わりに gcnew を使用するため、関数のスコープが外れたときでも gcnew で確保した内容が消えないようにしなければなりません。
以下は、線形リストで追加と削除ができるクラスです。先入れ先出のみの対応で、リストの真ん中に対して挿入・削除は対応しておりません。
**** List.h ****
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///------------------------------------------------
/// ■リストタイプクラスの先頭
///------------------------------------------------
ref class CListType
{
public: Int32 no; // リスト番号
public: array<unsigned char>^ buff; // 格納データ
public: Int32 len; // 文字数
public: CListType^ next; // 次の要素へのポインタ
///------------------------------------------------
/// コンストラクタ
///------------------------------------------------
public: CListType(Int32 length)
{
buff = gcnew array<unsigned char>(length);
len = length;
next = nullptr;
}
///------------------------------------------------
}; // ■クラスの最後
///------------------------------------------------
///------------------------------------------------
/// ■リストクラスの先頭
///------------------------------------------------
ref class CList
{
///------------------------------------------------
/// テーブル宣言
///------------------------------------------------
public: CListType^ head; // リストの先頭要素(ダミー)
public: CListType^ p;
public: CListType^ q;
public: CListType^ newcell;
public: CListType^ output;
public: Int32 No;
///------------------------------------------------
/// コンストラクタ
///------------------------------------------------
public: CList()
{
head = gcnew CListType(1); // リストヘッダー宣言
No = 0;
}
///------------------------------------------------
/// 追加
///------------------------------------------------
public: bool addlist(CListType^ input)
{
p = head->next; // 先頭要素の次の要素のアドレス
q = head; // 先頭要素のアドレス
while( p != nullptr )
{
q = p; // 追加位置の直前の要素のnextを後で設定するために、追加位置の直前の要素のアドレスを記憶しておく
p = p->next; // 次の要素へ進む
}
newcell = gcnew CListType(input->len); // 新しく追加する要素のためのメモリ領域を確保する
if( newcell == nullptr ){
return false; // メモリ不足
}
input->no = ++No;
for(Int32 ii=0; ii<(input->len); ii++){
newcell->buff[ii] = input->buff[ii]; // 新しい要素のデータを設定
}
newcell->len = input->len; // 文字数設定
newcell->next = p; // 新しい要素の次の要素へのアドレスを設定
q->next = newcell; // 新しい要素の直前の要素のnextに、新しい要素のアドレスを設定
return true;
}
///------------------------------------------------
/// 削除
///------------------------------------------------
public: CListType^ deletelist(void)
{
p = head->next; // 先頭要素の次の要素のアドレス
q = head; // 先頭要素のアドレス
if( p == nullptr ){ // リストの末尾
return nullptr;
}
else{
output = gcnew CListType(p->len); // 取出領域確保
output->no = --No;
for(Int32 ii=0; ii<(p->len); ii++){
output->buff[ii] = p->buff[ii]; // 新しい要素のデータを設定
}
output->len = p->len;
q->next = p->next; // 削除する要素の直前の要素のnextポインタを再設定
delete p;
}
return output;
}
///------------------------------------------------
}; // ■クラスの最後
///------------------------------------------------
登録:
投稿 (Atom)