|
Hello,
I have a function that is called from a dll and contains static variable:
void myFn(double data)
{
static double x;
...
}
At each iteration x increases on some value.
The problem occurs when pass diffent data at the same time (i.e. call the function more than once at the same time), x variable mixes all values.
data1[] = 1,2,3
data2[] = 4,5,6
The result for the first call must be 1+2+3 = 6
The result for the second call must be 4+5+6 = 15
But now the result for the first call will be 1+4+2+5+... and so on.
How to avoid this problem?
|
|
|
|
|
At first glance, your problem sounds like one of synchronization. But then I could not figure out how you were calling myFn() . It is expecting a single argument, yet you've shown two arrays. Are you passing one member of the array with each call to myFn() ?
alikalik wrote: The result for the first call must be 1+2+3 = 6
The result for the second call must be 4+5+6 = 15
But now the result for the first call will be 1+4+2+5+... and so on.
Nothing you've shown supports this.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
alikalik wrote: call the function more than once at the same time
are you calling the DLL from multiple threads ?
|
|
|
|
|
I'm creating add-in for MS Excel.
The argument is a value in a cell.
So for instance, if I call MyFn(B11) and MyFn(B12), where B11 and B12 are cells, the result will be wrong.
|
|
|
|
|
Try putting that code in your main() function.
|
|
|
|
|
Remove the static local variable making it an argument passed by reference.
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]
|
|
|
|
|
Hi..
return i + i;
Please let me know what does this return?
wether it reurns addition of i + i Or it returns only i.
Thanks.....
modified on Monday, June 15, 2009 1:40 PM
|
|
|
|
|
Why not just try it and see?
Anand9669 wrote: wether it reurns addition of i + i Or it returns only i.
Statements end with semicolons, so 2i will be returned. Otherwise, why would the compiler choose to ignore the + i; (and thus produce an error)?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Thanks for ur reply
right now i don't have c compiler in my machine..
|
|
|
|
|
it would be very much the same in the majority of programming languages...
Assuming i is int,
int a=i+i;
return a;
does return the same value as
return i+i;
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Thanks for ur reply..
u mean to say it is as good as
return (i + i);
and there is no need of paranthesis...
|
|
|
|
|
I am trying to handle the 'Cancel' button in my property pages (wizard) and I've implemented the 'OnQueryCancel' function to catch the cancel message successfully, but unfortunately it seems that the 'OnQueryCancel' function is being called twice if the user clicked the cancel button. Any ideas on how I could address this issue? Thanks!
virtual BOOL OnQueryCancel();
BOOL CWiz_Page1::OnQueryCancel()
{
int ret;
ret = MessageBox("Are you sure?", NULL, MB_YESNO);
if(ret == IDYES)
return true;
else
return false;
}
|
|
|
|
|
JBAK_CP wrote: ...but unfortunately it seems that the 'OnQueryCancel' function is being called twice if the user clicked the cancel button.
By default, this does not happen. You've added (or removed) something that is causing this. Trying creating a new CPropertySheet -based project from scratch and note its behavior.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Dear All,
I have problem with the CListCtrl drag and drop. I used the CreateImageEx to display the image while dragging the contents of the CListCtrl but unfortunately the image is displaying at the left top corner of the screen and not relevant to my GUI where the CListCtrl is placed.
The following is the code snippet. Please advice why the image is displayed like that.
void TestDlg::OnLvnBeginrdragList3(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
OnBegindrag(&pList, pNMHDR);
*pResult = 0;
}
void TestDlg::OnBegindrag(CListCtrl* pList, NMHDR* pNMHDR)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if (pList->GetSelectedCount() <= 0)
return;
int iItem = pList->GetSelectedCount();
POINT pt;
m_pDragImage = CreateDragImageEx(pList, &pt);
if (m_imageList == NULL)
return;
m_pDragWnd = pList;
CPoint ptStart = pNMListView->ptAction;
ptStart -= pt;
m_pDragImage->BeginDrag(0, ptStart);
m_pDragImage->DragEnter(GetDesktopWindow(), pNMListView->ptAction);
SetCapture();
}
|
|
|
|
|
Please anybody help me!!!
|
|
|
|
|
Hello all, im very much confused with this make this snippet work,, let me explain my problem in simple. please follow the folling code.
class ClassA
{
public:
function_A();
function_B();
}
class Class1
{
public:
ClassA A1
Function_1();
}
class Class1::Function_1()
{
Dlg1.DoModal();
A1.function_A();
A1.function_B();
}
class ClassDlg
{
FunDlg();
}
ClassDlg::OnRefresh()
{
i wanted "A1.function_A();"
i wanted "A1.function_B();"
}
The Dialog window will be called by "Class1::Function_1()" so after closing the dialog window the function "A1.function_A();" and "A1.function_B();" are called in order to update the contents of the mainpage(say property page). actually the contents are modified in the dialog window. so what i wanted to do is call the functions "A1.function_A();" and "A1.function_B();" before closing the dialog window say at after pressing the"Refresh" button(OnRefresh will be called). Im confused its not just happening what i desired. can any expert give me a solution, like is there any try statement i can give..??
please help me...
|
|
|
|
|
From your question it seems that you want to call the function of classA from ClassDlg. Why don't you create the object for class A in ClassDlg as well as you do in Class1?
or please rephrase your question if I understood incorrectly.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Hi anshuman, thanks for your reply,
Actually,A1(object of ClassA) is like a handle to the table in the mainpage(flex grid). if i create 2 bjects that will create 2 flex grids. Instead i just wanted to update the already created table contents by this object A1.
"Dlg1" is the object of class "ClassDlg" where
class ClassDlg
{
public:
FunDlg();
OnRefresh()
}
i just wanted to call these function say "A1.function_A(); and A1.function_B();" inside the member function of class ClassDlg.
|
|
|
|
|
Hi,
how can i set an attribute with value at a particular postion in an Xml node....(im using MSXML)
|
|
|
|
|
pradeep455 wrote: particular postion in an Xml node
Particular position within an XML node? What do you mean by that exactly? What I read that as is that you want to ensure a particular ordering of attributes within an element - which you can't do, because attributes form an unordered (or more correctly, I guess, an arbitrarily ordered) collection.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i mean suppose i have an xml file..
<test a1="1" a2="2">
</test>
and i need to add a0="0" before a1...is it possible...
|
|
|
|
|
Why would you do something like that ? As far as I know, the order of the attributes is not important in the xml format. So, why is it a need to have a0 before a1 ?
|
|
|
|
|
Nope. You add it to the test node and that's all you can do. Attributes[^] are stored as a NamedNodeMap[^], which is an unordered collection.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for ur reply...
May i know is there any possibility for Xml nodes to insert at a particular position...
|
|
|
|
|
Define what you mean by an XML node....
Strictly, an XML node is the smallest indivisible unit of an XML document - an element is a node. A text run is a node. An attribute is a node. Whitespace is a node.
Even better - tell us what you're trying to accomplish - why this insistence on creating attributes or nodes at a certain position? What significance does the position of the attribute/node have? Tell us the question you're trying to answer with your need for ordered attributes.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|