版本: 0.2.2
授权方式:GNU GPL
著作权所有(c) 2007 Midapex
本程序为自由软件;您可依据自由软件基金会所发表的GNU通用公共授权条款规定,就本程序再为发布与/或修改;无论您依据的是本授权的第二版或(您自行选择的)任一日后发行的版本。
本程序是基于使用目的而加以发布,然而不负任何担保责任;亦无对适售性或特定目的适用性所为的默示性担保。详情请参照GNU通用公共授权。
源代码下载地址: http://www.cppblog.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 #pragmaonce
11 usingnamespace System;
12
13 namespace Midapex
14 {
15 publicref 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 }