我在硬盘下的配置文件如下:
[PreviewBlock]
bPreviewBlock=0
[BFrameNum]
dwBFrameNum=0
[DownLoadPath]
chDownLoadPath=c:\DownLoad
[PictureSavePath]
chPictureSavePath=c:\Picture
[ClientRecordPath]
chClientRecordPath=c:\;我读的时候是这样写的
CString buf="";
GetPrivateProfileString("PreviewBlock","bPreviewBlock","",buf.GetBuffer(100),100,csFilename);GetPrivateProfileString("BFrameNum","dwBFrameNum","",buf.GetBuffer(100),100,csFilename);
g_struLocalParam.dwBFrameNum = atoi(buf);GetPrivateProfileString("DownLoadPath","chDownLoadPath","",buf.GetBuffer(100),100,csFilename);
strncpy(g_struLocalParam.chDownLoadPath,(LPCTSTR)buf,sizeof(g_struLocalParam.chDownLoadPath)); GetPrivateProfileString("PictureSavePath","chPictureSavePath","",buf.GetBuffer(100),100,csFilename);
strncpy(g_struLocalParam.chPictureSavePath,(LPCTSTR)buf,sizeof(g_struLocalParam.chPictureSavePath));GetPrivateProfileString("ClientRecordPath","chClientRecordPath","",buf.GetBuffer(100),100,csFilename);
strncpy(g_struLocalParam.chClientRecordPath,(LPCTSTR)buf,sizeof(g_struLocalParam.chClientRecordPath));调试时发现buf根本就没有取到值,还是空的
[PreviewBlock]
bPreviewBlock=0
[BFrameNum]
dwBFrameNum=0
[DownLoadPath]
chDownLoadPath=c:\DownLoad
[PictureSavePath]
chPictureSavePath=c:\Picture
[ClientRecordPath]
chClientRecordPath=c:\;我读的时候是这样写的
CString buf="";
GetPrivateProfileString("PreviewBlock","bPreviewBlock","",buf.GetBuffer(100),100,csFilename);GetPrivateProfileString("BFrameNum","dwBFrameNum","",buf.GetBuffer(100),100,csFilename);
g_struLocalParam.dwBFrameNum = atoi(buf);GetPrivateProfileString("DownLoadPath","chDownLoadPath","",buf.GetBuffer(100),100,csFilename);
strncpy(g_struLocalParam.chDownLoadPath,(LPCTSTR)buf,sizeof(g_struLocalParam.chDownLoadPath)); GetPrivateProfileString("PictureSavePath","chPictureSavePath","",buf.GetBuffer(100),100,csFilename);
strncpy(g_struLocalParam.chPictureSavePath,(LPCTSTR)buf,sizeof(g_struLocalParam.chPictureSavePath));GetPrivateProfileString("ClientRecordPath","chClientRecordPath","",buf.GetBuffer(100),100,csFilename);
strncpy(g_struLocalParam.chClientRecordPath,(LPCTSTR)buf,sizeof(g_struLocalParam.chClientRecordPath));调试时发现buf根本就没有取到值,还是空的
解决方案 »
- 新建窗口最小化显示
- 问SQL SERVER出现的若干问题,在此请教各位
- 如何得到u盘的vid和pid?
- ==== 请教 : 如何制作自动升级/更新 程序 ====
- 如何导出带有基类的标准C++类?
- 路径设置!求助!
- 用VB写的activex dll/exe/ocx/文档,是不是COM组件!!!100分有请。
- 各位高手帮忙:怎样从对话框接收一个函数?(对不起,前一个帖子没写清楚)急用,谢谢了!
- 在Windows2000下,调试Microsoft Visual C++ 6.0程序?
- *.scm是什么文件用什么打开?据说是用demostation,但demostation是什么?哪儿有?
- listctrl怎么初始化?
- 有关显示缩略图 Thumbnail
CString buf="";
GetPrivateProfileString("PreviewBlock","bPreviewBlock","",buf.GetBufferSetLength(100),100,csFilename); 之后别忘了buf.Release();
GetPrivateProfileInt 读比较好
后面的里面还是传 char szBuf[100]比较好些,我一般这样用的,没出过问题
还有就是注意你的 csFilename 是否对了
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int main()
{
TCHAR inBuf[80];
HKEY hKey1, hKey2;
DWORD dwDisposition;
LONG lRetCode;
TCHAR szData[] = TEXT("USR:App Name\\Section1");
// Create the .ini file key.
lRetCode = RegCreateKeyEx ( HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\"
"IniFileMapping\\appname.ini"),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey1,
&dwDisposition);
if (lRetCode != ERROR_SUCCESS)
{
printf ("Error in creating appname.ini key (%d).\n", lRetCode);
return (0) ;
}
// Set a section value
lRetCode = RegSetValueEx ( hKey1,
TEXT("Section1"),
0,
REG_SZ,
(BYTE *)szData,
sizeof(szData));
if (lRetCode != ERROR_SUCCESS)
{
printf ("Error in setting Section1 value\n");
// Close the key
lRetCode = RegCloseKey( hKey1 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\n", lRetCode);
return (0) ;
}
}
// Create an App Name key
lRetCode = RegCreateKeyEx ( HKEY_CURRENT_USER,
TEXT("App Name"),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey2,
&dwDisposition);
if (lRetCode != ERROR_SUCCESS)
{
printf ("Error in creating App Name key (%d).\n", lRetCode); // Close the key
lRetCode = RegCloseKey( hKey2 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\n", lRetCode);
return (0) ;
}
}
// Force the system to read the mapping into shared memory
// so that future invocations of the application will see it
// without the user having to reboot the system
WritePrivateProfileStringW( NULL, NULL, NULL, L"appname.ini" );
// Write some added values
WritePrivateProfileString (TEXT("Section1"),
TEXT("FirstKey"),
TEXT("It all worked out OK."),
TEXT("appname.ini"));
WritePrivateProfileString (TEXT("Section1"),
TEXT("SecondKey"),
TEXT("By golly, it works!"),
TEXT("appname.ini"));
WritePrivateProfileString (TEXT("Section1"),
TEXT("ThirdKey"),
TEXT("Another test..."),
TEXT("appname.ini")); // Test
GetPrivateProfileString (TEXT("Section1"),
TEXT("FirstKey"),
TEXT("Error: GPPS failed"),
inBuf,
80,
TEXT("appname.ini"));
_tprintf (TEXT("Key: %s\n"), inBuf);
// Close the keys
lRetCode = RegCloseKey( hKey1 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\n", lRetCode);
return(0);
} lRetCode = RegCloseKey( hKey2 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\n", lRetCode);
return(0);
}
return(1);
}