|
Sorry, but if I have to download something I'm not sure other developers in my company have installed, it's useless. I can't bring up a solution that can only be compiled on my computer.
Thanks anyway, I'll try if I can make sense of the Multimedia Timers cje mentioned
Martin
|
|
|
|
|
m.dietz wrote: I'm new to programming under Windows
The Windows Platform SDK is a standard part of the operating system and any development environment. You should not be developing without it. You might want to do some reading about things life safe strings etc.
led mike
|
|
|
|
|
could you use using multi-media timers? There are articles here on code project that talk about them. I use a class that wraps the multimedia timer that I inherit from (MMTimer) that allows me to get an Update callback when the timer fires.
cje
|
|
|
|
|
Hello!
I've implemented a singleton class and i discovered that in every .dll that i accessed a instance of the singleton a new instance is created. So, in every dll i have a different instance. My question is :How can I have a single instance of the singleton between multiple dll ?
This is my implementation:
class cSingleton
{
private:
static cSingleton* m_instance;
cSingleton(){};
~cSingleton(){};
public:
static cSingleton& Instance();
};
cSingleton& cSingleton::Instance()
{
if(m_instance == NULL)
{
m_instance = new cSingleton;
}
return *m_instance;
};
Thanks!
-- modified at 3:33 Thursday 17th August, 2006
|
|
|
|
|
Hi people
How can I get the IP of a machine in my workgroup?
I get a list of connected PCs in the workgroup using NetServerEnum, so I have the computer Name
Thanks in advance
|
|
|
|
|
Kharfax wrote: How can I get the IP of a machine in my workgroup?
Use gethostbyname() .
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Fantastic, thanks a lot David, that was a quick answer
|
|
|
|
|
void GetLocalIPAddress(char *ipAddress)
{
#define MAX_NAME_LEN 65
WSADATA wsaData;
if ( WSAStartup( MAKEWORD( 2, 2 ), &wsaData ) == 0 )
{
char HostName[MAX_NAME_LEN];
struct in_addr *ptr;
gethostname (HostName,MAX_NAME_LEN);
hostent *host = gethostbyname(HostName);
if(host == NULL)
{
ipAddress = NULL ;
WSACleanup( );
return ;
}
ptr = (struct in_addr *)host->h_addr_list[0];
CString str;
str.Format("%d.%d.%d.%d",
ptr->S_un.S_un_b.s_b1,
ptr->S_un.S_un_b.s_b2,
ptr->S_un.S_un_b.s_b3,
ptr->S_un.S_un_b.s_b4);
strcpy(ipAddress,(char*)str.GetString());
}
WSACleanup( );
}
|
|
|
|
|
Hey thanks a lot for the code
Anyway once David told me about gethostbyname the rest was easy.
But what I noticed is that I forgot to call WSACleanup(), now thanks to you I know I should call it
|
|
|
|
|
I have a CListCtrl embedded in a CView object which covers
the client area completely.
I am running the list control in report mode with several columns.
I want one column to follow the size of the listcontrol (view),
but I am running into some problems.
I cannot ask the list view for its client rect in the
OnInitialUpdate function because that always returns an
rectangle that is not correct yet. I don't know at what stage the client rect
will become valid so it is difficult to determine where
to put my column sizing code.
Any tips on how/when I can get the width of the window to
size my column?
Thanks
|
|
|
|
|
You can use the SetColumnWidth() member function, in addition to the LVSCW_AUTOSIZE / LVSCW_AUTOSIZE_USEHEADER parameter to resize your columns.
I tend to override the WM_SIZE message (OnSize() handler function), then call this function.
Now if you want to over the entire client area, you are on the right track when you said that you obtained the client rect. But not in the OnInitialUpdate() function, do this either after populating your control, or in the size handler.
I Dream of Absolute Zero
|
|
|
|
|
You could derive a class from CListCtrl and then you could add some code in OnSize() that adjusts the column width. This seems the best way to me - plus it is very reusable.
A cynic is a man who, when he smells flowers, looks around for a coffin. -H.L. Mencken
|
|
|
|
|
Do you use SetColumnWidth or Do you have a derived class from ListCtrl
|
|
|
|
|
Hi all,
As long as the OnSize handler gets called, the sizing works fine.
But when I reopen a new document in a SDI application, the OnSize
handler seems not to get called. Where do I have to place my sizing
routine which calls SetColumnWidth(...) ??
tia
|
|
|
|
|
Hi all,
Please help me out of this problem.
I have 3 classes which all require each other.
The problem is that they fail to recognize each other on compilation and give errors as: Undefined class Two, Undefined class Three and Undefined class One
Someone suggested me forward declaration. But that too did not help.
Where am i going wrong ? Please help me.
Here is my code.. (Actually i am having the same problem with an VC++ program. This is just to simulate the same problem)
File1.h
class One
{
private:
int one;
public:
int GetOne();
Two tw;
Three th;
};
File2.h
class Two
{
private:
int two;
public:
int GetTheTwo();
One on;
Three th;
};
File3.h
class Three
{
private:
int three;
public:
int GetAslThree();
One on;
Two tw;
};
File1.cpp
#ifndef _FILE1_H
#define _FILE1_H
#include "File1.h"
#endif
int One::GetOne()
{
return one;
}
File2.cpp
#ifndef _FILE2_H
#define _FILE2_H
#include "File2.h"
#endif
int Two::GetTheTwo()
{
return this->two;
}
File3.cpp
#ifndef _FILE3_H
#define _FILE3_H
#include "File3.h"
#endif
int Three::GetAslThree()
{
return this->three;
}
Thanks in advance.
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
Forward declaration can only be used for pointer types because the concrete definitions of the types have not been known yet in the compilation scope.
class One;
class Two;
class Three{
private:
int three;
public:
int GetAslThree();
One* pon;
Two* ptw;
};
Maxwell Chen
|
|
|
|
|
Hi Maxwell,
Thanks a lot for the quick reply.
That really helped me.
But i have a situation where i do need to declare an object rather than a pointer, is there any possible way for it?
Is it possible that i declare the pointer inside the class, and in the constructor of the class, i allocate memory for it. I am not able to make that work. Is there any other way for it.
Thanks in advance !!
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
What Maxwell said is correct, so you can put
class Class1;
class Class2;
at the top of Class3, and include the headers in the CPP, so long as Class3 returns, accepts and stores only pointers to Class1 and Class2. Then the compiler only needs to know that Class1 and Class2 exist, and that it needs to allocate storage for a pointer.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi Maxwell/Christian,
Thanks a lot guys for the quick reply.
That really helped me.
If i have a situation where i do need to declare an object rather than a pointer, then is there any possible way for it.
Is it possible that i declare the pointer inside the class, and in the constructor of the class, i allocate memory for it. Will, that work. Or is there any other way for it.
Since i am having different header files and CPP files, is it possible to include the files in such a way so that the declaration of a class appears before where it is required. But i guess, thats not possible with three classes.
Thanks a lot friends..!!!
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
The only other option, as someone suggested, is a redesign. Think about what makes these classes interdependent. Can you create a class which acts as a proxy between the two ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks Christian !!
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
You really should rethink your design here. Having classes that are inter-dependent is not easy to write, and become impossible to maintain. There are tons of options you can take for making this code cleaner, but I will only provide one here:
class Two;
class Three;
class One
{
private:
int _One;
public:
std::tr1::shared_ptr<Two*> _Two;
std::tr1::shared_ptr<Three*> _Three;
One() : _Two(new Two), _Three(new Three)
{
}
};
class Two
{
private:
int _Two;
public:
std::tr1::shared_ptr<One*> _One;
std::tr1::shared_ptr<Three*> _Three;
Two() : _One(new One), _Three(new Three)
{
}
};
class Three
{
private:
int _Three;
public:
std::tr1::shared_ptr<One*> _One;
std::tr1::shared_ptr<Two*> _Two;
Three() : _One(new One), _Two(new Two)
{
}
};
The best solution, however, would be to redesign these classes such that they are not inter-dependent.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
I'm not sure if this will work.
I think that this will surely blow your memory into oblivion.
When you create an One object it will create a Two and a Three object.
Those will create 2 One objects a Three and a Two object. These four objects will
create on there turn 3 Two, 3 Three and 2 One objects and so further and so on ...
Its like you said very dangerous to desing an inter-dependen class relation !!!
codito ergo sum
|
|
|
|
|
Thanks BadKarma... but that will make it quite complicated.
Thanks anyway.
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
BadKarma wrote: I think that this will surely blow your memory into oblivion.
He is going to have that problem anyway, it will just be on the stack instead of the heap (if he was actually able to do what he wanted to do, that is).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|