|
If you allocate an array with new, then you should deallocate an array also. When you use new[], some information will be put in front of your pointer to hold the number of elements you allocate. So, you really need to match new with delete and new[] with delete[], otherwise you'll get a crash.
|
|
|
|
|
I agree what you said.
But this code:
struct T{
int m;
int n;
};
[1] int* int_array=new int[4];
[2] delete int_array;
[3] struct T *t=new T[4];
[4] delete t;
The code will work well.
Why,now?
Thank you.
|
|
|
|
|
Because you are just being lucky . It is not because it doesn't crash that your code is correct. You will probably have some memory leak also: the delete expect to free only one element, so, only the space for one element will be deallocated, resulting in a memory leak.
|
|
|
|
|
I hope so.
And I will follow your guideline in future.
Thank you very.
Have a good day.
|
|
|
|
|
I have done an untitled dialog box in MFC,
Clicking on this dialog button on taskbar, window does not minimize or maximize.
To handle this i have written code in OnNcActivate message.
My problem is that, when i say ShowWindow(SW_SHOWNORMAL); at that time the window
is shown but again it gets minimized. It does not get hold.
Please try the code, let me know what is the problem.
Here is the following code
BOOL CRestoreDlg::OnNcActivate(BOOL bActive)
{
BOOL b2 = FALSE;
TBBUTTON tbButton;
HWND hWndBut = NULL;
WINDOWPLACEMENT wndpl;
HANDLE hProcess = NULL;
LPVOID lpRemoteBuffer = NULL;
DWORD dwProcessId = 0, dwThreadId = 0;
memset(&wndpl, 0, sizeof(WINDOWPLACEMENT));
memset(&tbButton, 0, sizeof(TBBUTTON));
GetWindowPlacement(&wndpl);
HWND hDesktop = ::GetDesktopWindow();
HWND hTray = ::FindWindowEx(hDesktop , 0, _T("Shell_TrayWnd"), NULL);
HWND hReBar = ::FindWindowEx(hTray, 0, _T("ReBarWindow32"), NULL);
HWND hTask = ::FindWindowEx(hReBar, 0, _T("MSTaskSwWClass"), NULL);
HWND hToolbar = ::FindWindowEx(hTask, 0, _T("ToolbarWindow32") , NULL);
LRESULT count = ::SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0);
dwThreadId = GetWindowThreadProcessId(hToolbar, &dwProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
if (NULL == hProcess)
{
return FALSE;
}
for (int i= 0 ; i < count ; i++ )
{
memset(&tbButton, 0, sizeof(TBBUTTON));
lpRemoteBuffer = VirtualAllocEx(hProcess, NULL, sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE);
if (NULL == lpRemoteBuffer)
{
return FALSE;
}
::SendMessage(hToolbar, TB_GETBUTTON, i, (LPARAM)lpRemoteBuffer);
b2 = ReadProcessMemory(
hProcess,
lpRemoteBuffer,
(LPVOID)&tbButton,
sizeof(TBBUTTON),
NULL);
if (FALSE == b2)
{
return FALSE;
}
BYTE localBuffer[BUFFER_SIZE];
BYTE* pLocalBuffer = localBuffer;
DWORD_PTR ipLocalBuffer = (DWORD_PTR)pLocalBuffer;
pLocalBuffer = localBuffer;
ipLocalBuffer = (DWORD_PTR)pLocalBuffer;
DWORD_PTR lpRemoteData = (DWORD_PTR)tbButton.dwData;
ReadProcessMemory(hProcess, (LPVOID)lpRemoteData, (LPVOID)ipLocalBuffer, sizeof(DWORD_PTR), NULL);
HWND windowHandle;
memcpy(&windowHandle, (void *)ipLocalBuffer, 4);
if (windowHandle == m_hWnd)
{
if (tbButton.fsState & TBSTATE_PRESSED)
{
if (wndpl.showCmd == SW_SHOWMINIMIZED)
{
ShowWindow(SW_SHOWNORMAL);
}
else if (wndpl.showCmd == SW_SHOWNORMAL)
{
ShowWindow(SW_SHOWMINIMIZED);
}
}
}
VirtualFreeEx(hProcess, lpRemoteBuffer, 0, MEM_RELEASE);
}
CloseHandle(hProcess);
return TRUE;
}
|
|
|
|
|
If the winow is created with out the WS_MINIMIZEBOX, style your window cannot be minimized. then why are you doing all this?
|
|
|
|
|
Dialog box tilte bar is removed from property of dialog box, and own title bar is set with min/max buttons.
When default title bar is removed, dialog window does not minimize/maximize from taskbar button.
We have to handle this, I have tried to do it in OnNCActive message. It is not working fine.
If any idea about it, please help
|
|
|
|
|
I just tried this and got a very simple solution. Add the following code in the OnInitDialog() function. Even if the window dosent have the titlebar, if you specify this style the minimize/restore is working
ModifyStyle( 0, WS_MINIMIZEBOX );
|
|
|
|
|
Thank you. It has worked.
|
|
|
|
|
Thank You. It has worked.
|
|
|
|
|
Hello all,
I have made a worker thread (which is running 10 times simultaneously) in which i am displaying a messagebox. I want that when a message window is open second message window shouldn't popup.
Can anybody help me in this.
Thanks in advance.
|
|
|
|
|
|
neha.agarwal27 wrote: I have made a worker thread (which is running 10 times simultaneously) in which i am displaying a messagebox.
Why? That pretty much goes against the grain of what a worker thread is meant for.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
anybody pls give me a suggestion.
i already developed communication b/w two systems by RS-232(9pin)port.
nw i want 2 prepare communication b/w Pc and Modem.
when ever i hit a AT commands to Modem from my dailog...then Modem response is also be displayed in my Dailog box....
kp
|
|
|
|
|
Yes, and what's the exact question ? Where are you stuck exactly ? You already asked a similar question yesterday and you got some answers, so where is the problem ?
(And please, avoid using SMS language, because it is quite difficult to read for non native english speakers).
|
|
|
|
|
Mr.Moonen sir thankyou for your's reply.
i created a port configarations using combo box and i created a "openport" button.and port also opened.
after this in i created a two editboxes, one for ATcommands to Modem and other for Responses from modem like When Hyper terminal.
exactly here iam not getting any idea.how send commands to modem and getting responces from modem to our editbox.
i think u can understand my problem.
kp
|
|
|
|
|
Once you opened the port with CreateFile, you can use ReadFile to read data from the serial port and WriteFile to write data on the port. Take a look at this article[^] for complete information.
Take a look also at this section[^] that contains several articles about serial port communication (and some wrapper classes too, to make your life easier).
|
|
|
|
|
Cedric Moonen wrote: ...it is quite difficult to read for non native english speakers).
It's difficult for us English-ians too!
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hi
can u help me by telling how you develop communication between two systems through port
thanks
|
|
|
|
|
Mr.p_
first you go through your systems hyperterminal and see the port configarations and know about them
|
|
|
|
|
trn f cmd eko md n th mdm
Er,
Turn off the Command Echo mode on the modem.
A modem will either echo back the command you send it (E1) or not (E0).
Type in "ATE0" It will echo back.
Type in another AT command. It should not echo.
Read the modem commands in the manual if this is not clear.
It is probably working correctly.
Gary
|
|
|
|
|
Hey everyone,
I've got a C++ console application and it goes into a loop while that never ends except when the user presses the ESC key! Right now my loop is coded like this:
while (!kbhit())
{ code }
I have to change the kbhit bit to make it so it only ends the loop when I press the ESC key!
Thanks for your help in advance, I appreciate it!
Michael
|
|
|
|
|
while( 1 )
{
if( kbhit())
{
if( getch() == 27 ) break;
}
cout << "Hello ";
}
- NS -
|
|
|
|
|
it is mush simple if it is like that.
while ( (ch = getch())!= 27 )
{
/// loop statements
}
Thank You.
hiren thakkar
|
|
|
|
|
It is wrong...
The loop will be blocked, because getch will wait for key hit. The loop will be executed in each key strokes...
- NS -
|
|
|
|