GetPrivateProfileSectionNames

GetPrivateProfileSectionNames

The GetPrivateProfileSectionNames function retrieves the names of all sections in an initialization file. This function is provided for compatibility with 16-bit Windows-based applications. Win32-based applications should store initialization information in the registry.

获取ini文件的section。

DWORD GetPrivateProfileSectionNames(
  LPTSTR lpszReturnBuffer,  // address of return buffer
  DWORD nSize,              // size of return buffer
  LPCTSTR lpFileName        // address of initialization filename
);
 
Parameters
lpszReturnBuffer
Pointer to a buffer that receives the section names associated with the named file. The buffer is filled with one or more null-terminated strings; the last string is followed by a second null character.指向一个缓冲,用来保存返回的所有section。
nSize
Specifies the size, in characters, of the buffer pointed to by the lpszReturnBuffer parameter. lpszReturnBuffer的大小。
lpFileName
Pointer to a null-terminated string that names the initialization file. If this parameter is NULL, the function searches the WIN.INI file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.读取的ini文件名。
Return Values

The return value specifies the number of characters copied to the specified buffer, not including the terminating null character. If the buffer is not large enough to contain all the section names associated with the specified initialization file, the return value is equal to the length specified by nSize minus two.装载到lpszReturnBuffer缓冲区的字符数量。

Remarks

This operation is atomic; no updates to the initialization file are allowed while the section names are being copied to the buffer.

Calls to profile functions might be mapped to the registry instead of to the initialization files. When the operation has been mapped, the GetPrivateProfileSectionNames function retrieves information from the registry, not from the initialization file; the change in the storage location has no effect on the function's behavior. 

e.g:

#include "stdafx.h"
#include "GetPrivateProfileSectionName.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
		CString csFileName = "E:\\VC++\\GetPrivateProfileSection\\sention.ini";
		char strRetunrStringBuf[1024];
		char strVaule[256];
		int iReturnSize = 0;
		int iCountTotal = 0;
		int iCountPrivate = 0;
		int iBufSize = 1 * 1024;
		
		memset(strRetunrStringBuf, 0, sizeof(strRetunrStringBuf));	
		iReturnSize = GetPrivateProfileSectionNames(strRetunrStringBuf,
            iBufSize,
			csFileName);
		
		while(iCountTotal < iReturnSize)
		{
			memset(strVaule, 0, sizeof(strVaule)); 
			memcpy(strVaule, &strRetunrStringBuf[iCountTotal],strlen(&strRetunrStringBuf[iCountTotal]));
			iCountPrivate = strlen(&strRetunrStringBuf[iCountTotal]) + 1;
			iCountTotal += iCountPrivate;
			printf("%s\n", strVaule);
		}
	}

	return nRetCode;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值