|
I made a couple of small changes, and now it works.
TCHAR* IPAddress()
{
WSADATA wsa;
WSAStartup(MAKEWORD(1, 0), &wsa);
char szBuffer[250];
TCHAR *lpIPAddr = new TCHAR[18];
memset(lpIPAddr, '\0', 18 * sizeof(TCHAR));
if(gethostname(szBuffer, 250) != 0)
return 0;
struct hostent * host = gethostbyname(szBuffer);
_stprintf(lpIPAddr, "IP Locale: %d.%d.%d.%d\n",
(BYTE)host->h_addr_list[0][0],
(BYTE)host->h_addr_list[0][1],
(BYTE)host->h_addr_list[0][2],
(BYTE)host->h_addr_list[0][3]);
return lpIPAddr;
}
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Anders... Thanks, thanks, thanks!!!
|
|
|
|
|
Fine, but remember to close WSA and deallocate memory allocated with operator new ( TCHAR *lpIPAddr = new TCHAR[18]; ). You should first initialize WSA, then create buffer, and lastly send it to the IPAdress function as an argument.
|
|
|
|
|
do you know any free sw to what when i give by me created xml file will say it is good/wrong formated one?
i afraid when i will use any-firma parser it can bring problem
(search at www.xml.org asks me i want to debug y/n)
t!
|
|
|
|
|
The sample programs of Xerces XML parser can be used as XML validators. It's available from xml.apache.org.
|
|
|
|
|
Hi everybody.
I have the following question. Is it possible to get behavour like this from templates.
template < typename T >
class TType
{
public:
CString GetAsString( )
{
CString sValue;
sValue.Format( GetFormat<t>( ), m_tValue );
return sValue;
}
protected:
T m_tValue;
};
Define some function that depended of the type will return different string for formating.
template < class int >
CString GetFormat( )
{
return "%d";
}
template < class float >
CString GetFormat( )
{
return "%.4f";
}
and then when this is used
TType< int > a; // will use template function for int
TType< float > a; // will use template function for float
|
|
|
|
|
It is invalid C++. Your idea written correctly looks like this:
template <typename t="">
class TType
{
public:
CString GetAsString()
{
CString sValue;
sValue.Format(GetFormat<t>(), m_tValue);
return sValue;
}
protected:
T m_tValue;
};
template <class t=""> CString GetFormat();
template <> CString GetFormat<int>() { return "%d"; }
template <> CString GetFormat<float>() { return "%.4f"; }
Unfortunately, this doesn't work on VC++ 6.0 (GetFormat<int> is called even for float's).
Try this:
template <typename t="">
class TType
{
public:
TType(const T& value)
: m_tValue(value)
{
}
CString GetAsString()
{
CString sValue;
sValue.Format(TypeHelper<t>::GetFormat(), m_tValue);
return sValue;
}
protected:
T m_tValue;
};
template <class t=""> class TypeHelper;
template <> class TypeHelper<int>
{
public:
static CString GetFormat() { return "%d"; }
};
template <> class TypeHelper<float>
{
public:
static CString GetFormat() { return "%.4f"; }
};
--
Martin
|
|
|
|
|
Are you sure that this will work ?
|
|
|
|
|
Hm, it seems that discussion boards software stripped some chars from my post. For example, in template specialization definition:
template <> class TypeHelper<int>
, it stripped "<int>" after class name.
Please send me request email, and I will send you correct version of my post.
Regards
--
Martin
|
|
|
|
|
I found out why some chars was stripped from my message and how to send it correctly. So, here it is, again:
It is invalid C++. Your idea written correctly looks like this:
template
class TType
{
public:
CString GetAsString()
{
CString sValue;
sValue.Format(GetFormat(), m_tValue);
return sValue;
}
protected:
T m_tValue;
};
template <class T> CString GetFormat();
template <> CString GetFormat<int>() { return "%d"; }
template <> CString GetFormat<float>() { return "%.4f"; }
Unfortunately, this doesn't work on VC++ 6.0 (GetFormat<int> is called even for float's).
Try this:
template <class T>
class TType
{
public:
TType(const T& value)
: m_tValue(value)
{
}
CString GetAsString()
{
CString sValue;
sValue.Format(TypeHelper::GetFormat(), m_tValue);
return sValue;
}
protected:
T m_tValue;
};
template <class T> class TypeHelper;
template <> class TypeHelper<int>
{
public:
static CString GetFormat() { return "%d"; }
};
template <> class TypeHelper<float>
{
public:
static CString GetFormat() { return "%.4f"; }
};
--
Martin
|
|
|
|
|
You need to create a GetFormat function template and specializations for different types. VC++ seems to have problems with some forms of specializations. I was able to make the following code work:
CString GetAsString()
{
CString sValue;
sValue.Format( GetFormat(m_tValue), m_tValue );
return sValue;
}
template < class T >
CString GetFormat(const T& unused)
{
return CString();
}
template < >
CString GetFormat(const float & unused)
{
return "%.4e";
}
template < >
CString GetFormat(const int & unused)
{
return "%d";
}
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Does anybody know a possibility to display graphical primitives as Rectangles,
that are saved in the RichTextFormat File through th CRichEdit Control or any
other control
eiselekd
|
|
|
|
|
when i try to use CRecordSet functions such as SetAbsolutePosition and MoveNext etc, i get an error. When i debug, it complaints about the IsOpen function, that if m_hstmt is NULL, it returns FALSE. I can use the CRecordSet functions to a certain point, after that this error message keeps coming up.
Seems like my CRecordSet pointer looses it's position or something.
I'm using Visual Studio 6.0, and i'm trying to get information from an access database.
Kristian
|
|
|
|
|
Hmmm. sounds tricky;P
...::: knowledge is king :::...
|
|
|
|
|
I have a CEdit derived class. I wanted to override the OnChar messages and PreTranslateMessage. However, when I add these I get "member function not declared in CDerivedEdit" errors. I have checked that the correct entry is in the header file and the mapping macro in the implementation file. Am I doing something else wrong or is something weird somewhere?!
thanks in advance
|
|
|
|
|
I've been trying to close another application from within my application I've used EnumWindows to obtain the handle of the other application. The problem is If The Other Application Remains Active WM_CLOSE message works fine but if it is not active there goes the problem I'm unable to activate it and the Other Application remains without closing . Does anyone knows how to come over this?
Thanks in advance
P Vijaya Rama Raju
|
|
|
|
|
Try sending WM_QUIT to the UI Thread.
--------------------------------------------------
If my messages appear curt, I apologize.
I try to be brief to save your time as well as mine.
--------------------------------------------------
|
|
|
|
|
Can you write code ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Have you tried TerminateProcess() ?
Here is a sample:
int KillPid(DWORD pid) {
HANDLE hPid = OpenProcess(0, FALSE, pid);
if (hPid != NULL) {
if (TerminateProcess(hPid, 0) == TRUE) {
CloseHandle(hPid);
return 0;
} else {
CloseHandle(hPid);
return GetLastError();
}
CloseHandle(hPid);
}
return 1;
}<pre>
|
|
|
|
|
Thanks, it is useful example ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Some people say I can, most say I can't
Try:
http://www.codeproject.com/threads/interprocesssync.asp
--------------------------------------------------
If my messages appear curt, I apologize.
I try to be brief to save your time as well as mine.
--------------------------------------------------
|
|
|
|
|
can you point me the difference beetween:
Option m_Option;
m_Option.DoModal();
and:
m_Option = new Option(this);
m_Option->DoModal();
Both work but what is the difference "new" create a new instance ?
but if I "new" something I assume I should delete it somewhere ?
I'm a bit lost here while MFC do so much things automaticly
I don't want to miss something and to get memory leak.
Thanks
|
|
|
|
|
The difference is that m_Option is obviously a member variable to a pointer, Option is just an istance of the dialog. You never call delete on a CWnd, you call DestroyWindow, which ( I believe ) will be called for you in the case of a modal dialog. You should definately set m_Option to NULL after the DoModal though, and also in your constructor, for safety.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
In your option 's ::PostNcDestroy()
add :
delete this;
no memory leak;
|
|
|
|
|
Thanks
|
|
|
|