Body
1.IntPtr converted into byte[]
public byte[] ConvertToBytes(IntPtr dataBuf, int length)
{
byte[] byteBuf = new byte[length];
Marshal.Copy(dataBuf, byteBuf, 0, length);
return byteBuf;
}
2. Read and write INI file
Generally used to read and write configuration files
<summary>
Read and write INI file
</summary>
public class IniFile
{
<summary>
File ini Name
</summary>
public string Path;
<summary>
Declaring API functions for reading and writing INI files
</summary>
<param name= "section" ></param>
<param name= "Key" ></param>
<param name= "Val" ></param>
<param name= "FilePath" ></param>
<returns></returns>
[DllImport ("kernel32")]
private static extern long WritePrivateProfileString (string section, string key, String val, string filePath);
[DllImport ("kernel32")]
private static extern int getprivateprofilestring (string section, String key, String Def, StringBuilder retVal, int size, String filePath);
<summary>
Class, passing the INI file name
</summary>
<param name= "IniPath" ></param>
Public IniFile (String inipath)
{
//
Todo:add constructor Logic here
//
Path = IniPath;
}
<summary>
Write INI file
</summary>
<param name= "section" ></param>
<param name= "Key" ></param>
<param name= "Value" ></param>
public void Iniwritevalue (string section, String Key, String Value)
{
WritePrivateProfileString (section, Key, Value, this.) Path);
}
<summary>
Reading the INI file specifies
</summary>
<param name= "section" ></param>
<param name= "Key" ></param>
<returns></returns>
public string Inireadvalue (string section, String Key)
{
StringBuilder temp = new StringBuilder (5000);
int i = getprivateprofilestring (section, Key, "", temp, 5000, this. Path);
Return temp. ToString ();
}
}