|
m_pWndInPlace is invalid here.
PS: The problem is about anothing, change value via value list(a parent CMFCPropertyGridProperty),
the changes in subitems will not be informed. And when trying to add it manually, encounter this problem. I'll find another way before VS2008 SP1.
modified on Saturday, July 5, 2008 8:29 PM
|
|
|
|
|
Dear All
I'm having a spot of trouble - I'm hoping someone out there with a bigger brain than me might be able to help
I am trying to read a file and filter the contents into an output file. The input file is about 1.5Gb.
My code chugs away neatly doing it's job until it hits about 12% completion, then simply hangs or crashes! I have changed from the fstream.h to the windows.h to avoid the larger file issues associated there, but it still appears to give me problems. I was expecting problems over 4Gb, but the source text file is way smaller than that.
Anyway, here's the code for you - Again, any help is really apreciated.
#include <windows.h>
#include <iostream.h>
char * getEmail(char * str)
{
char * email;
int atpos = 0;
int spos = 0;
int epos = 0;
int length = strlen(str);
email = new char[length];
strcpy(email, "");
int x = 0;
while(x < length)
{
char ch = str[x];
if(ch == '@')
{
atpos = x;
}
x++;
}
if (atpos > 0)
{
bool found = false;
spos = 0;
x = atpos;
while(x > 0 && !found)
{
char ch = str[x];
if(ch == ',' || ch == '"')
{
spos = x;
found = true;
}
x--;
}
found = false;
epos = length;
x = atpos;
while(x < length && !found)
{
char ch = str[x];
if(ch == ',' || ch == '"')
{
epos = x;
found = true;
}
x++;
}
x = spos + 1;
int i = 0;
while(x < epos)
{
char ch = str[x];
email[i] = ch;
email[i + 1] = '\0';
x++;
i++;
}
}
return email;
}
int main(void){
HANDLE infileH;
HANDLE outfileH;
BOOL rsuccess;
BOOL wsuccess;
char s[10];
DWORD numRead;
DWORD numWriten;
char infile[MAX_PATH] = {"datafile.txt"};
char outfile[MAX_PATH] = {"output.txt"};
char * email;
char str[1024];
int x;
int i;
int atcount;
double goodemails = 0;
double bademails = 0;
DWORD pc = 0;
DWORD c = 0;
DWORD t = 0;
DWORD sizeLo, sizeHi;
cout << "Starting email extraction...\n\n";
infileH = CreateFile(infile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
if(infileH == INVALID_HANDLE_VALUE)
{
cout << "Error #" << GetLastError() << " occured on file open." << "\n";
}
sizeLo = GetFileSize(infileH, &sizeHi);
t = sizeLo;
outfileH = CreateFile(outfile, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
if(outfileH == INVALID_HANDLE_VALUE)
{
cout << "Error #" << GetLastError() << " occured on file open." << "\n";
}
x = 0;
do{
rsuccess = ReadFile(infileH, s, 1, &numRead, 0);
s[numRead] = 0;
str[x] = s[0];
str[x + 1] = '\0';
if(str[x] == '\n')
{
email = new char[1024];
email = getEmail((char*)str);
strcat(email, "\r\n");
i = 0;
atcount = 0;
while(i < (int)strlen(email))
{
if(email[i] == '@') atcount++;
i++;
}
if(atcount == 1)
{
wsuccess = WriteFile(outfileH, email, strlen(email), &numWriten, 0);
c = c + strlen(str);
pc = (DWORD)(((float)c / (float)t) * 100.0);
cout << pc << "% complete: " << email;
goodemails++;
}else{
c = c + strlen(str);
pc = (DWORD)(((float)c / (float)t) * 100.0);
cout << pc << "% complete: " << email;
bademails++;
}
x = 0;
}
x++;
}while(numRead > 0 && rsuccess && wsuccess);
CloseHandle(outfileH);
CloseHandle(infileH);
cout << "\n\n100% email extraction complete.\n\n";
cout << "Number of extracted emails: " << goodemails << "\n";
cout << "Number of bad emails removed: " << bademails << "\n";
return 0;
}
</iostream.h></windows.h>
|
|
|
|
|
You're going to need to do some more work at narrowing down the problem to just a small handful of lines if you want anyone to take you seriously. Use the debugger to help with this.
I see two instances of new , but no matching delete . Are you running low on memory?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
David is right; you allocate email, then clobber that pointer with an allocation within getEmail(); Neither make sense since you're using 1k.
I suspect, though, that the bigger problem is a buffer overrun. You do nothing to prevent more than 1k of data being put in str or email.
Another observation: you know how much data is being placed in the various strings, yet insist on calling strlen() and strcat() on them.
And what's with snippets like these?
char ch = str[x];
if(ch == ',' || ch == '"')
char ch = str[x];
email[i] = ch;
Why make goodemails a double. It can never be larger than a DWORD!
Why do you duplicate the code calculating the percent complete and why not define variable locally so it's more clear?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Thanks for the feedback. I worked with C++ back in the day and I guess I'm rather rusty. Trying to throw this together quickly and with zero sleep doesn't help.
Joe, you were spot on with the buffer overruns. More haste, less speed. All works a treat after some housekeeping.
Thanks again
|
|
|
|
|
Ubik K wrote: I worked with C++ back in the day and I guess I'm rather rusty.
Other than a few calls to cout , nothing that you have is C++.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm sure you're fun at parties. Ever heard of tact? Would it have been more accurate to say C with a smattering of Win32 system service calls?
|
|
|
|
|
The modeless dialog is created this way:
void CPropWnd::OnNavigator()
{
CNavDlg *pDlg = new CNavDlg(this, this);
pDlg->Create(IDD_NAVIGATOR, this);
CRect rc;
GetWindowRect(&rc);
pDlg->SetWindowPos(NULL,rc.left+rc.Width()+5,rc.top,0,0,SWP_NOZORDER|SWP_NOSIZE|SWP_SHOWWINDOW);
pDlg->UpdateWindow();
}
Why, and how?
|
|
|
|
|
I just wonder where you would destroy your dialog? If you create a dialog with "new" keyword you have to destroy it somewhere. Maybe this is the real source of your problem ...
So long,
Stefan
|
|
|
|
|
If the windows will be destroyed automatically after its parent is destroyed, I can't delete the object in OnPostDestroy .
|
|
|
|
|
I think OnPostDestroy is too late, OnDestroy would be the right event handler in my opinion. Can you try that?
|
|
|
|
|
CScrollView do it in OnPostDestroy,
OnDestroy is also ok, better to delete this after the base class's OnDestroy is called.
system
|
|
|
|
|
Hi all,
I have made a dialog based application in that i have given it name abc so name of exe is coming as abc.exe. I want to change it.... How can i do it???
|
|
|
|
|
It varies depending on which version of Visual Studio you are using. The general idea is to look at the linker properties for the project. One of the properties is the name of the output file. Set the output file property to the name you want.
|
|
|
|
|
Hello everybody,
Does anyone know how to catch out of memory allocation in C/C++?
Thanks in advance
It is never late to learn
|
|
|
|
|
Simply check the reutned pointer for NULL. If it is null the memory was not allocated.
-Saurabh
|
|
|
|
|
That really depends on HOW you're allocating the memory.
Throw us a bone here
Mark
|
|
|
|
|
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
I need to impersonate the user to logged in to the system .The process of impersonation should be like this
1) The user will input the username to be impersonate and passwd
2) There will be a dummy user in the system .
3) I need to read all the privilages for the inputted user
4) Then the dummy user will be logged in to the system with all the
privilages of the inputted user
The purpose of this is whether i inputted administrator or guest user ,the logged user will be dummy with the admin/guest privilges
Can any body tell me how can i achieve this
The whole thing should be worked in winNT series and winXP series (including vista )
Its a servie application
vineesh
|
|
|
|
|
And for what reason, might I ask, would you want to impersonate a user?
Forgive me if your intentions are good, but this sounds like a question better asked at http://www.offensivecomputing.net/[^]
|
|
|
|
|
http://www.codeproject.com/KB/grid/PrintDataGridView.aspx[^]
this is link where a code is present in VB and c#, can anybody provide me this type of code in VC++2005.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
modified on Saturday, July 5, 2008 6:52 AM
|
|
|
|
|
|
I m not talking about Grid ctrl i just want to know about the printing method which is used in this example.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|