|
Randor wrote: The upcast in the documentation is completely pointless
I disagree; the upcast makes it clear what the code is trying to do. Since the actual item being returned is a CButton (even though GetDlgItem doesn't know that) it would seem the sensible thing to do, especially if you then want to call some method on the CButton object.
It's time for a new signature.
|
|
|
|
|
Richard MacCutchan wrote: Since the actual item being returned is a CButton
Are you sure saying that GetDlgItem returns a CButton object?
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: Are you sure saying that GetDlgItem returns a CButton object?
No, I'm saying it returns the object whose ID is sent to GetDlgItem() , which will be some class derived from CWnd . That is why the upcast is required.
It's time for a new signature.
|
|
|
|
|
Richard MacCutchan wrote:
No, I'm saying it returns the object whose ID is sent to GetDlgItem(), which will be some class derived from CWnd.
Richard,
This is not always the case. GetDlgItem will return a CTempWnd object[^] if there is no entry inside the internal MFC handle map.
You should always avoid upcasting a pointer from GetDlgItem.
Best Wishes,
-David Delaune
|
|
|
|
|
Sorry but I'm still not clear on this. It doesn't matter whether the object pointer is permanent or temporary, it is still a CButton* . If the object does not exist, or the value to GetDlgItem() is not valid you won't get a pointer to anything.
OK David,
I have just read that article again and understand (almost, but not completely) why your assertion was correct. Sorry, for belabouring this but my experience of MFC was that this upcasting always worked; I just hope nobody is still using one of my old programs.
Thanks for the guidance.
Richard
It's time for a new signature.
modified on Tuesday, July 20, 2010 1:28 PM
|
|
|
|
|
Richard MacCutchan wrote: Thanks for the guidance.
Your welcome.
Best Wishes,
-David Delaune
|
|
|
|
|
How about calling GetCheckedRadioButton like:
int radioCheck = GetCheckedRadioButton(ID_RADIO1,ID_RADIO3);
This will return the ID of the checked radio button or 0 if none are checked
|
|
|
|
|
i am trying to skip line in a csv format file, but cant do so. i am beginner in c++.
|
|
|
|
|
Why are you unable to do so?
|
|
|
|
|
what have you tried so far ?
how is it identified which line to skip - for example line number 10, or, by something in the line (csv data) itself ? what are you doing with the lines you're not skipping etc
The approach will be different depending on your response - the first is easy - you read the file line by line, when a line counter equals the line to skip you dont do anything with the line (eg write it to a file) - if you use stl getline, you dont even need to worry wether the file is in csv format or not if you are skipping by a line number ....
We cant read your mind - unless you explain clearly what you're trying to do, and post any code you're tried, its a bit of a waste of your and our effort
'g'
|
|
|
|
|
Hi All
error C2440: '=' : cannot convert from 'void *' to 'FL_FILE *'
how can i solve this error?
I use Precompiled Headers off.
Code is here
void main()
{
FL_FILE *file;
media_init();
fl_init();
if (fl_attach_media(media_read, media_write) != FAT_INIT_OK)
{
printf("ERROR: Media attach failed\n");
return;
}
fl_listdirectory("/");
file = fl_fopen("/file.bin", "w");
if (file)
{
unsigned char data[] = { 1, 2, 3, 4 };
if (fl_fwrite(data, 1, sizeof(data), file) != sizeof(data))
printf("ERROR: Write file failed\n");
}
else
printf("ERROR: Create file failed\n");
fl_fclose(file);
}
|
|
|
|
|
You haven't really given people many clues to solve this one. Like which line the error occurs on... And no includes. And no mention of what library you're using (where all the fl_* guff comes from).
After that it looks like the only place you can get this error is file = fl_fopen("/file.bin", "w"); From the error message it looks like fl_open returns a void * and you're trying to assign it to an FL_FILE * . However as it looks like you're using C and not C++ that should be an allowed conversion...
Are you:
- compiling your code as C++ when it should be compiled as C?
- including all the headers you should be for the library you're using?
- using any build configuration settings, like #defines, that the library writer specified?
In addition have you tried compiling the code with all warnings switched on (that's /W4 on both VC++ and gcc)? That might give you some hints as to what's going on.
Ash
|
|
|
|
|
My questions is, im trying to make a small benchmark and im not sure if i am correctly doing this.
I am using a high-resolution performance counter, ive placed it in bold
This uses MD5, which you can simply get it at http://www.evenbalance.com/downloads/pbmd5.cpp[^]
im not really sure if im getting the correct bytes per second
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "md5.h"
#define MUL_BYTES 1024
#define MUL_KB (MUL_BYTES*1024)
#define MUL_MB (MUL_KB*1024)
void Benchmark_MD5(void)
{
unsigned __int64 iPerf;
unsigned __int64 iBaseTime;
double dbFreq;
unsigned char bzBuffer[] = {0x0a, 0x55, 0x23};
unsigned __int64 iValue;
MD5_CTX md5;
int iPasses = 5000;
QueryPerformanceFrequency((LARGE_INTEGER *)&iPerf);
dbFreq = 1.0 / (double)iPerf;
QueryPerformanceCounter((LARGE_INTEGER *)&iBaseTime);
for (int i = 0; i < iPasses; i++) {
MD5Init(&md5, 0);
MD5Update(&md5, bzBuffer, 3);
MD5Final(&md5);
}
QueryPerformanceCounter((LARGE_INTEGER *)&iValue);
double seconds = ((double)(iValue - iBaseTime) * dbFreq);
double bps = (double)((double)(16 + iPasses) / seconds);
printf("DEBUG: [Passes = %d] %5.3f Byte/s\n", iPasses, bps);
printf("RESULT:\t");
if (bps < MUL_BYTES)
printf(" %5.2f Bytes/sec\n", bps);
else if (bps < MUL_KB)
printf(" %5.2f KB/sec\n", bps / 1024);
else if (bps < MUL_MB)
printf(" %5.2f MB/sec\n", bps / 1024 / 1024);
else
printf(" %5.2f GB/sec\n", bps / 1024 / 1024 / 1024);
}
void main(void)
{
Benchmark_MD5();
}
|
|
|
|
|
|
This is the results
DEBUG: [Passes = 5000] 311191.953 Byte/s
RESULT: 303.90 KB/sec
DEBUG: [Passes = 5000] 734956.927 Byte/s
RESULT: 717.73 KB/sec
DEBUG: [Passes = 5000] 391962.053 Byte/s
RESULT: 382.78 KB/sec
DEBUG: [Passes = 5000] 274082.350 Byte/s
RESULT: 267.66 KB/sec
DEBUG: [Passes = 5000] 281520.063 Byte/s
RESULT: 274.92 KB/sec
|
|
|
|
|
saiyuk6=7 wrote: double seconds = ((double)(iValue - iBaseTime) * dbFreq);
To get seconds, shouldn't you be dividing by the timer's frequency?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I've updated the code somewhat now, i have taken your advice by dividing the timers freq
i've changed how the bps is calculated as well
double bps = (double)((ulSize * iPasses) / tm.Seconds());
i've multiplied the Size of the Buffer by the number of passes that runs in the for loop
results are
<br />
DEBUG: 1074556249.047 Byte/s<br />
MEMSET: 0.00/sec 0.98/ms 1.00 GB/sec<br />
RESULT: 6.91/sec 6905.56/ms 72.41 MB/sec<br />
class CTimer {
public:
CTimer() {
m_TimeStart.QuadPart = 0;
m_TimeStop.QuadPart = 0;
QueryPerformanceFrequency(&m_Frequency);
}
void Start(void) {
QueryPerformanceCounter(&m_TimeStart);
}
void Stop(void) {
QueryPerformanceCounter(&m_TimeStop);
}
double Seconds() const {
return (double)(m_TimeStop.QuadPart - m_TimeStart.QuadPart) / (double)m_Frequency.QuadPart;;
}
double Milliseconds() const {
return Seconds() * 1000.0;
}
private:
double m_dbFreq;
LARGE_INTEGER m_Frequency;
LARGE_INTEGER m_TimeStart;
LARGE_INTEGER m_TimeStop;
};
#define MUL_BYTES 1024.0
#define MUL_KB (MUL_BYTES*1024.0)
#define MUL_MB (MUL_KB*1024.0)
#define MUL_GB (MUL_MB*1024.0)
std::string BPStoString(double dbPerSec)
{
char *pTemp[] = {
"Bytes", "KB", "MB",
"GB", "TB", "PB",
"EB", "ZB", "YB"
};
char szTemp[30];
int i = 0;
while (dbPerSec >= 0.9 * MUL_BYTES) {
dbPerSec /= MUL_BYTES;
i++;
}
sprintf(szTemp, "%5.2f %s/sec", dbPerSec, pTemp[i]);
return std::string(szTemp);
}
void Benchmark_MD5(void)
{
CTimer tm;
tm.Start();
unsigned long ulSize = MUL_KB;
unsigned char *bzBuffer = new unsigned char[ulSize];
if (bzBuffer != NULL) {
memset(bzBuffer, 0, ulSize);
tm.Stop();
<code>double bps = (double)((ulSize * 1) / tm.Seconds());</code>
printf("DEBUG: %5.3f Byte/s\n", bps);
printf("MEMSET: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());
}
tm.Start();
MD5_CTX md5;
int iPasses = 500;
for (int i = 0; i < iPasses; i++) {
MD5Init(&md5);
MD5Update(&md5, bzBuffer, ulSize);
MD5Final(&md5);
}
tm.Stop();
<code> double bps = (double)((ulSize * iPasses) / tm.Seconds());</code>
printf("RESULT: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());
delete bzBuffer;
}
modified on Monday, July 19, 2010 8:57 PM
|
|
|
|
|
saiyuk6=7 wrote: unsigned char *bzBuffer = new unsigned char[ulSize];
Why not:
unsigned char bzBuffer[MUL_KB];
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
well i've tried doing that but i get this error
bm.cpp
bm.cpp(40) : error C2057: expected constant expression
bm.cpp(40) : error C2466: cannot allocate an array of constant size 0
bm.cpp(40) : error C2133: 'bzBuffer' : unknown size
Well i had started to allocate memory for it because later on i was going to start using a hash driver that i was going to make that would provide me with several hash algo's,.... example
there might be errors below, but its just a example of what i had planned to do
unsigned char *bzBuffer;
for (int i = HT_MD5; i < (HT_WHIRLPOOL + 1); i++) {
hash.Init(i);
bzBuffer = new unsigned char[hash.DigestSize()];
if (bzBuffer == NULL) {
return 0;
}
hash.Update(hashTest[i].buffer, hashTest[i].length);
hash.Final(bzBuffer);
for (int h = 0; h < hash.DigestSize(); h++)
printf("%02.2%", bzBuffer[i]);
delete bzBuffer;
}
modified on Tuesday, July 20, 2010 12:28 PM
|
|
|
|
|
int _cdecl main(int argc, char *argv[])
{
OutputDebugString("Hello World");
}
When I compile and debug with Target = Win32 I get:
Hello World
(plus a lot of 'instlsp.exe': Loaded 'C:\WINDOWS\SysWOW64\....dll', Cannot find or open the PDB file)
When I compile and debug with Target = x64 I get nothing
It runs but the output is filtered somewhat.
I tried this
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Debug Print Filter]
"DEFAULT"=dword:0000000f
And also 0xFFFFFFFF
No success even after reboot.
I feel like I am stuck in chapter 1 of the Kernighan and Ritchie C book.
I am using Visual C++ Express under Windows XP Pro x64
Is this just a bad day?
Going to the zoo now. Perhaps the monkeys will have a clue, I should take a couple of typewriters with me.
|
|
|
|
|
Pascal Ganaye wrote: Going to the zoo now. Perhaps the monkeys will have a clue,
Sorry, but I have no clue.
Seriously though, I'm on Windows 7 x64 and it works just right for me. Which platform are you on?
It's time for a new sig. Seriously.
|
|
|
|
|
Hi
I am developing a application
knowing the size of downloaded data from the net
for a month for a PC.
How to do this?
|
|
|
|
|
You need to be more specific. What 'data'? Where is it stored? Is it part of your application?
If you have a more intelligent router connecting you to the Internet then you could use SNMP to pull statistics from the router.
Sorry but while you are so vague it is impossible to advise further.
P.S. this is more a general IT question.
Alan
|
|
|
|
|
|
I tried compiling my application in 64bit, during compilation I got errors. Cause my application uses UNICODE, does 64bit lack UNICODE support???
|
|
|
|