这是从最近做的一个图像采集模块中抽出来的代码,用来读取可执行文件当前目录下的图像卡配置文文件MonitorCard.ini
int
m_ScanMode
=
(
int
)GetPrivateProfileInt(
"
Video Parameter
"
,
"
Scan
"
,
100
,
"
./MonitorCard.ini
"
);
int m_VideoStandard = ( int )GetPrivateProfileInt( " Video Parameter " , " Standard " , 100 ,
int m_VideoStandard = ( int )GetPrivateProfileInt( " Video Parameter " , " Standard " , 100 ,
"
./MonitorCard.ini
"
);
int m_VideoFormat = ( int )GetPrivateProfileInt( " Video Parameter " , " Format " , 100 , " ./MonitorCard.ini " );
int type = ( int )GetPrivateProfileInt( " Video Parameter " , " VideoSourceType " , 100 , " ./MonitorCard.ini " );
int nIndex = ( int )GetPrivateProfileInt( " Video Parameter " , " VideoSourceIndex " , 100 , " ./MonitorCard.ini " );
int m_CryOsc = ( int )GetPrivateProfileInt( " Video Parameter " , " CryOsc " , 100 , " ./MonitorCard.ini " );
int m_VideoFormat = ( int )GetPrivateProfileInt( " Video Parameter " , " Format " , 100 , " ./MonitorCard.ini " );
int type = ( int )GetPrivateProfileInt( " Video Parameter " , " VideoSourceType " , 100 , " ./MonitorCard.ini " );
int nIndex = ( int )GetPrivateProfileInt( " Video Parameter " , " VideoSourceIndex " , 100 , " ./MonitorCard.ini " );
int m_CryOsc = ( int )GetPrivateProfileInt( " Video Parameter " , " CryOsc " , 100 , " ./MonitorCard.ini " );
其中MonitorCard.ini文件的格式如下:
[Video Parameter]
Scan = 0
Standard = 0
Format = 4
VideoSourceType = 0
VideoSourceIndex = 0
CryOsc = 0
Scan = 0
Standard = 0
Format = 4
VideoSourceType = 0
VideoSourceIndex = 0
CryOsc = 0
这样,GetPrivateProfileInt函数四个参数的含义就一目了然了!
注意:GetPrivateProfileString中最后一个参数也就是配置文件的位置不能写相对目录,必须是绝对目录,因此我们可以这样处理:
CString path;
::GetCurrentDirectory(_MAX_PATH,path.GetBuffer(_MAX_PATH));
path.ReleaseBuffer();
path += " /config.ini " ;
DWORD len = GetPrivateProfileString(
" DZH " ,
" AppName " ,
"默认字符串内容 " ,
m_appName.GetBuffer(_MAX_PATH),
_MAX_PATH,
path
);
::GetCurrentDirectory(_MAX_PATH,path.GetBuffer(_MAX_PATH));
path.ReleaseBuffer();
path += " /config.ini " ;
DWORD len = GetPrivateProfileString(
" DZH " ,
" AppName " ,
"默认字符串内容 " ,
m_appName.GetBuffer(_MAX_PATH),
_MAX_PATH,
path
);