---
title: "CString 诡异的 GetLength() 返回 0"
author: "msnvip"
date: "2009-01-21T17:55:35Z"
tags: []
slug: "cstring-getlength-0"
draft: false
lastmod: "2009-01-21T17:55:35Z"
id: 319789
url: "https://msnvip.iteye.com/blog/319789"
---

如果CString是从GetPrivateProfileStr()返回的
记得return 该CString 前 释放buffer
要不,CString.GetLength()将返回0
找了半天原因,
----------------------------------------------------
 “If   you   use   the   pointer   returned   by   GetBuffer   to   change   the   string   contents,   you   must   call   ReleaseBuffer   before   using   any   other   CString   member   functions.   ”   
    
  在i=m_SZFileName.GetLength()之前调用m_SZFileName.ReleaseBuffer()就可以了。