Click here to Skip to main content
16,010,544 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionVC++ deletes files?? Pin
20-Feb-02 13:42
suss20-Feb-02 13:42 
AnswerRe: VC++ deletes files?? Pin
Andres Manggini20-Feb-02 16:01
Andres Manggini20-Feb-02 16:01 
GeneralNon-Visual CRichEditCtrl For Printing Mechanism Pin
perlmunger20-Feb-02 13:03
perlmunger20-Feb-02 13:03 
GeneralRe: Non-Visual CRichEditCtrl For Printing Mechanism Pin
Tim Smith20-Feb-02 13:28
Tim Smith20-Feb-02 13:28 
GeneralRe: Non-Visual CRichEditCtrl For Printing Mechanism Pin
perlmunger20-Feb-02 13:45
perlmunger20-Feb-02 13:45 
GeneralRe: Non-Visual CRichEditCtrl For Printing Mechanism Pin
Tim Smith20-Feb-02 13:58
Tim Smith20-Feb-02 13:58 
GeneralRe: Non-Visual CRichEditCtrl For Printing Mechanism Pin
perlmunger21-Feb-02 5:43
perlmunger21-Feb-02 5:43 
GeneralCString and memory mapped files Pin
20-Feb-02 12:59
suss20-Feb-02 12:59 
I am attempting to use memory mapped files to access rather large files for manipulation purposes.

Mapping a view of the file returns an LPVOID pointer that I (LPTSTR) cast
to a CString for easier string manipulation. I am able to work with the contents quickly as expected. I am not, however, able to successfully save the newly modified contents back to the file. Unmapping returns successfully, but the file contents are never updated. Printing the contents of the CString var shows that the changes have been made.

I was told that, due to reference counting in the CString class, I would be unable to use the returned pointer in this fashion. So I tried to create the LPVOID, copy the pointer to the CString var, make changes, then copy the pointer back to the original LPVOID. The contents of the LPVOID var changes, but once again the file does not.

Currently I am using PJ Naughter's MemMappedFile class, which is a wrapper for the MMF API. Here is the code I am using:

<tt><font color=#990000><br>LPVOID pMsgPtr;<br>CString strMsgPtr;<br><font color=#009900>//First I am loading the pointer into an LPVOID var:<br></font>pMsgPtr = MemMappedMsgFile.Open<font color=#220000>(</font><font color=#220000>)</font>;<br><br><font color=#009900>//Then I am giving the pointer to a CString var for easier string manipulation:<br></font>strMsgPtr = <font color=#220000>(</font>LPTSTR<font color=#220000>)</font>pMsgPtr;<br><br><font color=#009900>//Then I make changes to the file as needed.<br></font>strMsgPtr.MakeUpper<font color=#220000>(</font><font color=#220000>)</font>;<br><br><font color=#009900>//Then if I either try to Unmap the file, the changed contents<br></font><font color=#009900>//are not saved.<br></font><font color=#009900>//Even if I copy the CString back to the LPVOID and unmap, it still doesn't<br></font><font color=#009900>//work:<br></font>pMsgPtr = strMsgPtr.GetBuffer<font color=#220000>(</font>dwMsgLen<font color=#220000>)</font>;<br>strMsgPtr.ReleaseBuffer<font color=#220000>(</font>dwMsgLen<font color=#220000>)</font>;<br><br><font color=#009900>//But, if I modify the LPVOID directly before passing the pointer, the<br></font><font color=#009900>//changes are saved.<br></font><br></font></tt>



Is there any way that I can use the CString manipulation functions while maintaining the pointer?


Thanks,
Chris


GeneralRe: CString and memory mapped files Pin
Tim Smith20-Feb-02 13:27
Tim Smith20-Feb-02 13:27 
GeneralExcel like Tab control Pin
20-Feb-02 12:50
suss20-Feb-02 12:50 
GeneralRe: Excel like Tab control Pin
Mazdak20-Feb-02 19:08
Mazdak20-Feb-02 19:08 
GeneralRe: Excel like Tab control Pin
Steen Krogsgaard20-Feb-02 21:38
Steen Krogsgaard20-Feb-02 21:38 
GeneralRe: Excel like Tab control Pin
567890123421-Feb-02 0:58
567890123421-Feb-02 0:58 
GeneralHelp with Documents and Views Pin
Aaron Schaefer20-Feb-02 12:36
Aaron Schaefer20-Feb-02 12:36 
GeneralRe: Help with Documents and Views Pin
Mazdak20-Feb-02 19:08
Mazdak20-Feb-02 19:08 
GeneralRe: Help with Documents and Views Pin
Steen Krogsgaard20-Feb-02 21:48
Steen Krogsgaard20-Feb-02 21:48 
GeneralError with compiled app (localization) Pin
blink4me20-Feb-02 12:11
blink4me20-Feb-02 12:11 
GeneralMemory leak Pin
Stew20-Feb-02 11:20
Stew20-Feb-02 11:20 
GeneralRe: Memory leak Pin
Christian Graus20-Feb-02 11:31
protectorChristian Graus20-Feb-02 11:31 
GeneralRe: Memory leak Pin
CodeGuy20-Feb-02 11:41
CodeGuy20-Feb-02 11:41 
GeneralRe: Memory leak Pin
Stew20-Feb-02 14:04
Stew20-Feb-02 14:04 
GeneralRe: Memory leak Pin
CodeGuy21-Feb-02 1:56
CodeGuy21-Feb-02 1:56 
GeneralMember variables which are Pointers to User Defined Classes - Prob with CPropertySheet Pin
dazinith20-Feb-02 11:16
dazinith20-Feb-02 11:16 
GeneralRe: Member variables which are Pointers to User Defined Classes - Prob with CPropertySheet Pin
dazinith20-Feb-02 11:18
dazinith20-Feb-02 11:18 
GeneralSplitter Windows Pin
Anthony988720-Feb-02 8:59
Anthony988720-Feb-02 8:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.