//---定义
[DllImport("kernel32")]
static extern int GetPrivateProfileString(string strApplicationName,string strKeyName,string strDefalult,StringBuilder strReturnedString, long nSize,string strFileName);
//---引用
StringBuilder strCaption
strpath = @"C:\Test.ini"//该文件存在
int result = GetPrivateProfileString("DatabaseConnetion","ServerName","NULL",strCaption,strCaption.Capacity,strpath);
可是,比较怪...
StrCaption.ToString()返回的总是默认值"NULL"

解决方案 »

  1.   

    我以前也遇到这样的问题,应该第一个还是能读出来的,但是第二个应该就是NULL了,用API读INI的时候遇到二进制0的时候就结束了,后面的字符没有办法读取的。后来没有办法,只好改用XML来解决,不够偶觉得XML比INI好用
      

  2.   

    你查看一下MSDN
    INI的读写API好像要求注册表中要有键值的
      

  3.   

    用XML吧,时代在进步,搂住要与时俱进,强烈建议用XML
      

  4.   

    //---引用
    StringBuilder strCaptionnew StringBuilder (256);
    strpath = @"C:\Test.ini
    int result = GetPrivateProfileString("DatabaseConnetion","ServerName","NULL",strCaption,strCaption.Capacity,strpath);
      

  5.   

    如果不行,请检查你的ini文件:
    [DatabaseConnetion]
    ServerName=。
      

  6.   

    //---引用
    StringBuilder strCaption楼主直接用 string strcaption试试
      

  7.   

    我没有用INI了,改用XML文件了