ATL / WTL / STL
|Here is the thing: In C/C++ every pointer is automatically casted into
(const void*) and every non-const pointer is automatically casted into
(void*). The msdn web page used cast just because of the pointer arithmetic involved, as you see they add an integer value to the start of the buffer:
(LPCTSTR)m_sendBuffer + m_nBytesSent. They cast the buffer pointer into
LPCTSTR because they want the addition to step the pointer with *byte* granularity. The problem with this is that
LPCTSTR can translate not only to
(const char*) but also into
(const wchar_t*) (when the project character set is unicode, and note that
wchar_t is a type whose size is 2 bytes!) so I guess MS guys made a mistake here and
(LPCTSTR) is a bug (if the project character setting is set the unicode), they should have used
(char*) or its equivalent in winodws:
const char* or
LPCSTR or something like that, something that is a *byte* pointer. Your problem is that you try to convert an instance of your struct into a pointer. You can not convert an instance into a pointer! You can converty only a pointer into a different type of pointer and in rare cases conversion might be needed between pointer and integral types.
GetSystemTime( &m_current_time );
int t1 = sizeof( m_current_time );
int chars_sent = m_C_Server_Send_Time_Socket->Send( (LPCTSTR) m_current_time, t1, 0 );
int chars_sent = m_C_Server_Send_Time_Socket->Send( (LPCTSTR) &m_current_time, t1, 0 );
int chars_sent = m_C_Server_Send_Time_Socket->Send( &m_current_time, t1, 0 );
Note that using
(LPCTSTR) is a bug even on microsoft's side! You need to convert your struct pointer into a
(char*) only if you want to step your pointer with byte precision!
SYSTEMTIME* p = &m_current_time + 1;
SYSTEMTIME* p = &(&m_current_time);
char* p = (char*)&m_current_time + 1;
void* p = (char*)&m_current_time + 1;
const void* p = (char*)&m_current_time + 1;
Note that an addition or a substraction on a pointer always steps the pointer with the size of the type the pointer points to (like when you indexing into an array of the specified type). For this reason you can not step void pointers without casting them into something else - the size of void isn't defined.
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.