|
I found a way to do this, so don't worry to answer this.
|
|
|
|
|
Hai,
I'm working on a C++ application.I declared two int variable as public.But when I assign those variables in one the member functions and try to use that value in the other member function, I could'nt get those values.When I debug the application I get some junk values assigned to those variables.What am I missing here?
Thanks in advance.
|
|
|
|
|
Hello,
Post some code so we can see whats going on...
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
hai, Sorry for that..
class myclass
{
public :
int var1 ; int var2;
int cnt;
myclass(void);
myclass(int myvar);
int myfunc1();
int myfunc2();
}
myclass::myclass(void)
{ var1=0;var2=0; }
mycalss::mycalss(int myvar)
{this->cnt = myvar;}
int mycalss::myfunc1()
{
.....
var1 = 6758; //here I assign values to these variables
var2 = 674;
.....
}
int mycalss::myfunc2()
{
....
if(var1<7000 && var2> 500)/// Here I couldnt get those values that I assigned in func1()
....
}
while calling these function in main I call as
myclass myC;
myC.myfunc1();
myclass myC1(dcnt);
myC1.myfunc2();
what am I missing??
Thanks again.
|
|
|
|
|
Hello,
In your code exemple, you create 2 instances of myclass. Since the 2 variables var1 and var2 are not static, they are not shared between the 2 instances of myclass.
Exemple:
myclass A;
A.myfunc1();
myclass B;
if you declare var1 and var2 static, they'll be shared among all instances of myclass. (you can even access the value static variables without an instance of the class like this: myclass::var1!)
Hope that this will help you out.
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
Hai,
Thanks a lot..But when I declare the var as static it gives me LNK2001 error.
ie..
error LNK2001: unresolved external symbol "public: static int mycalss::var1" (?var1@myclass@@2HA)
where I went wrong??
thanks.
|
|
|
|
|
Now that var1 is static member, how/where are you initializing it?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hai,
I did'nt change anything in the code expect for I declared the var1 & var2 as static and used them as myclass::var1 and myclass::var2 in the funcs.
what should I do?? Thanks a lot.
|
|
|
|
|
Ann66 wrote:
I did'nt change anything in the code expect for I declared the var1 & var2 as static...
My point exactly. Static member variables must be defined and initialized outside of the class declaration.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang_static_data_members.asp
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Ya ..It worked..thanks a lot
|
|
|
|
|
Hello,
Declare your var like this:
<br />
class myclass<br />
{<br />
public:<br />
static int var1, var2;<br />
};<br />
You can access the vars like this
<br />
myclass::var1 = 1;<br />
myclass::var2 = 8457;<br />
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
It worked..thanks a lot..
|
|
|
|
|
I'm writing some sort of firewall, using the hook driver from microsoft.
I want to take the packet received up to the user mode ap to make the filtering there, cause that way, using user mode api i can know which process is holding a connection.
I know this method will slow down the connection... but it's just an experiment
Then... I'd like to know if for every packet there's a new instance of the driver, or they're queued. cause if they are queued the method above, would be slow AND i'll miss some packets
Thank you in advance for your help
|
|
|
|
|
It depends on the type of your driver...
Yours sincerely,
Alex Bash
|
|
|
|
|
|
Hi Guys,
I have a class derived from CStatic that I used to create my own custom static display. I try to use SetBitmap to insert an image into the control as a background and then I draw the text on top of that. The problem is that sometimes the button doesn't show the image that I set into it. Sometimes it shows windows controls(minimize button, maximize button, or just garbage), but this only happens sometimes. I cannot reproduce the problem consistently so maybe I am leaking resources or something, I don't know. Here is my code. Can anyone tell what is wrong?
void CStatusDisplay::SetButton(CString cszFilename, UINT nIDResource)
{
CBitmap cbBitmap;
HBITMAP hBitmap;
HBITMAP hOldBitmap=NULL;
if(cszFilename!="")
{
if(LoadBitmapFromFile(cszFilename, cbBitmap))
{
hBitmap = (HBITMAP)cbBitmap.Detach();
hOldBitmap = SetBitmap(hBitmap);
}
else
{
AfxMessageBox("Error loading bitmap in display status");
}
}
else
{
if(cbBitmap.LoadBitmap(nIDResource))
{
hBitmap = (HBITMAP)cbBitmap.Detach();
hOldBitmap = SetBitmap(hBitmap);
}
else
{
AfxMessageBox("Error loading bitmap in display status");
}
}
if(hOldBitmap!=NULL)
DeleteObject(hOldBitmap);
}
//This gets called in OnPaint!!
void CStatusDisplay::Draw()
{
CClientDC dc(this);
CRect rect;
GetClientRect(&rect);
CMemDC2 memDC(&dc, &rect,TRUE);
//memDC.FillSolidRect(&rect, RGB(72,82,107));
//memDC.FillSolidRect(&rect, RGB(255,0,0));
DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, (LPARAM)0);
//add some text on top of that
CFont font;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = m_nFontSize;
if(m_bBold)
lf.lfWeight = FW_BOLD;
if(m_bItalics)
lf.lfItalic = TRUE;
strcpy(lf.lfFaceName, m_cszFontName);
font.CreateFontIndirect(&lf);
CFont* def_font = memDC.SelectObject(&font);
memDC.SetBkMode(TRANSPARENT);
memDC.SetTextColor(m_crTextColor);
UINT uFormat = NULL;
if(m_cszAlign == "left")
uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER |DT_LEFT | DT_END_ELLIPSIS;
else if(m_cszAlign == "lefttop")
uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_TOP |DT_LEFT | DT_END_ELLIPSIS;
else if(m_cszAlign == "center")
uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER |DT_CENTER | DT_END_ELLIPSIS;
else if(m_cszAlign == "wordbreak")
uFormat = DT_NOPREFIX | DT_VCENTER |DT_CENTER | DT_WORDBREAK;
memDC.DrawText(m_cszStatus, &rect, uFormat);
memDC.SelectObject(def_font);
BOOL bRet = font.DeleteObject();
}
CStaticDisplay::OnPaint()
{
CPaintDC dc(this);
Draw();
}
|
|
|
|
|
I am trying to create an owner draw List Box in a dialog so I can have the option of displaying lines in bold font. I am using the OnDrawItem but this function does not get called by the framework. Why is this so?
|
|
|
|
|
In addition, when I select Owner Draw (fixed) and Has Strings for the control properties, I cannot even bring up the dialog. I get the error: The exception Breakpoint: A breakpoint has been reached. (0x800000003) occured in the application at location... etc.
|
|
|
|
|
Use the "DrawItem" not the OnDrawItem
and you can use the "MeasureItem" to set the height of the items
|
|
|
|
|
Hi.
I have read an MS Project XML file and would now like to create a nice view of the tasks. I really don’t know how to start.
Anyone know if there is any MS Project-like view that I could start from?
The View I would create should look like (see URL):
http://www.ceco.se/bilder/Task.jpg
All tips are helpful!
_____________________________
...and justice for all
APe
|
|
|
|
|
Binding a multicast socket to a specific network adapter on w2k boxes with two (or more) network adapters with tcp protocol installed does not work properly. The in/outbound multicast traffic is sometimes going to the wrong adapter. The only way to get this working is to disable the other adapter, send at least one multicast packet through the specified card and then enable the other adapter again. After reboot the same problem appears again. I think that's a Windows bug but I haven't found any prove for that.
Any help would be more than appreciated.
|
|
|
|
|
I have text file with several lines.
I want to read this file using CFile object line by line i.e. read one line and copy it to CString object, read next line and copy to CString object....
How to do this?
Thanks & Regards,
Neeraj
|
|
|
|
|
Neeranjan wrote:
How to do this?
Use CStdioFile instead.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Do you need to use CFile ? Can't you use CStdioFile instead (it derives from CFile) ?
With CStdioFile, you can read a text file line by line.
|
|
|
|
|
Due to the fact that CFile does not have a read line implementation you will need to read one character at a time from the stream and look for '\r' once you find that character you have found the end of the line.
Remember on Windows a Line is delimited by \r\n
so after you find a \r you need to skip the next character in the buffer.
Something like this
CFile x;
//Load your File for processing
CString y;
char temp[1];
ZeroMemory(temp, sizeof(temp));
for(int i = 0; i < x.GetLength(); i++);
{
x.Read(temp, 1);
if (x != '\r')
y += temp;
else
{
x.Read(temp, 1); //Skip the next character it should be \n;
//Do something with your new line
}
}
Forever Developing
|
|
|
|