2021年7月7日 星期三

 C# 讀寫 ini 檔案

使用 kernel32.DLL

引用:using System.Runtime.InteropServices; //DllImport

範例:


 class clsINI

    {

        [DllImport("kernel32")]

        private static extern bool WritePrivateProfileString(string section, string key, string def,  string filePath);

        [DllImport("kernel32")]

        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);


        private string iniFileName;

        //private bool bDisposed = false;


        public clsINI(string xfilepath)

        {

            iniFileName = xfilepath;

        }

        public void WriteIni(string section, string key, string val)

        {

            WritePrivateProfileString(section, key, val, iniFileName);

        }

        public string ReadIni(string section, string key)

        {

            StringBuilder temp = new StringBuilder(255);

            GetPrivateProfileString(section, key, "", temp, 255, iniFileName);

            return temp.ToString();

        }

    }


參考:

https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-writeprivateprofilestringa

https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getprivateprofilestring


沒有留言:

張貼留言

DiCom 篇

 首先,要找到參考資料 (1) dicomlibrary: https://www.dicomlibrary.com/dicom/dicom-tags/  ,認識DiCom 的標籤。 (2) 再來一個參考文件: 數位醫學影像去識別化實作指引手冊 (3)DiCom 元件: GitH...