|
hi friend
if you declare it as the follwing:
int x;
<br />
class A{<br />
...<br />
};
try to write the following in class B.cpp:
//B.CPP
extern int x;
<br />
class B{<br />
...<br />
}
I hope this works
|
|
|
|
|
Dear Friend,
I think you cannot access a global variable outside its class directly.
Suppose your variable is declared in class 'A'.
To access it in class 'B', you should create an object of class 'A' in class 'B'. Now you can access the variable using this object.
|
|
|
|
|
For functions that you want to use globally, put their declaration in a header file and include the header file wherever you want to use the function.
For variables, you have to declare it outside the scope of a class in one file. In all other files, you have to declare it as extern. For eg.
File1.cpp
int x;
class SomeClass {...};
File2.cpp
extern int x;
// Your code here.
The extern keyword tells the compiler that the variable is defined in some other file. In fact, if you forget to define it in File1.cpp, you'll get a linker error, not a compiler error.
Regards
Senthil
|
|
|
|
|
|
|
You are right, _bstr_t instead of CComBstr helped in throwing exception, now each of put_* methods works fine, thx.
But href has still wrong value ;-(. Perhaps there are another way to set default document ;-(
Luda
|
|
|
|
|
|
Hi.
I'm developing a program that instantiates a COM executable.
In my machine the problem doesn't occur, but in the machine of a colleague we have this problem. The source code are the same, without any modification. We are using Visual C++ 6.0 SP5, Win2K and WinXP.
The code below are the code that works in one machine and in another doesn't work.
HRESULT hr;
IUnknown * pXXXXX;
IConnectionPointContainer * pCPC;
IConnectionPoint * pCPIXXXXXEvents;
<br>
pXXXXX = NULL;
pCPIXXXXXEvents = NULL;
pCPC = NULL;
m_pIXXXXXEvents = new CIXXXXXEvents(this);
m_bComError = TRUE;
<br>
hr = CoCreateInstance(CLSID_XXXXX, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (LPVOID*)&pXXXXX);
if (FAILED(hr))
{
pXXXXX = NULL;
OutputDebugString("Failed to create XXXXX COM object");
}
<br>
hr = pXXXXX->QueryInterface(IID_IXXXXX, (LPVOID*)&m_pIXXXXX);
if (FAILED(hr))
{
m_pIXXXXX = NULL;
OutputDebugString("Couldn't QueryInterface for m_pIXXXXX");
}
<br>
hr = pXXXXX->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pCPC);
if(FAILED(hr))
{
OutputDebugString("Couldn't QueryInterface for pCPC");
}
<br>
hr = pCPC->FindConnectionPoint(__uuidof(_IXXXXXEvents), &pCPIXXXXXEvents);
if(FAILED(hr))
{
OutputDebugString("Couldn't FindConnectionPoint for pCPIXXXXXEvents");
}
<br>
hr = pCPIXXXXXEvents->Advise(m_pIXXXXXEvents, &ulAdviseSFN);
if(FAILED(hr))
{
:((
OutputDebugString("Couldn't Advise for m_pIXXXXXEvents");
}
Anyone has any idea of what is happening and a suggestion of how to solve it?
Thanks
Dennis
|
|
|
|
|
Hi
I wrote a small program to count how many points are clicked using array. My count array doesnt work even though i wrote the declaration before or in the function itself.
For example:
int count=0;<br />
if((nFlags & MK_LBUTTON) == MK_LBUTTON){<br />
count++<br />
}
and
if((nFlags & MK_LBUTTON) == MK_LBUTTON){<br />
int count;<br />
count++;<br />
}
From what I can see is everytime a left mouse is clicked the array reset itself. The code is inside a OnMouseMove(UINT nFlags CPoint point) class.
Thanks
|
|
|
|
|
jw81 wrote:
int count=0;
if((nFlags & MK_LBUTTON) == MK_LBUTTON){
count++
actaully problem is of Scope of variable count .it is local variable in function.
let see what actually happening in your code-> Every time you click on mouse the count variable created in memory and as function ends, count variable scope end and program release it from memory.
now to solve this problem with either declare it in global or make it local to class which handlling you onmousemove function rather declarign it in function.
"I Think this Will Help"
[Vote One Here,.....]
<h5
alok gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|
ThatsAlok wrote:
now to solve this problem with either declare it in global or make it local to class which handlling you onmousemove function rather declarign it in function
Or ... let it where it is now, but declare it as static .
By the "lifetime" point of view, global or static is mostly the same.
Declare it as class member will let every calss instance hace its own.
That is: if yor class is used to handle many windows and you want each one to have its own counter, make it a class member.
If you want a same single counter to count everything in all instances, declare it as static . In the function if only that function use it; In the class if many function class use it; globally if you have to access it from everywhere.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
emilio_grv wrote:
: if yor class is used to handle many windows and you want each one to have its own counter, make it a class member.
i think, it just a beginner problem,so i have given beginner answer.
conecpt of static is little complicated for beginner.
"I Think this Will Help"
[Vote One Here,.....]
<h5
alok="" gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|
I guess Alok answered my question, thanks.
|
|
|
|
|
Hello,
I don't understand your problem exactly, but if this declaration is inside a funktion, well you declare a variable and reset it to zero, then ++ it.
could you please try using 'static int ... ' instead of your currnt statement? does it solve any problem?
|
|
|
|
|
I think you need to declare the count variable outside this function, eg. declare it as global or class member variable. If you declare in this function, every time you click the mouse, the counter is reset to zero.
|
|
|
|
|
how to write into the serial/parallel/USB port
using VC++6?
thx
|
|
|
|
|
|
up.
Before the main frame is created I want to display splashwindow for 3 seconds. how to do it?
|
|
|
|
|
Add A Splash window Control in your project.
you can find Splash window Control here ->
Project->add to Project->Component and Controls
Select Directory ->Visual C++ Components
and scroll to SplashWnd and insert it into your project.
"I Think this Will Help"
[Vote One Here,.....]
<h5
alok gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|
hi!!
You can just create a dialog window... and use "BitBlt" to display any bitmap... add a timer control..and after the timer expires... start the app.. hope you fing this useful - V.G
|
|
|
|
|
But I can't use Timer in PreCreateWindof function.
|
|
|
|
|
you use it during the creation of the Frame window...just make it invisible... after the time expires, make it visible..ok? -V.G
|
|
|
|
|
I think about this:
<br />
BOOL CRightHTMLView::PreCreateWindow(CREATESTRUCT& cs)<br />
{<br />
MSG message;<br />
<br />
int i=0;<br />
m_nTimer = SetTimer(1, 100, NULL);
ASSERT(m_nTimer!=0);<br />
if(i==0)<br />
{<br />
dlg->DoModal();
if(::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {<br />
::TranslateMessage(&message);<br />
::DispatchMessage(&message);<br />
}<br />
i = 1;<br />
}<br />
Then
<br />
void CRightHTMLView::OnTimer(UINT nIDEvent)<br />
{<br />
Sleep(3000);<br />
dlg->DestroyWindow();<br />
KillTimer(1);<br />
<br />
CHtmlView::OnTimer(nIDEvent);<br />
}
Did you mean the same?
|
|
|
|
|
Thank you! I did it
|
|
|
|
|
can I use serialize to store and reterive non array data for example lets say that I have a class that has some array variables that I can use serialize to store them, but what if I want to also store some unique variables to the same file after all array data has been stored, is there a way or can I append data to that file ?
thanks in advance
|
|
|
|