posts - 45,  comments - 232,  trackbacks - 0
工程:在.NET中实现INI文件读写API
版本: 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 #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 天下无双 阅读(2157) 评论(2)  编辑 收藏 引用 所属分类: C/C++

FeedBack:
# re: 在.NET中实现INI文件读写API V0.2.2
2007-12-13 13:23 | 梦在天涯
qiang !  回复  更多评论
  
# re: 在.NET中实现INI文件读写API V0.2.2
2007-12-18 12:00 | 秦歌
ding  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



常用链接

留言簿(15)

随笔分类

随笔档案

相册

我的其它领域Blog

搜索

  •  

积分与排名

  • 积分 - 202567
  • 排名 - 128

最新评论

阅读排行榜

评论排行榜