Click here to Skip to main content
15,112,453 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to custmize the ribbon category at run time using MFC Pin
Ashish Ranjan Mishra4-Apr-16 7:36
MemberAshish Ranjan Mishra4-Apr-16 7:36 
SuggestionRe: How to custmize the ribbon category at run time using MFC Pin
David Crow5-Apr-16 16:50
MemberDavid Crow5-Apr-16 16:50 
Questioninput to be parsed to produce a node tree Pin
Member 124358024-Apr-16 6:45
MemberMember 124358024-Apr-16 6:45 
SuggestionRe: input to be parsed to produce a node tree Pin
Richard MacCutchan4-Apr-16 8:03
mveRichard MacCutchan4-Apr-16 8:03 
QuestionC, Win32 API: l need a help with file/data storage Pin
Member 121394424-Apr-16 5:32
MemberMember 121394424-Apr-16 5:32 
AnswerRe: C, Win32 API: l need a help with file/data storage Pin
jeron14-Apr-16 5:49
Memberjeron14-Apr-16 5:49 
QuestionRe: C, Win32 API: l need a help with file/data storage Pin
David Crow4-Apr-16 6:22
MemberDavid Crow4-Apr-16 6:22 
AnswerRe: C, Win32 API: l need a help with file/data storage Pin
Jochen Arndt4-Apr-16 6:25
professionalJochen Arndt4-Apr-16 6:25 
Open the file with OPEN_ALWAYS and check the error code to know if it has been created or an existing file has been opened:
C++
// Clear error
SetLastError(0);
HANDLE hFile = CreateFile(fileName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
    if (GetLastError() == ERROR_ALREADY_EXISTS)
    {
        // Read file here
    }
    else
    {
        // Ask for key and write file here
    }
    CloseHandle(hFile);
}

Alternatively check if the file exists and open it for reading or writing afterwards. This can be optimised by trying to open the file for reading and if that fails to open it for writing:
HANDLE hFile = CreateFile(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
    // Read file here
}
else
{
    hFile = CreateFile(fileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile != INVALID_HANDLE_VALUE)
    {
        // Ask for key and write file here
    }
}
if (hFile != INVALID_HANDLE_VALUE)
    CloseHandle(hFile);

QuestionAn example of _tcslwr with BYTE type Pin
Member 123535314-Apr-16 1:18
MemberMember 123535314-Apr-16 1:18 
AnswerRe: An example of _tcslwr with BYTE type Pin
Jochen Arndt4-Apr-16 2:08
professionalJochen Arndt4-Apr-16 2:08 
Questionhow to access member functions and variables in another project without .lib Pin
kamal19773-Apr-16 8:53
Memberkamal19773-Apr-16 8:53 
AnswerRe: how to access member functions and variables in another project without .lib Pin
Daniel Pfeffer3-Apr-16 21:16
professionalDaniel Pfeffer3-Apr-16 21:16 
GeneralRe: how to access member functions and variables in another project without .lib Pin
kamal19774-Apr-16 13:10
Memberkamal19774-Apr-16 13:10 
AnswerRe: how to access member functions and variables in another project without .lib Pin
Richard MacCutchan3-Apr-16 22:43
mveRichard MacCutchan3-Apr-16 22:43 
GeneralRe: how to access member functions and variables in another project without .lib Pin
kamal19774-Apr-16 13:07
Memberkamal19774-Apr-16 13:07 
GeneralRe: how to access member functions and variables in another project without .lib Pin
Richard MacCutchan4-Apr-16 22:45
mveRichard MacCutchan4-Apr-16 22:45 
GeneralRe: how to access member functions and variables in another project without .lib Pin
leon de boer5-Apr-16 3:40
Memberleon de boer5-Apr-16 3:40 
AnswerRe: how to access member functions and variables in another project without .lib Pin
leon de boer5-Apr-16 3:50
Memberleon de boer5-Apr-16 3:50 
QuestionC++ file stream read/write[SOLVED] Pin
Biruk Abebe3-Apr-16 7:22
MemberBiruk Abebe3-Apr-16 7:22 
AnswerRe: C++ file stream read/write Pin
leon de boer3-Apr-16 8:12
Memberleon de boer3-Apr-16 8:12 
GeneralRe: C++ file stream read/write Pin
Biruk Abebe3-Apr-16 8:40
MemberBiruk Abebe3-Apr-16 8:40 
GeneralRe: C++ file stream read/write Pin
leon de boer3-Apr-16 10:22
Memberleon de boer3-Apr-16 10:22 
GeneralRe: C++ file stream read/write[SOLVED] Pin
Biruk Abebe3-Apr-16 11:26
MemberBiruk Abebe3-Apr-16 11:26 
QuestionC, Win32 API: l need help with ReadFile function[Solved] Pin
Member 121394421-Apr-16 1:46
MemberMember 121394421-Apr-16 1:46 
AnswerRe: C, Win32 API: l need help with ReadFile function Pin
Jochen Arndt1-Apr-16 2:30
professionalJochen Arndt1-Apr-16 2:30 

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.