Click here to Skip to main content
15,914,452 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMFC Modal OpenGL dialog wont show up unless I pressed "Alt" key (on intel hardware) Pin
xanagan6666-Dec-07 22:37
xanagan6666-Dec-07 22:37 
Questionstruct member alignment? Pin
Laurence6-Dec-07 20:36
Laurence6-Dec-07 20:36 
AnswerRe: struct member alignment? Pin
Matthew Faithfull7-Dec-07 2:23
Matthew Faithfull7-Dec-07 2:23 
AnswerRe: struct member alignment? Pin
Bram van Kampen7-Dec-07 13:12
Bram van Kampen7-Dec-07 13:12 
GeneralData corruption during File Write Pin
SelvaKr6-Dec-07 20:35
SelvaKr6-Dec-07 20:35 
GeneralRe: Data corruption during File Write Pin
Nelek6-Dec-07 21:32
protectorNelek6-Dec-07 21:32 
GeneralRe: Data corruption during File Write Pin
JudyL_MD7-Dec-07 2:02
JudyL_MD7-Dec-07 2:02 
GeneralRe: Data corruption during File Write Pin
Bram van Kampen7-Dec-07 12:46
Bram van Kampen7-Dec-07 12:46 
SelvaKr wrote:
after the next restart the entire file has only 0's. it is getting corrupted.


I sense that you are after a way of writing mission critical data in an guaranteed safe way, so that integrity is maintained, even during a powerfailure halfway tru the write. I have done quite a bit of research on this,and came to the following design conclusions.-

1. It is Not possible to guarantee a successfull write under above circumstances

2. It is possible as Second Best, to maintain a consistent state. This means that under such circumstances, the transaction is either completed in full, or you are returned to the state prevailing before the transaction commenced. This is not a guaranteed write, but, atleast, you have not the corruption of a partially completed transaction.

My system requires two identical file sets, marked Primary and Alternate.
There is also a single third file, the State file, which holds only One Byte. This Byte assumes one of the following Values:-
STATE_NORMAL, STATE_MOD_PRIMARY, STATE_MOD_ALTERNATE.

When we start, Both Primary ad Alternate Sets are Identical.

Step 1:
The Write Operation commences by opening the State File, and Writing STATE_MOD_PRIMARY to it, after which it is closed. This indicates that the Primary Set is now entering into a potentially unstable State, but the Alternate holds a consistent backup.

Step 2:
Carry Out All your Writes to the Primary Set. When the Write is Completed, Close All Files.

Step 3:
Open the State File, and Write STATE_MOD_ALTERNATE to it, after which it is closed. This indicates that the Alternate Set is now entering into a potentially unstable State, but the Primary Set holds the New Dataset.

Step 4:
Delete All Alternate Files, and replace them with copies of the Primary Set.

Step 5:
Open the State File, and Write STATE_MOD_NORMAL to it, after which it is closed. This indicates that the Data Set is Once again in a Stable state.

When your Excecutable starts, it must investigate the FileTime's of the State File, the Primary Set, and the Alternate Set. A Prima Facia Consistent state is indicated by FileTime(Primary)<filetime(alternate)><filetime(state) but:="" see="" below,="" this="" relation="" state="" may="" not="" hold="" if="" you="" breakdown="" again="" during="" recovery.<br="" mode="hold">
Another Consistency test is that the State File contains STATE_MOD_NORMAL

If any of this fails, you can figure out from the above description, where things went wrong, and what todo. The two Possibilities here are RollBack: Copy the Alternate to the Primary, or, Complete: Copy the Primary to the Alternate.

I have developped a custom API to implement the above.
It works with:

HFILESET OpenFileSetForWrite(DWORD Flags,int NrOfFiles, LPCSTR[] FileNames);

ERRCODE WriteFileSetFile(LPCSTR Buf,int size,int count,HFILESET hfs,int FileIndex,int* WrSize);

ERRCODE CloseFileSet(HFILESET hfs);

Another aspect is that I included a 64 byte code in the State File to help the App recover to where things went wrong. If at all posible the user is brought to the starting screen of the aborted transaction.

Note.: Powerfailures and Hardware failures(broken tracks in boards etc) are notoriously hard to simulate. It is essentially 'Out of Spec Behaviour. What attracted me to your question was that you suggest to have a hardware way of testing your code. Could you suggest to me how to test this. I used a method involving a USB Device which was fired via a (semi)random timer, triggered by the WriteFileSet() funtion, to cut the Power to the PC. What did you use to test your software.

Regards, Smile | :)

Bram van Kampen

Generalerrors in converting code from multibyte to unicode Pin
neha.agarwal276-Dec-07 20:13
neha.agarwal276-Dec-07 20:13 
GeneralRe: errors in converting code from multibyte to unicode Pin
kcynic6-Dec-07 20:42
kcynic6-Dec-07 20:42 
GeneralRe: errors in converting code from multibyte to unicode Pin
CPallini6-Dec-07 23:47
mveCPallini6-Dec-07 23:47 
GeneralRe: errors in converting code from multibyte to unicode Pin
krmed7-Dec-07 1:59
krmed7-Dec-07 1:59 
GeneralHelp about characterset [modified] Pin
kcynic6-Dec-07 20:11
kcynic6-Dec-07 20:11 
GeneralRe: Help about characterset Pin
Hamed Musavi7-Dec-07 3:25
Hamed Musavi7-Dec-07 3:25 
GeneralRe: Help about characterset Pin
kcynic7-Dec-07 14:14
kcynic7-Dec-07 14:14 
GeneralRe: Help about characterset Pin
Hamed Musavi7-Dec-07 19:24
Hamed Musavi7-Dec-07 19:24 
QuestionHelp! How to change the color of the current row in datagrid [modified] Pin
shakaqrj6-Dec-07 19:49
shakaqrj6-Dec-07 19:49 
GeneralHelp in visual C++ Pin
cinzhan6-Dec-07 19:39
cinzhan6-Dec-07 19:39 
GeneralRe: Help in visual C++ Pin
ThatsAlok6-Dec-07 20:11
ThatsAlok6-Dec-07 20:11 
Generaldata map declartion. Pin
CodingLover6-Dec-07 18:53
CodingLover6-Dec-07 18:53 
GeneralRe: data map declartion. Pin
Karismatic6-Dec-07 19:34
Karismatic6-Dec-07 19:34 
GeneralRe: data map declartion. Pin
CodingLover6-Dec-07 20:04
CodingLover6-Dec-07 20:04 
GeneralRe: data map declartion. Pin
jhwurmbach6-Dec-07 21:40
jhwurmbach6-Dec-07 21:40 
GeneralRe: data map declartion. Pin
David Crow7-Dec-07 2:57
David Crow7-Dec-07 2:57 
GeneralExplorer view Pin
john56326-Dec-07 18:27
john56326-Dec-07 18:27 

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.