|
I have a very strange problem.
I have an MFC application that open a modal CDialog and using opengl to render to it using timer
I initialize opengl and timer in OnInitDialog();
it look something like this
<br />
void initComponent(){<br />
<br />
int desktopWidth = GetSystemMetrics(0);<br />
int desktopHeight = GetSystemMetrics(1);<br />
SetWindowPos(NULL,0,0,desktopWidth,desktopHeight,SWP_NOZORDER);<br />
<br />
initOpenGL();<br />
<br />
SetTimer(1,15,NULL);<br />
<br />
} <br />
My application have no problem so far on NVIDIA and ATI hardware.
but on intel(integrated chipset) , it wont show the dialog unless I pressed "Alt" key(and then the program work fine).
I tried calling SetFocus , set property to foreground windows , move
initialize opengl into OnCreate but it still the same on intel hardware.
My Dialog is
1.a popup modal dialog.
2.has no border.
3.initialize OpenGL and Timer in OnInitDialog.
4.draw image in timer.
5.work fine on NVIDIA and ATI hardware (test on 8 PC)
6.Had to press "Alt" key for dialog to show up on intel hardware.(test on 3 pc)
Thank in advance.
|
|
|
|
|
Why VC6 set default struct member alignment's value is 8? I think 4 is better. Because now windows is 32bit.
|
|
|
|
|
All Microsoft Compilers have set default alignment to 8 for as long as anyone can remember. Changing it now could break oodles of older source code beside it has nothing much to do with 32bit Windows 8 bytes is 8 bytes it used to be 4 words now it's 2 and in the 64bit world only 1. Just our luck that 8 byte alignment works nicely for all 3 then isn't it.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Use #pragma pack and set it to whatever suites you best.
All my Header files start with #pragma pack(1).
I allign my data for Data Files Manually on an 1,2, 4 or 8 byte boundary (as suites me) and hey presto, where's the problem. Take care though, NOT to use ints and longs, use BYTE,WORD,DWORD and QWORD for structures saved on file. This combined with a byte packing boundary, will future proof your data against any compiler allignment changes.
For structures not saved on file, and not exchanged between processes, allignment issues are immaterial, as long as they are agreed between the processes. The Microsoft Default of 8 bytes probably gives the fastest raw acces. The question is: Is it worth the bother. The important reflection is that: At least it is something we can quite easily choose ourselves to suit our purposes.
Regards,
Bram van Kampen
|
|
|
|
|
Hi All,
I am having an application where a structure will be directly written into HDD in binary format at a particular time interval.
But if PC gets turned off due to some abnormal problems, during file write, after the next restart the entire file has only 0's. it is getting corrupted.
How can i avoid this problem (apart from taking backup and restore in case of corruption).
Any help would be appreciated.
Thanks.
Selva
|
|
|
|
|
If the file is very big one way could be dividing the data to be written in small packets, opening file, saving a packet, closing file and repeating.
It will be slower, but closing the file sometimes during the process should make to save the already sent content, you will lose only the packet you are sending in the moment the computer crashes.
BTW It is just a guess, never tried it.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
An alternative to Nelek's suggestion of Open, Write, Close is to call a Flush after every write.
There always is a window of opportunity for disk files to get trashed. Even using the suggestions you've received, there is a chance that the machine will power down before the disk cache is written to disk. The only way to make that window smaller is to use something like the commit function, which is a pretty low level C function. It instructs the OS to issue the actual write commands to the disk. The one case you can't guard against is someone powering off a machine while the actual physical write is in progress, but from what little you said, it sounds flush should give you what you need.
Judy
|
|
|
|
|
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,
Bram van Kampen
|
|
|
|
|
Hello all,
I have a code which is compiling in multibyte character set but giving some errors in unicode character set like:
1) error C2664: 'CStdioFile::Open' : cannot convert parameter 1 from 'char[260]' to 'LPCTSTR'.
2) error C2664: 'GetTempPathW' : cannot convert parameter 2 from 'char [260]' to 'LPWSTR'
3) error C2664: 'CStdioFile::Open' : cannot convert parameter 1 from 'char [260]' to 'LPCTSTR'
4) error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'
can anybody please help me in this....
Thanks in advance
|
|
|
|
|
I think ther first three ones can be resolved by type-converting.
(4) should use _T("") macro or L prefix.
|
|
|
|
|
You can either change array declarations (i.e. TCHAR instead of char ) and then assign them consistently or apply string conversions http://msdn2.microsoft.com/en-us/library/87zae4a3(VS.71).aspx[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Without seeing the code that is causing these errors, it's difficult to say exactly the best way to solve them.
For the CStdioFile.Open, if you are using something like
myFile.Open("test.txt", CFile::modeCreate); you could just change it to
myFile.Open(_T("test.txt"), CFile::modeCreate);
The same may be try for the ATL::CStringT problem. The following code could cause the error:
CString myString("Test"); Again, this can be fixed by using
CString myString(_T("Test"));
The advantage is that this will work with either MBCS or Unitcode builds.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
My OS is Windows XP professional. I set my location to US and Language to English.
So,when I want to print some no English words like Chinese,Japanese,I would failed. For example
wchar_t *s = L"??";//?? are some non-English words,it did not display rightly
int err = wprintf(s);//operation failed,err = -1,
wcout<<s<<endl;//no output on the screen
I want to know why the printing operation would be failed.
Someone would advise me to set my system's default location and language,but,if a system with US location and open a file with such non-English file,how should it to display the content?
Thanks.
modified on Friday, December 07, 2007 2:27:13 AM
|
|
|
|
|
The problem is that a computer with the language you are talking about, created the file with it's own charsets and fonts. Codes for these characters has a glyph in that font but they don't in your current font or they even don't exist in your current character set. Some info about these terms[^]
So here you have two options:
1. The hard and right way: define your application to use Unicode. You shall take care of all strings and all functions that use strings since each character will take (at least) two bytes instead of usual one byte. You also should take care of all functions that ask you to enter Size or Length of the string which will be different. I'm still not 100% sure this helps when printing, but as softwares like MS Office Word can do the job, they'll do it this way probably.
2. The easy way(might not help for printing): Install the language in your computer and ask windows to select it as your default language for NON-UNICODE applications: Go to control panel->Regional and language options, select Advanced tab and check if you can find the language you want in the combo box under 'Language for non Unicode programs' if not go to Language tab where you should select if it's an East Asian or if it has complex scripts, then apply and return back to Advanced. Find the language and select it. Apply changes and your application should not show those characters any longer, but I doubt it fixes print problem. Also note that in VC6 You have to right click on dialogs in your resource view and choose [Neutral] instead of default English language if you want to show characters truely on screen.
// "In the end it's a little boy expressing himself." Yanni
while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
Yes,I agree with you.
In fact,my problem is that,when I reading the ID3v1 text tags from a .mp3 file.There is no enough information about characterset of the text string coding.So,if a text string is non-English encoded,the reading and displaying would failed.A text string in ID3v1 is a 30 characters(also is 30 bytes) long array.I read it one by one,and call MultiByteToWideChar function to convert the string into Unicode string,but the converted Unicode string is incorrect.
Thanks
|
|
|
|
|
Please do some tests to find out how you need to act:
Use debug window to see the memory address of the variable that you use to store the id3 tag. Also try changing debug option that says 'Use Unicode string'. It's likely that debug window shows true characters and that shows you to use Unicode.
Make sure your dialogs where you display the text on them have neutral language set. Try displaying data in GDI controls like Static or TextBox instead of directly drawing them on the DC.
Try softwares that display these data, like WinAmp or JetAudio, if you have access to them and check to see if they can display the tag truely.
If you noticed any difference, you can find a true solution to the problem, or at least you'll have a clue to start from.
// "In the end it's a little boy expressing himself." Yanni
while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
Hello,everyone
I'm using vc6.0, using ms datagrid control 6.0
I want to change the color of the current row in datagrid.
Changing the current row's font or other things to make the row selected noticeable is also OK!!
Thanks!!
modified on Monday, December 10, 2007 7:39:03 PM
|
|
|
|
|
hi all
Currently i am creating a window mobile program using visual c++. wanted to find out what is the code to redirect my current dialog to another new dialog in 2 seconds.
Thanks for your help. Appreciate your help guys.
|
|
|
|
|
what about putting timer in your application, which open new dialog after 2 seconds!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Hi all,
I'm working with a map to store a string, int pair. I want to make my code more clear. So I'm try to define my map in a common place and use to store data on it. So where should I declare the map.
I've try to define in the class definition file(class header file), but in the data insertion statement I got the following error.
<br />
error C2678: binary '[' : no operator found which takes a left-hand operand of type 'const std::map<_Kty,_Ty>' (or there is no acceptable conversion)<br />
I've declared the map as follows,
map<string, int=""> data_map;</string,>
How can I solved this.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Firstly map not declared as
map data_map;
if you have to store an int & a string inside the map then declaration will be like this: -
map< int,std::string > data_map;
In this the integer filed will be your primary field and corresspoding to which you get the data.
Regards,
Pankaj Sachdeva
There is no future lies in any job but future lies in the person who holds the job
|
|
|
|
|
Oops,
Really sorry about that. Miss the middle part of the code, may be because of the code tags.
Its like this,
map<string, int=""> data_map
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: Really sorry about that. Miss the middle part of the code, may be because of the code tags.
Oops you did it again!
Use the pre-Tag to enclose the code or use the < > tags instead of the one on your keyboard.
You'll find them below the text editor when writing the message!
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Karismatic wrote: Firstly map not declared as
map data_map;
His map is declared as:
map<string, int=""> data_map;
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi Experts,
I want to create a project that has two view :
First view displays the tree view of all files and folders and
Second view displays the corresponding file click on the folder of first view.
My mean to say like a Windows Explorer view.
How can I achieve it.
Thanx in advance.
|
|
|
|
|