您的位置:首页 > 其它

调用API函数读写INI

2006-09-15 17:54 99 查看

using System;


using System.Collections.Generic;


using System.Text;


using System.Runtime.InteropServices;




namespace Config




...{


class PrivateProfile




...{




/**//// <summary>


/// 添加GetPrivateProfileInt等API函数的声明


/// </summary>




//UINT GetPrivateProfileInt(


// LPCTSTR lpAppName,


// LPCTSTR lpKeyName,


// INT nDefault,


// LPCTSTR lpFileName


//);


[DllImport("kernel32", EntryPoint = "GetPrivateProfileInt")]


public static extern int GetInt(


string lpAppName,


string lpKeyName,


int nDefault,


string lpFileName);




//DWORD GetPrivateProfileSection(


// LPCTSTR lpAppName,


// LPTSTR lpReturnedString,


// DWORD nSize,


// LPCTSTR lpFileName


//);


[DllImport("kernel32", EntryPoint = "GetPrivateProfileSection")]


public static extern int GetSection(


string lpAppName,


StringBuilder lpReturnedString,


int nSize,


string lpFileName);




//DWORD GetPrivateProfileSectionNames(


// LPTSTR lpszReturnBuffer,


// DWORD nSize,


// LPCTSTR lpFileName


//);


[DllImport("kernel32", EntryPoint = "GetPrivateProfileSectionNames")]


public static extern int GetSectionNames(


StringBuilder lpszReturnBuffer,


int nSize,


string lpFileName);




//DWORD GetPrivateProfileString(


// LPCTSTR lpAppName,


// LPCTSTR lpKeyName,


// LPCTSTR lpDefault,


// LPTSTR lpReturnedString,


// DWORD nSize,


// LPCTSTR lpFileName


//);


[DllImport("kernel32", EntryPoint = "GetPrivateProfileString")]


public static extern int GetString(


string lpAppName,


string lpKeyName,


string lpDefault,


StringBuilder lpReturnedString,


int nSize,


string lpFileName);




//BOOL GetPrivateProfileStruct(


// LPCTSTR lpszSection,


// LPCTSTR lpszKey,


// LPVOID lpStruct,


// UINT uSizeStruct,


// LPCTSTR szFile


//);


[DllImport("kernel32", EntryPoint = "GetPrivateProfileStruct")]


unsafe public static extern bool GetStruct(


string lpszSection,


string lpszKey,


void* lpStruct,


uint uSizeStruct,


string szFile


);




//BOOL WritePrivateProfileSection(


// LPCTSTR lpAppName,


// LPCTSTR lpString,


// LPCTSTR lpFileName


//);


[DllImport("kernel32",EntryPoint = "WritePrivateProfileSection" )]


public static extern bool WriteSection(


string lpAppName,


string lpString,


string lpFileName);




// BOOL WritePrivateProfileString(


// LPCTSTR lpAppName,


// LPCTSTR lpKeyName,


// LPCTSTR lpString,


// LPCTSTR lpFileName


//);


[DllImport("kernel32", EntryPoint = "WritePrivateProfileString")]


public static extern bool WriteString(


string lpAppName,


string lpKeyName,


string lpString,


string lpFileName);




//BOOL WritePrivateProfileStruct(


// LPCTSTR lpszSection,


// LPCTSTR lpszKey,


// LPVOID lpStruct,


// UINT uSizeStruct,


// LPCTSTR szFile


//);


[DllImport("kernel32", EntryPoint = "WritePrivateProfileStruct")]


unsafe public static extern bool WriteStruct(


string lpszSection,


string lpszKey,


void* lpStruct,


uint uSizeStruct,


string szFile);


}


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: