|
Member 7809860 wrote: but after i free the POL1 i did pol1=nod
Yes, but that only changes the local reference to your node.
If you want the callers value to be updated you will need something like:
int push(Node **pol1,int hez,int mek)
{
Node *temp = *pol1;
Node *followtemp = *pol1;
Node *node = (Node*)malloc(sizeof(Node));
node->hezka = hez;
node->mekadem = mek;
node->size = 0;
node->next = NULL;
if ((*pol1)->size == 0)
{
free(*pol1);
*pol1 = node;
}
return ++(*pol1->size);
}
and call it like
void main()
{
Node *pol1 = create();
printf("%d\n", push(&pol1, 2, 3));
printf("%d\n", pol1->size);
}
|
|
|
|
|
The problem is that
int push(Node *poll, int hez, int mek) passes the pointer poll by value, not by reference. The assignment poll=node; is valid within push() , but the change will not be passed to the caller. As a result, after calling push() the pointer poll in main will still point to the memory location of your first node, but this node was already freed. The newly created node will be lost, as you failed to pass the pointer back to main . Your print statement accesses poll->size which is now undefined and can have any arbitrary value.
|
|
|
|
|
you are right.i solved the problem with *pol1=*node .
thanks
|
|
|
|
|
i have address a function of a process
example :73D7469D
i don't know how to read this function of that process and interact with this function
plz help me
thanks so much..sorry if my english isn't good
|
|
|
|
|
so0_lanhlung2 wrote: i don't know how to read this function of that process and interact with this function
Short answer: you can't do that.
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 open spy++ and i right click\propeties.i see winproc:001....(address) of a window
may i redefine this winproc of this window to send WM_KEYDOWN.
because this window had security...i can't sendmessage,postmessage,defwinproc
can you help me .
thanks so much
|
|
|
|
|
That's more or less the primary purpose of having security there. Without it, the opportunities for hackers and writers of viruses would be truly endless. Access to the victim's e-mails, social networks, and bank accounts would be just a few WM_KEYDOWN messages away!
|
|
|
|
|
i have 2 class CControl and CMainFrame ( MFC), in CControl i have a function
void CControl::OnButtonRun()
{
// TODO: Add your control notification handler code here
CBaocaoDoc *pDoc = GetDocument();
if(pDoc->dc_status)
{
if((pDoc->nc_status) && (pDoc->phoi_status))
{
m_feetrate.SetRange(0,1000,TRUE);
UpdateData(TRUE);
m_fr=temp_mfr; // lay toc do
m_feetrate.SetPos(temp_mfr); // set toc do
SetTimer(2,1000,NULL);
UpdateData(FALSE);
}
else MessageBox("Chua chon chi tiet hoac file","Thong bao",MB_OK);
}
else MessageBox("Chua xuat file chua duong dung cu","Thong bao",MB_OK);
}
now i want call OnButtonRun() from CMainFrame, if i call function like
void CMainFrame::OnImportfile()
{
// TODO: Add your command handler code here
CControl abc;
abc.OnButtonRun();
}
MFC have error C2248: 'OnButtonRun' : cannot access protected member declared in class 'CControl'
please, help me, thanks .
|
|
|
|
|
I'm assuming the OnButtonRun function is an event handler.
I'm further assuming that this function is called on a button click.
You can send the BN_CLICKED message to the button to simulate the button click which will then call the OnButtonRun function -
abc.SendMessage(WM_COMMAND, (BN_CLICKED << 16) | BUTTON_ID, abc.GetDlgItem(BUTTON_ID));
Having said this, you may need to access the already existing instance of CControl instead of creating a new instance of it.
|
|
|
|
|
there's a couple of ways to do it, one is using SendMessage() or PostMessage() to message the event handler (as someone has already suggested, this is the proper way)... here's another resource for how to do it:
Scroll to the bottom of the page for solutions:
http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/Q_21374701.html[^]
if you've defined CControl yourself, then you can take a shortcut and just make the method public (by doing this you're ignoring the framework)
I noticed that you're also creating CControl when you call it, that doesn't really make sense if the control is also associated with something in the GUI since you're creating this on the stack that means it'll be gone after the execution of OnImportfile()
|
|
|
|
|
dat19887 wrote: MFC have error C2248: 'OnButtonRun' : cannot access protected member declared in
class 'CControl' please, help me, thanks .
Start here.
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
thanks for reply, i'm trying but i don't work, maybe it work with API, but not with MFC, thanks very much
sorry because my english isn't good.
|
|
|
|
|
(If a mod has a better idea of where to move this question then by all means move it. I figure this forum is the closest match due to the increased odds that a professional C/C++ programmer would know about Git)
I am trying to insert a commit below the current initial-commit in a git repository. This is a local project/repository that isn't being shared, so my evil intentions won't affect others :P
The closest i've gotten was following the instructions here: http://stackoverflow.com/questions/645450/git-how-to-insert-a-commit-as-the-first-shifting-all-the-others[^]
Unfortunately those instructions discard all branches coming off of master, which i don't want to happen.
|
|
|
|
|
This is a C++ forum and has no relation to GIT whatsoever.
So you will need to find a GIT forum youself.
Here is a starting step - GIT Forums[^]
|
|
|
|
|
Hello community,
I need to show html pages in mfc dialog.In this mulitThread application,i used WebBrowser control in main thread to make it work,but the cpu usage is high up to 50%.Is there any resources should to be released?I can,t find the reason.
Complier is visual studio 2008, mfc 9.0.
Thanks for any help!
Desmond
|
|
|
|
|
Never had any problems of this kind. Does your page contain dynamic elements, like flash components and the like? How does the page perform when displayed in a stand alone browser, i.e. IE?
|
|
|
|
|
I've got the following file header structure with every field ending by '\0':
struct CF_HEADER
{
TCHAR strIdentifier[7];
TCHAR bHasPath[2];
TCHAR bOrder[2];
TCHAR nTime[4];
TCHAR nEffect[2];
TCHAR nNum[3];
TCHAR nPos[3];
};
Then I initialized a UNICODE .txt file with this header. And in the file the following can be seen by Notepad:
XXXXXX 0 0 000 0 00 00
Of course there're times when these data should be updated. One of these functions to update the bOrder field is like this:
CF_HEADER m_cfhdInfo;
CFile file;
...
void SetOrder(BOOL bOrder)
{
_itot_s(bOrder, &m_cfhdInfo.bOrder[0], sizeof(TCHAR), 10);
updateHeader();
}
void updateHeader()
{
file.Seek(2, CFile::begin);
file.Write(&m_cfhdInfo, sizeof(CF_HEADER));
}
When I called SetOrder(TRUE), things proved weird. The following data can be seen in the file by Notepad:
XXXXXX 01 000 0 00 00
However, I had expected the results like this:
XXXXXX 0 1 000 0 00 00
Anyone could help? Thanks in advance.
|
|
|
|
|
Krauze wrote: _itot_s(bOrder, &m_cfhdInfo.bOrder[0], sizeof(TCHAR), 10);
Should be
_itot_s(bOrder, &m_cfhdInfo.bOrder[0], sizeof(m_cfhdInfo.bOrder)/sizeof(m_cfhdInfo.bOrder[0]), 10);
Anyway both give the same result, I suppose.
Why are you using 'generic text mapping' while producing a UNICODE file?
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]
|
|
|
|
|
Yes, they turned out to be the same.
BTW, I reckon I need use wchar_t instead of TCHAR......as you said...
anyways, thank you all the same
|
|
|
|
|
Could you please post the code that fills the struct at first (the one that produced the right ouptut)?
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]
|
|
|
|
|
Are you sure TRUE is defined as 1? I know in MFC it is, but I've seen implementations that use the definition
#define FALSE 0
#define TRUE (!FALSE)
I don't see how this could be the cause of your problem, but it might add to it.
Also, have you checked the type BOOL is in fact defined as int and not overwritten by some old header? Wouldn't be the first time I've seen conflicting macro definitions...
You could of course overcome such issues by explicitely defining an int variable that holds the intended value:
void SetOrder(BOOL bOrder) {
int iOrder(bOrder?1:0);
_itot_s(iOrder, ...
P.S.:
I just checked the definition of the not operator '!', and it appears my above example
#define TRUE (!FALSE) would in fact result in the definition
#define TRUE true (provided you have a modern C++ compiler that supports the type bool). In a context that requires an int, true would be converted to 1 as required by the standard, so the concern I brought up can in fact not be a problem at all, and my workaround is uncalled for.
modified on Friday, April 1, 2011 10:41 AM
|
|
|
|
|
Hello community,
i need to determine the control under the cursor, to call "vertical scroll" event for it!
I have two CListCtrl-controls in my dialog, so if the mouse is over one of them,
it should be possible to scroll in this control without clicking inside of control!
Just like in MS Outlook, if mouse is over "preview" area, you can use mouse wheel without clicking in this control to scroll!
Thanks for any help!
Arrin
|
|
|
|
|
Well the cheap and cheerful way would be to call WindowFromPoint[^] when you have a WM_MOUSEWHEEL message. That will return the handle of the window/control under the mouse, then you can just SendMessage it the scroll.
|
|
|
|
|
Hello,
thanks for answer,i try to do this, but there is an little problem
when i use WM_MOUSEWHEEL windows catch this event only i my mouse is not over a CListCtrl!
But i need to use when is OVER an CListCtrl, to set set focus to this list control!
regards
Arrin
|
|
|
|
|
Try adding the wm_mousewheel handler in the dialog class. This message is always sent to parent first and then passed down to children
|
|
|
|