掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
iniファイル 取得について (ID:71001)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
インクルードとかリンクするのが面倒なら.NETっぽくDllImportで書いてみるとか。 using namespace System; using namespace System::Text; using namespace System::IO; using namespace System::Reflection; using namespace System::Runtime::InteropServices; [DllImport("kernel32.dll")] UInt32 GetPrivateProfileString(String^ lpAppName, String^ lpKeyName, String^ lpDefault, StringBuilder^ lpReturnedString, UInt32 nSize, String^ lpFileName); int main(array<System::String ^> ^args) { String^ path = Path::Combine(Path::GetDirectoryName(Assembly::GetEntryAssembly()->Location), L"test.ini"); StringBuilder^ sb = gcnew StringBuilder(1024); UInt32 ret = GetPrivateProfileString(L"DB_INFO", L"SERVER_NAME", L"default", sb, sb->Capacity, path); System::Console::WriteLine(sb->ToString()); return 0; } windows.hのインクードとkernel32.libをリンクする方法。 #include "windows.h" #pragma comment(lib, "kernel32.lib") // オプションで指定可 #include "vcclr.h" using namespace System; using namespace System::IO; using namespace System::Reflection; int main(array<System::String ^> ^args) { String^ path = Path::Combine(Path::GetDirectoryName(Assembly::GetEntryAssembly()->Location), L"test.ini"); pin_ptr<const wchar_t> pin_path = PtrToStringChars(path); wchar_t buff[1024]; DWORD ret = ::GetPrivateProfileStringW(L"DB_INFO", L"SERVER_NAME", L"default", buff, _countof(buff), pin_path); System::Console::WriteLine(%String(buff)); return 0; } 参考 過去ログの自分の発言より >ついでに、Win32 API を使うには >・#include <windows.h> を適当なところに記述する >・プロジェクトのプロパティから > リンカ→入力→追加の依存ファイル に適切な lib を追加する > (基本的に「親またはプロジェクトの規定値からの継承」をチェックすればOK) > ※ #pragam comment( lib, "〜〜〜.lib" ) でもOK ・#include <windows.h> を適当なところに記述する は正しくは #include "windows.h" ですね。
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.