工程:在.NET中實現INI文件讀寫API
版本: 0.2.2
授權方式:GNU GPL
著作權所有(c) 2007 Midapex
本程序為自由軟件;您可依據自由軟件基金會所發表的GNU通用公共授權條款規定,就本程序再為發布與/或修改;無論您依據的是本授權的第二版或(您自行選擇的)任一日后發行的版本。
本程序是基于使用目的而加以發布,然而不負任何擔保責任;亦無對適售性或特定目的適用性所為的默示性擔保。詳情請參照GNU通用公共授權。
源代碼下載地址:
http://www.shnenglu.com/Files/dyj057/IniFileCliV0.2.2.zip描述:
使用C++/CLI封裝C++實現的INI文件讀寫API,可以應用在.NET平臺。
已測試通過的開發環境:
WinXP+VS2005
應用舉例(C#):
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using Midapex;
5
6 namespace TestIniFile
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 NIniFile ini = new NIniFile("myconfig.ini");
13 string nameKey = "name";
14 string ageKey = "age";
15
16 ini.Section = "student";
17 ini.Write(nameKey, "Tony");
18 ini.Write(ageKey, 20);
19 Console.WriteLine("[{0}]", ini.Section);
20 Console.WriteLine("{0}={1}",nameKey, ini.Read(nameKey, ""));
21 Console.WriteLine("{0}={1}",ageKey, ini.Read(ageKey, -1));
22 }
23 }
24 }
類頭文件聲明如下(C++/CLI):
1 // ***************************************************************
2 // version: 0.2.2 date: 12/13/2007
3 // -------------------------------------------------------------
4 // Wrapper C++ IniFile class for .NET
5 // -------------------------------------------------------------
6 // Copyright (C) 2007 - All Rights Reserved
7 // ***************************************************************
8 //
9 // ***************************************************************
10 #pragma once
11 using namespace System;
12
13 namespace Midapex
14 {
15 public ref class NIniFile
16 {
17 public :
18 NIniFile(String^ fileName)
19 {
20 m_fileName = fileName;
21 }
22
23 property String^ Section
24 {
25 String^ get() { return m_section; }
26 void set (String^ section) { m_section = section; }
27 }
28
29 void Write(String^ key, String^ strVlaue);
30 void Write(String^ key, int intValue);
31
32 String^ Read(String^ key, String^ defaultStrValue);
33 int Read(String^ key, int defaultIntValue);
34
35 private:
36 String^ m_fileName;
37 String^ m_section;
38 };
39 }
posted on 2007-12-13 12:17
天下無雙 閱讀(2193)
評論(2) 編輯 收藏 引用 所屬分類:
C/C++