「C++/CLI/clrapi」の編集履歴(バックアップ)一覧はこちら

C++/CLI/clrapi - (2012/09/28 (金) 06:06:14) の1つ前との変更点

追加された行は緑色になります。

削除された行は赤色になります。

|開発環境|Microsoft Visual C++ 2010 Express (SP1)| |実行環境|Microsoft Windows XP Home Edition (SP3)| |プロジェクトの種類|空の CLR プロジェクト| |プロジェクト名|clrapi| 参考 -[[Win32 APIやDLL関数を呼び出すには?>http://www.atmarkit.co.jp/fdotnet/dotnettips/024w32api/w32api.html]] -[[GetPrivateProfileStringにみるAPIの使用方法>http://www5b.biglobe.ne.jp/~yone-ken/VBNET/special/sp06_GetPrivateProfileString.html]] clrapi1.cpp #highlight(cpp){{ using namespace System; using namespace System::Runtime::InteropServices; typedef IntPtr HWND; typedef UInt32 UINT; typedef String^ LPCTSTR; [DllImport("user32", CharSet=CharSet::Auto)] extern "C" { int MessageBox( HWND hWnd, // オーナーウィンドウのハンドル LPCTSTR lpText, // メッセージボックス内のテキスト LPCTSTR lpCaption, // メッセージボックスのタイトル UINT uType // メッセージボックスのスタイル ); } int main() { String^ lpText = L"hello, world"; String^ lpCaption = L"Platform Invoke Sample"; MessageBox((HWND)0, lpText, lpCaption, 0); return 0; } }} ---- clrapi2.cpp #highlight(cpp){{ using namespace System; using namespace System::Text; using namespace System::Runtime::InteropServices; typedef Int32 INT; typedef UInt32 UINT; typedef Int32 BOOL; typedef UInt32 DWORD; typedef StringBuilder^ LPTSTR; typedef String^ LPCTSTR; [DllImport("kernel32", CharSet=CharSet::Auto)] UINT GetPrivateProfileInt( LPCTSTR lpAppName, // セクション名 LPCTSTR lpKeyName, // キー名 INT nDefault, // キー名が見つからなかった場合に返すべき値 LPCTSTR lpFileName // .ini ファイルの名前 ); [DllImport("kernel32", CharSet=CharSet::Auto)] DWORD GetPrivateProfileString( LPCTSTR lpAppName, // セクション名 LPCTSTR lpKeyName, // キー名 LPCTSTR lpDefault, // 既定の文字列 LPTSTR lpReturnedString, // 情報が格納されるバッファ DWORD nSize, // 情報バッファのサイズ LPCTSTR lpFileName // .ini ファイルの名前 ); [DllImport("kernel32", CharSet=CharSet::Auto)] BOOL WritePrivateProfileString( LPCTSTR lpAppName, // セクション名 LPCTSTR lpKeyName, // キー名 LPCTSTR lpString, // 追加するべき文字列 LPCTSTR lpFileName // .ini ファイル ); //============================================================================== int main() { String^ sectName = L"General"; String^ fileName = L"C:\\tmp\\clrapi.ini"; // C:\WINDOWSに作られたりする StringBuilder^ retStr = gcnew StringBuilder(4); UINT ui; DWORD dw; WritePrivateProfileString(sectName, L"x", L"4649", fileName); ui = GetPrivateProfileInt(sectName, L"x", 0, fileName); Console::WriteLine(L"x=[{0}]", ui); dw = GetPrivateProfileString(sectName, L"x", L"", retStr, retStr->Capacity, fileName); Console::WriteLine(L"dw=[{0}] x=[{1}]", dw, retStr); Console::ReadLine(); return 0; } }} 出力 x=[4649] dw=[3] x=[464]
|開発環境|Microsoft Visual C++ 2010 Express (SP1)| |実行環境|Microsoft Windows XP Home Edition (SP3)| |プロジェクトの種類|空の CLR プロジェクト| |プロジェクト名|clrapi| 参考 -[[属性 (C# によるプログラミング入門)>http://ufcpp.net/study/csharp/sp_attribute.html]] -[[Win32 APIやDLL関数を呼び出すには?>http://www.atmarkit.co.jp/fdotnet/dotnettips/024w32api/w32api.html]] -[[GetPrivateProfileStringにみるAPIの使用方法>http://www5b.biglobe.ne.jp/~yone-ken/VBNET/special/sp06_GetPrivateProfileString.html]] clrapi1.cpp #highlight(cpp){{ using namespace System; using namespace System::Runtime::InteropServices; // Managed class name typedef IntPtr HWND; typedef UInt32 UINT; typedef String^ LPCTSTR; /*/ // Unmanaged C language type typedef void* HWND; typedef unsigned int UINT; typedef const wchar_t* LPCTSTR; */ [DllImport("user32", CharSet=CharSet::Auto)] int MessageBox( HWND hWnd, // オーナーウィンドウのハンドル LPCTSTR lpText, // メッセージボックス内のテキスト LPCTSTR lpCaption, // メッセージボックスのタイトル UINT uType // メッセージボックスのスタイル ); //============================================================================== int main() { String^ lpText = L"hello, world"; String^ lpCaption = L"Platform Invoke Sample"; MessageBox((HWND)0, lpText, lpCaption, 0); // MessageBox(0, L"hello, world", L"Platform Invoke Sample", 0); return 0; } }} ---- clrapi2.cpp #highlight(cpp){{ using namespace System; using namespace System::Text; using namespace System::Runtime::InteropServices; typedef Int32 INT; typedef UInt32 UINT; typedef Int32 BOOL; typedef UInt32 DWORD; typedef StringBuilder^ LPTSTR; typedef String^ LPCTSTR; [DllImport("kernel32", CharSet=CharSet::Auto)] UINT GetPrivateProfileInt( LPCTSTR lpAppName, // セクション名 LPCTSTR lpKeyName, // キー名 INT nDefault, // キー名が見つからなかった場合に返すべき値 LPCTSTR lpFileName // .ini ファイルの名前 ); [DllImport("kernel32", CharSet=CharSet::Auto)] DWORD GetPrivateProfileString( LPCTSTR lpAppName, // セクション名 LPCTSTR lpKeyName, // キー名 LPCTSTR lpDefault, // 既定の文字列 LPTSTR lpReturnedString, // 情報が格納されるバッファ DWORD nSize, // 情報バッファのサイズ LPCTSTR lpFileName // .ini ファイルの名前 ); [DllImport("kernel32", CharSet=CharSet::Auto)] BOOL WritePrivateProfileString( LPCTSTR lpAppName, // セクション名 LPCTSTR lpKeyName, // キー名 LPCTSTR lpString, // 追加するべき文字列 LPCTSTR lpFileName // .ini ファイル ); //============================================================================== int main() { String^ sectName = L"General"; String^ fileName = L"C:\\tmp\\clrapi.ini"; // C:\WINDOWSに作られたりする StringBuilder^ retStr = gcnew StringBuilder(4); UINT ui; DWORD dw; WritePrivateProfileString(sectName, L"x", L"4649", fileName); ui = GetPrivateProfileInt(sectName, L"x", 0, fileName); Console::WriteLine(L"x=[{0}]", ui); dw = GetPrivateProfileString(sectName, L"x", L"", retStr, retStr->Capacity, fileName); Console::WriteLine(L"dw=[{0}] x=[{1}]", dw, retStr); Console::ReadLine(); return 0; } }} 出力 x=[4649] dw=[3] x=[464]

表示オプション

横に並べて表示:
変化行の前後のみ表示: