|
Hi experts
I write a recursive program to read entries from a file .
First i take 512 entries in a buffer then i read them .
But after reading app. 1000 of entreis the "new" operator does not allocate memory to buffer. It display a exception
"Unhandled exception at 0x7c90eddc in PST_OFFICE97.exe: 0xC0000005: Access violation writing location 0x00030f18."
when i look at 0x00030f18 it shows bytes filled with highlighted "?".
what is the problem ?
|
|
|
|
|
You need to post some code
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
BOOL Message::TableofOffset_Index_Pointer(DWORD dwOffsetOfTable)
{
cout<<hex<<dwoffsetoftable<<endl;
dword="" offset="0ul;
" bool="" flag="false;
" struct="" firsttableoffset="" *prev_table_offset="NULL;
" if(dwoffsetoftable="=0x115d5200)//0x114d9400)
" getchar();
="" if(message::readfilebyte(dwoffsetoftable,0x200))
="" memcpy(&offset,m_pbytfilebuffer+skip_bytes,4);
........
.......
.......
="" memcpy(&first_table_offset-="">st_dwTableId,m_pbytFileBuffer+i,4);
memcpy(&First_Table_Offset->st_dwUnknown,m_pbytFileBuffer+i+BytesToRead,4);
memcpy(&First_Table_Offset->st_dwOffsetOfTable,m_pbytFileBuffer+i+(BytesToRead*2),4);
i=BytesToRead*3;
........
.......
.......
dwOffset=Tmp->st_dwOffsetOfTable;
Tmp=Tmp->Next;
delete[]m_pbytFileBuffer;
m_pbytFileBuffer;
Message::TableofOffset_Index_Pointer(dwOffset);
///////calling same function
return true;
}
|
|
|
|
|
So how does the recursion end?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
How can i combine a LPCSTR with an int resulting in a LPCSTR.
E.g.
LPCSTR test = "Count = ";
int count = 5;
And I want a LPCSTR to be equal to "Count = 5".
|
|
|
|
|
The best way to do this is to use a wrapper like std::string, or CString. The C way to do this, is to use string manipulation methods. The method that gets a string from a number is sprintf. The method to combine strings is strcat.
strcat(test, sprintf("%d", count));
Here are the wrinkles:
1 - you say test is a LPCSTR. C stands for const, so it can't be changed
2 - this method does not allocate memory, test needs to have enough space allocated after the null terminator to make room for a copy of the number string.
3 - I did this inline, but that will leak memory, you need to make a copy of the string with the number, allocate memory to a new string that includes enough space for both strings, then use strcpy to copy the first one over, and strcat to copy over the second.
4 - if you're using VS2005, you'll need to use the new 'safe' versions or you will get warnings
So much easier to use C++.
ostringstream ss;
ss << "Count=" << 5;
string s= ss.str();
Something like that.
http://www.codeproject.com/vcpp/stl/ostringstream.asp[^]
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi all,
I have used Registered ActiveX Controls in VC++ 6.0 such as
Microsoft Forms 2.0 Label.
Microsoft Forms 2.0 Image.
Microsoft Forms 2.0 CheckBox etc..
In some of the systems, when i run the exe, it will not display these components.
What is the problem. Please help me.
Thanks in Advance.
|
|
|
|
|
The ActiveX controls must be registered/installed in each machine in which you will use your app.
this is the main reason why I always try to not use them. Of course some times the only solution is using some of them and installing/registering them in each computer.
Hope this helps.
|
|
|
|
|
Thank you,
May i know the DLL/OCX need to be registered for
Microsoft Forms 2.0 Label.
Microsoft Forms 2.0 Image.
Microsoft Forms 2.0 CheckBox etc..
these components?
|
|
|
|
|
MaHeSG wrote: May i know the DLL/OCX need to be registered for
FM20.DLL
nave
|
|
|
|
|
|
Dear Friends,
I hav developed an MFC application in Visual Studio 2005 my problem is that the application runs fine in my PC(which has Visual Studio 2005 installed in it).For final code release(i.e to give .exe file to somebody) i should build it in Release mode.Im not able to properly configure the Property Pages.(Though the building is succesfully in Release mode it doesnt run on other pc that doesnt hav visual tool it gives message saying that the application configuration is incorrect)
Im using the following code somewhere in the project:
#using "mscorlib.dll";
using namespcae System;
this requires to be compiled with Common language RunTime Support as: /clr and RunTime Library as /MT. This is creating some problem i think.
Please help me Im not able to properly configure the Property Pages
|
|
|
|
|
You need to install the .Net Framework v2.0 on the other computer.
|
|
|
|
|
Hello All,
I have a timer in my dialog which starts in the function and some process is done and I have called the stop timer as below.
working code:-
<br />
<br />
int OnStart(HWND hwnd)<br />
{<br />
dwLastTickCount = GetTickCount();<br />
SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL);<br />
pA->start();<br />
KillTimer(hwnd, ID_ELASPED_TIMER);<br />
return 0;<br />
}
Now the problem is timer clock is not displayed on the dialog, once the process is over the timer is displayed.
Can one please tell me how to do 2 process at a time ??? displaying the timer clock on the dialog and doing the process ??
I tried with thread as below its not working what is the error ?? what changes I have to make to thread ??
<br />
<br />
int OnStart(HWND hwnd)<br />
{<br />
HANDLE hr;<br />
hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,0,0,0);<br />
<br />
return 0;<br />
}<br />
<br />
<br />
UINT WorkerThreadProc(LPVOID Param);<br />
<br />
<br />
UINT WorkerThreadProc(LPVOID Param)<br />
{<br />
HWND hwnd;<br />
<br />
IMyA *pA;<br />
<br />
dwLastTickCount = GetTickCount();<br />
SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL);<br />
<br />
pA->start();<br />
<br />
KillTimer(hwnd, ID_ELASPED_TIMER);<br />
<br />
return true;<br />
}<br />
Thanking you,
Suresh HC.
|
|
|
|
|
Suresh H wrote: SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL);
how did u get the handle hwnd in the thread function? As per your code its not valid handle. You need to pass this handle to the WorkerThreadProc from the OnStart function. Modify it as below
int OnStart(HWND hwnd)<br />
{<br />
HANDLE hr;<br />
hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,(LPVOID)hwnd,0,0);<br />
<br />
return 0;<br />
}
UINT WorkerThreadProc(LPVOID Param)<br />
{<br />
HWND hwnd = (HWND)Param;<br />
<br />
IMyA *pA;<br />
<br />
dwLastTickCount = GetTickCount();<br />
SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL);<br />
<br />
pA->start();<br />
<br />
KillTimer(hwnd, ID_ELASPED_TIMER);<br />
<br />
return true;<br />
}
nave
|
|
|
|
|
Hi Naveen,
Thank you very much now the thread function is working & the timer is also displayed along with process. I forgot to pass the HWND from onStart function.
Thank you very much,
Suresh HC.
|
|
|
|
|
hi Naveen,
I am getting some problem with the handle HWND & hwnd.
in thread i am trying to extract the Edit box contents but i am getting the junk values, why i am getting the junk values ?? what is wrong in the code ???
same code was working in the OnStart function, when I moved it to thread is not working what is cause ???
<br />
<br />
<br />
UINT WorkerThreadProc(LPVOID Param)<br />
{<br />
HWND hwnd = (HWND)Param;<br />
<br />
<br />
char *FName = new char[20];<br />
HWND HEFName = GetDlgItem(hwnd, IDC_FILE_NAME);<br />
SendMessage(HEFName , EM_GETLINE, 0 ,(LPARAM)FName);<br />
}
output :- ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
|
|
|
|
|
Suresh H wrote: SendMessage(HEFName , EM_GETLINE, 0 ,(LPARAM)FName);
MSDN says
lParam:<br />
Pointer to the buffer that receives a copy of the line. Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer. For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters. The size in the first word is overwritten by the copied line.
so u should set the first 2 byte of buffer as size of the array.
char *FName = new char[20];<br />
WORD* pWord = (WORD*)FName;<br />
*pWord = 20;<br />
HWND HEFName = GetDlgItem(hwnd, IDC_FILE_NAME);<br />
SendMessage(HEFName , EM_GETLINE, 0 ,(LPARAM)FName); ]
if the edit control is a single line edit I suggest you to use GetWindowText() function.
nave
|
|
|
|
|
Hi Naveen,
Once again thank you very much for the response.
Now i am getting the values properly. Thank you very much for explanation its very use full.
I had used the same code in the OnStart() and it was working properly ,but how ??
|
|
|
|
|
Suresh H wrote: and it was working properly ,but how ??
may be because the following reason.
When you new some data, the memory allocated contains some junk values. when you call the function from OnStart(), the first two byte might had some valid positive values. Then there is a chance for that function to work properly. Just a guess
nave
|
|
|
|
|
Thanks Naveen for the response.
|
|
|
|
|
In addition to what Naveen said, read this article on creating and dealing with worker threads ->Using Worker Threads[^] There is a sub topic "Worker threads and the GUI II: Don't touch the GUI" that specifically spells out to not to let other threads touch the UI and why its bad.
Best of luck.
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
hi !
i need to pass array of objects in the function by reference. can any one help me ?
i created the following class declaration.
class TagE
{
string x,
string y,
int z,
public :
void foo(TagE & )//? what should i write here?
};
int main()
{
TagE t[25];
// how can i pass t[25] as function argument
foo(t);// what should i write here
}
can any guide me or send me test/demo/example link?
Amit
|
|
|
|
|
amitmistry_petlad wrote: void foo(TagE & )//
u can pass the array to foo by changing the prototype of foo as below
void foo(TagE* );
nave
|
|
|
|
|
but i want to use reference rather then pointer.
|
|
|
|