|
option 1 (plain C ):
make the variable global (or having scope-file, declaring it static ).
option 2 (C++ ):
if both functions are actually methods of a class, they can access class data members...
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]
|
|
|
|
|
Thanks for the reply. I can access the pointer Variable in side the second function(methods of the same class). But I want to access the contents of this pointer.
Consider the following code:
dtCore::RefPtr<dtCore::Object> m_Obj = new Object("Car");
m_Obj->LoadFile("demoMap/StaticMeshes/Pajero.IVE\0");
This is inside the first function. Here I've initialized the m_Obj variable to something. When I access this variable inside the second function it contains NULL value why because I've initialized it in the Constructor to NULL since it's a base member. But I 've to access what I've initalize in the first function from the second function not the one in the Constructor. How to do?
|
|
|
|
|
Probably I didn't get you. Anyway the following simple snippet possibly may help.
class A
{
int * _p;
public:
A(){ _p = NULL;}
void fun1() { _p = new int; *_p = 10; }
void fun2()
{
if (_p)
printf("%d\n", *_p);
else
printf("_p is not initialized\n");
}
~A(){if (_p) delete _p;}
};
void main()
{
A a;
a.fun2();
a.fun1();
a.fun2();
}
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]
|
|
|
|
|
why don't you use a member variable within a class. This way you can use it across the class
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi,
What is the difference b/w strlen(NULL) and strlen(""). strlen("") return 0 whereas strlen(NULL) crashes my program leading memory leak.Could any one explain me please?
Thanks in advance.
|
|
|
|
|
"" returns a valid const char pointer to an empty string while NULL is a invalid pointer.
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]
|
|
|
|
|
and why TF whould you do such a thing like strlen(NULL) ?
if you had looked at the doc before asking, you would see that strlen() gets a const char* parameter. obviously, it has to be valid (that means, it has to point to a valid string). NULL is not a valid pointer, hence the crash.
on the other hand, "" is a valid string (even though empty, but valid), so strlen("") returns the number of character in that empty string : 0 characters.
|
|
|
|
|
Hi all,
I want to make option buttons in my tree control...
How can i do this??
thanks in advance
|
|
|
|
|
hi how to create and run a webserver in VC++(MFC)
|
|
|
|
|
You just posted this same inane query 4 hours back. At first, you post a query that is not in compliance with the guidelines[^], and you can't wait for a day before re-posting it?
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
There's a link to one on the front page you clown.
A C++ Embedded Web Server[^]
And yeah - I did 1 vote both posts from you asking this question today.
|
|
|
|
|
The source code for the Apache HTTP server[^] shows a pretty good example of a web server implementation
Seriously, what are you asking? Do you want to use someone elses
server or develop your own? To do your own you're going to need
to have a firm grasp on the TCP/IP protocol and the HTTP protocol[^].
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi everybody,
i like to center a label into a CDialog.
I calculate the left and right position of the label to set the postition via a SetWindowPos.
left gets the value of the calculation and the right value is (left + WidthOfLabel)
In this case the width of the displayed label should be constant at a width of "WidthOfLabel", right?
But in my application the width of the label grows sometimes of one pixel..
If i resize the dialog at a double size, the label has a bigger width than the initial width
Is there a special treatement behind the SetWindowPos which changes the sizes sometimes to fit to the Dialog automatically ?
Big thanks
|
|
|
|
|
baerten wrote: i like to center a label into a CDialog.
You don't like CenterWindow() , do you?
Regards,
Sandip.
|
|
|
|
|
LOL
ehm Okay ... i think your way seems to be easier
But anyway a strange behavour.
Thanks SandipG
|
|
|
|
|
baerten wrote: Is there a special treatement behind the SetWindowPos which changes the sizes sometimes to fit to the Dialog automatically ?
Not that I know of.
How are you calculating WidthOfLabel?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i have a structure and BYTE array
typedef struct _my_struct
{
DWORD dwValue ;
BYTE yValue1 ;
BYTE yValue2 ;
WORD wValue1 ;
BYTE yValue3 ;
WORD wValue2 ;
BYTE yValue4 ;
}mystruct ;
BYTE Buf[10] = {"ab--c--d"} ;
i need to copy
a to yValue1,
b to yValue2,
-- to wValue1,
c to yValue3,
-- to wValue2,
and d to yValue1.
i tried the following code but its not working
mystruct st ;
memcpy( &st.yValue1 , Buf , 6 ) ;
is any way to do that ?
Thanks & Regards
|
|
|
|
|
nitin3 wrote: mystruct st ;
memcpy( &st.yValue1 , Buf , 6 ) ;
i
do not use this unless you are sure about the alignment of your structure.
If you are not aware of what is alignment read this Pragma packing[^]
Regards,
Sandip.
|
|
|
|
|
nitin3 wrote: is any way to do that ?
Yes, using the recipe
nitin3 wrote: copy
a to yValue1,
b to yValue2,
-- to wValue1,
c to yValue3,
-- to wValue2,
and d to yValue1.
you proposed.
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]
|
|
|
|
|
One problem is that you're copying 6 bytes, but the length of Buf is 8.
|
|
|
|
|
Aside from needing to pack the structure:
#pragma pack(push, 1)
typedef ...;
#pragma pack(pop)
and copying 8 bytes, not 6:
memcpy(..., 8);
you may also need to swap the WORD values after the copy depending on their represenstation in Buf and meaning in mystruct:
memcpy(...);
_swab(&Buf[2], &st.wValue1, 2);
_swab(&Buf[5], &st.wValue2, 2);
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
modified on Monday, September 22, 2008 6:37 PM
|
|
|
|
|
Hello All,
I am hooking into the "Windows Mail" application through 'c' langugage by a COM dll in 'c'.
When the "Windows Mail" application window is activated, the IStoreNamespace object is created and initialised from within the scope of the Windows Mail application. As described in the previous post above, the RegisterNotification method fails with error E_NOTIMP.
Other functionality of the IStoreNamespace seem to work as required.
I have also tried a number of simple test applications using the IStoreNamespace object and they seem to work including the RegisterNotification method.
Also the same code base and hooking process is working on Windows XP and Outlook Express.
Please Help me in this, as I have been trying its solution since long!
Thanks in advance!
dolly,
N,IN
|
|
|
|
|
Hello everyone,
The different assembly code when we call through z and z1 in below sample is,
- we know the type of z, so no need to access vtable to make function call;
- we do not know the exact type for a pointer, so need to access vtable to make function call.
My question is whether my two items' understanding is correct. Thanks.
z.func();
000A1575 lea ecx,[z]
000A1578 call Zoo::func (0A11A4h)
z1->func();
000A157D mov eax,dword ptr [z1]
000A1580 mov edx,dword ptr [eax]
000A1582 mov esi,esp
000A1584 mov ecx,dword ptr [z1]
000A1587 mov eax,dword ptr [edx]
000A1589 call eax
000A158B cmp esi,esp
000A158D call @ILT+440(__RTC_CheckEsp) (0A11BDh)
class Zoo
{
public:
virtual void func() {cout << "Zoo" << endl; }
};
int main()
{
Zoo z;
Zoo* z1 = new Zoo();
z.func();
z1->func();
delete z1;
return 0;
}
thanks in advance,
George
modified on Monday, September 22, 2008 4:49 AM
|
|
|
|
|
Dear all,
I have an application that can identify a window. The method in which I worked out is given below.
I will store the attributes of the window such as( class name, window caption, resource id etc..) to a file.
When the second time , window is up, using the above attributes, I will identify the window.
But, I encounter a problem with the above scenario. The problem comes, when the 'window does not have
window caption', 'window class name is same' and 'control id is zero'..
I can't use window handle, bcz it will differ when the window is up for the second time.
Is there any method to solve this problem? OR Is there any unique attribute to identify the window?
Please help,
Thanks in advance,
George K J
modified on Monday, September 22, 2008 4:22 AM
|
|
|
|
|
IMHO there is a logical pitfall in your requirements: processes and executable files are different things. For instance you may have three different instances of your_application.exe running at the same time, the system allows you to differenziate between these three processes, but such a distinction makes sense only at runtime.
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]
|
|
|
|