|
To me, the code is "cleaner" without the braces, but I understand it's just a style thing.
J
"I am the Lorax. I speak for the trees."
|
|
|
|
|
"just a style thing"?
Read a good book on defensive programming - "Code Complete" comes to mind. Your "style" is prone to errors.
|
|
|
|
|
John M. Drescher wrote:
I always insert the braces
I'll to that!
I prefer to wear gloves when using it, but that's merely a matter of personal hygiene
[Roger Wright on VB]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
[Rich Cook]
|
|
|
|
|
I sounds like you are single steping through the code with the debugger.
1. for(int i = 0; i < 20; ++i)
2. if(!m_aSoftwareGains[i].Load(pFile))
3. return false;
4. m_bSoftwareGainsLoaded = true;
<pre\>
When single stepping it will appear to go 1,2,4,1,2,4,...,1,2,3.
<pre>
1. for(int i = 0; i < 20; ++i)
2. {
3. if(!m_aSoftwareGains[i].Load(pFile))
4. return false;
5. }
6. m_bSoftwareGainsLoaded = true;
<pre\>
Now It should appear to be 1,3,5,1,3,5,...,1,3,4.
INTP
|
|
|
|
|
Yes, I discovered this after digging through the assembly. Oops.
J
"I am the Lorax. I speak for the trees."
|
|
|
|
|
Are you sure you don't have a ";" at the end of line one?
I've tried to reproduce the difference in behaviour, but with no success. When you look at the disassembly, it seems to be identical with or without braces.
Haakon.
'Problems worthy
of attack
prove their worth
by hitting back.'
Piet Hein
|
|
|
|
|
It was a user problem. I assumed the problem was there, and that biased my testing.
I stepped through, and when the code returns from the call (line 2), the little yellow arrowhead points to line 4. THAT DOESN'T MEAN THAT IT IS THE NEXT INSTRUCTION TO RUN! I must have seen that in my testing, wondered what the hell was going on, and stopped the debug.
I too traced through the assembly, but made the same mistake - didn't trace through far enough.
Oh well.
J
"I am the Lorax. I speak for the trees."
|
|
|
|
|
No problem.
If we didn't learn anything, you certainly have.
H.
'Problems worthy
of attack
prove their worth
by hitting back.'
Piet Hein
|
|
|
|
|
code:
#define _CRTDBG_MAP_ALLOC
#include<cstdlib>
#include<crtdbg.h>
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrefInst, LPSTR cmdLine, int cmdShow)
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
int* i = new int;
i = NULL;
_CrtDumpMemoryLeaks();
return 0;
}
debug output:
==========================================================
'Game.exe': Loaded 'C:\work\StreetsOfDusk\Binaries\Debug\Game.exe', Symbols loaded.
'Game.exe': Loaded 'C:\WINNT\system32\ntdll.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\d3d9.dll', No symbols loaded.
'Game.exe': Loaded 'C:\WINNT\system32\d3d8thk.dll', No symbols loaded.
'Game.exe': Loaded 'C:\WINNT\system32\msvcrt.dll', No symbols loaded.
'Game.exe': Loaded 'C:\WINNT\system32\kernel32.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\user32.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\gdi32.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\advapi32.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\rpcrt4.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\version.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\lz32.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\winmm.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\mmdrv.dll', Cannot find or open a required DBG file.
'Game.exe': Unloaded 'C:\WINNT\system32\mmdrv.dll'
'Game.exe': Loaded 'C:\WINNT\system32\indicdll.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\imm32.dll', Cannot find or open a required DBG file.
'Game.exe': Loaded 'C:\WINNT\system32\TDispVol.dll', No symbols loaded.
'Game.exe': Loaded 'C:\WINNT\system32\d3d9d.dll', No symbols loaded.
Direct3D9: (INFO) :======================= Hal HWVP device selected
The program '[696] Game.exe: Native' has exited with code 0 (0x0).
==========================================================
What means "Cannot find or open a required DBG file."? Where can I get those DBG files?? The msdn didn't help me
|
|
|
|
|
i have no idea what your problem, but i searched google, and i found this site, where at the bottom, bumps you to this microsoft site about downloading new symbols.
it might help...
*.*
|
|
|
|
|
|
It's nothing to do with CRTDBG.H - that's the debugger telling you that it couldn't find debugging symbols for the DLLs being loaded.
Download a symbol set for your operating system from the Microsoft Debugging Tools site[^], and/or use the Symbol Server described at that site.
If you go the Symbol Server route, you'll need a permanent internet connection of at least DSL grade. 512Kbps DSL only just about cuts it - there's a hefty delay the first time you debug a project.
--
Mike Dimmick
|
|
|
|
|
Ok, i have yet another refreshing problem. I have a lsitbox on a dialogpage (actually, its page1 of a propertysheet dialog, if it makes any difference) that has x number of strings. The user has the option to delete, add to, or edit a current string. If the user selects, say, to add a new string, a new window pops up asking for the name of the string.
WHen the user hits ok, the stringname is stored and added to the contents of the lisbox. However, when the user hits ok, the main page (with the listbox) is now in focus, and the contents of the listbox have not been updated. The only way to see the new string is to change focus to another page in the dialog box, or close the dialogbox and reopen it.
I've tried UpdateData() in OnSetActive, which i put in the page1 class of my propertysheet. It didint work. (i admit i dont fully understand it, but it was a shot in the dark).
Is there some way i can refresh the page (or the whole dialog for that matter) When focus is set to it? Or, is there a way to refresh only the listbox?
*.*
|
|
|
|
|
keegan wrote:
WHen the user hits ok, the stringname is stored and added to the contents of the lisbox. However, when the user hits ok, the main page (with the listbox) is now in focus, and the contents of the listbox have not been updated.
These two seem contradictory.
You have a property page (which is derived from a dialog) that has a listbox and an Add button on it. When the Add button is clicked, a (modal) dialog is displayed where text can be entered. When that dialog is dismissed, the text that was entered is added to the listbox. Yes? You should have code something like:
void CMyPropertyPage::OnClickAdd()
{
CMyDialog dlg;
if (dlg.DoModal() == IDOK)
m_listbox.AddString(dlg.m_strText);
}
Otherwise, I'm not understanding your question.
|
|
|
|
|
Heh, i was putting my AddString in my DoDataExchange. It's worked there on other pages, but i see why it should go where you suggested.
Once again, thanks
*.*
|
|
|
|
|
DoDataExchange() is only called during a call to UpdateData().
As a side note, you should rarely, if ever, have a need to explicitly call UpdateData().
|
|
|
|
|
I have a dialog app that I've written. I want to put our company logo on it but it's in jpg format. I could resave it to a bitmap but it takes away from it's colors. So how can I display this jpg on my dialog app?
I've looked at some of the examples in the bitmaps section of codeproject but these are way too much more than I need. Any suggestions?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
You could transform it into a 24 bit bitmap but it will be a large file... I would use CxImage but I agree it is a lot of code for a simple thing like that. I think there are ways using ActiveX but I am not sure how to do this.
John
|
|
|
|
|
Try using GDI+. Displays JPEGs beautifully
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
I would like to read files greater than 32G. I think ReadFile can only handle 4 Gig files. Any suggestion? Would Mapped file work:?
Rdh
|
|
|
|
|
|
Assuming you are not wanting to read the entire file at once, there is still a maximum of 3GB of address space available. Just a guess, but I'd say that you'll need to read the file in chunks.
|
|
|
|
|
Let me see if I can explain this with shortness and clearity.
I am having to hard code the layout of a struct in memory.
Meaning that I have to hard code the actual memory location of each element in the struct.
Lets just say for simplicity that I have to start my first element at 0x0000.
The struct is layed out like this:
struct data<br />
{<br />
double min[4];<br />
double max[4];<br />
char name[4];<br />
int count;<br />
<br />
}
In order to create the struct in memory I think I need to create the layout of a byte(short word) like so:
typedef union u_do_word{<br />
unsigned short word;<br />
struct do_word_bits{<br />
unsigned pad : 8;<br />
unsigned bit7 :1;<br />
unsigned bit6 :1;<br />
unsigned bit5 :1;<br />
unsigned bit4 :1;<br />
unsigned bit3 :1;<br />
unsigned bit2 :1;<br />
unsigned bit1 :1;<br />
unsigned bit0 :1;<br />
}bits;<br />
} do_word_t;
And create the pointer and variables for the elements
I put the hex address in the name.
start of the min array
<br />
static do_word_t word_0x00;<br />
static unsigned short *vme_word_0x00;
static do_word_t word_0x20;<br />
static unsigned short *vme_word_0x20;
static do_word_t word_0x40;<br />
static unsigned short *vme_word_0x40;
static do_word_t word_0x80;<br />
static unsigned short *vme_word_0x80;
start of the max array
<br />
static do_word_t word_0xA0;<br />
static unsigned short *vme_word_0xA0;
static do_word_t word_0xC0;<br />
static unsigned short *vme_word_0xC0;
static do_word_t word_0xE0;<br />
static unsigned short *vme_word_0xE0;
static do_word_t word_0x100;<br />
static unsigned short *vme_word_100;
start of the char array
This is the part that I am not sure about.
I believe that an unsigned short will give me the correct size for a double, but how should I do the char array.
Is this correct???
static do_word_t word_0x120;<br />
static unsigned char *vme_word_0x120;
<br />
static do_word_t word_0x?????; (?? 0x124 ??)<br />
static unsigned char *vme_word_0x?????;
<br />
static do_word_t word_0x?????; (?? 0x128 ??)<br />
static unsigned char *vme_word_0x?????;
<br />
static do_word_t word_0x?????; (?? 0x12C ??)<br />
static unsigned char *vme_word_0x?????;
I am not sure how to step through the memory and create the correct size for the char array or the int at the end
Thanks for taking the time to read my winded message,
Steven
|
|
|
|
|
The size of a double is 8 bytes. Use the sizeof(double) to see that your self. I have no clue why you would want to do this. Also if you don't pack the data using #pragma pack(push,1) before your struct and #pragma pack(pop) after your struct you will get unexpected results.
John
|
|
|
|
|