|
You need to subclass the dialog so that it can get events.
Sunil
|
|
|
|
|
Compound types, by definition, are types that are derived from other basic types. Right?
In my opinion, pointers, with their unique representation( * and &), must be classificated as a fundamental type.
Am I wrong?
|
|
|
|
|
sawerr wrote: Compound types, by definition
Interestingly, Bjarne Stroustrup does not provide a definition in his glossary of C++[^].
|
|
|
|
|
A pointer is not a type.
Otherwise you would be able to create it this way - * p;
|
|
|
|
|
Since a pointer is a memory address its type if you lie is actually its size, and hence is the same as the bit ness of the OS, 32 or 64, 4 or 8.
However, and this is where it gets interesting, when you increment a pointer the address increases by the size of the declared type. So a char pointer goes up by one byte, a DWORD pointer by 4 and so on.
|
|
|
|
|
Hi,
In my client server application, am sending array of data in ASCII format, while receiving it on other end, i cant able to retrieve whole data using dynamic array.
Instead i used static array and i received the whole data.Can anyone help me to receive the same data using dynamic array.
|
|
|
|
|
without seeing the code that you are using in your receiver it is difficult to guess how to improve it.
|
|
|
|
|
Declare dynamic char buffer:
char* Dynamic_Recieve_Buffer = new char[2000];
Use dynamic buffer:
recv(mySocket , Dynamic_Receive_Buffer , 2000 , 0);
Example code:
#include<stdio.h>
#include<winsock2.h>
#pragma comment(lib,"ws2_32.lib") //Winsock Library
int main(int argc , char *argv[])
{
char* Dynamic_Receive_Buffer = new char[2000];
WSADATA wsa;
SOCKET mySocket;
struct sockaddr_in server;
int recv_size;
char *message;
printf("\nInitialising Winsock...");
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
{
printf("Failed. Error Code : %d",WSAGetLastError());
return 1;
}
printf("Initialised.\n");
if((mySocket = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
{
printf("Could not create socket : %d" , WSAGetLastError());
}
printf("Socket created.\n");
server.sin_addr.s_addr = inet_addr("74.125.235.20");
server.sin_family = AF_INET;
server.sin_port = htons( 80 );
if (connect(mySocket , (struct sockaddr *)&server , sizeof(server)) < 0)
{
puts("connect error");
return 1;
}
puts("Connected");
message = "GET / HTTP/1.1\r\n\r\n";
if( send(mySocket , message , strlen(message) , 0) < 0)
{
puts("Send failed");
return 1;
}
puts("Data Send\n");
if((recv_size = recv(mySocket , Dynamic_Receive_Buffer , 2000 , 0)) == SOCKET_ERROR)
{
puts("recv failed");
}
puts("Reply received\n");
Dynamic_Receive_Buffer[recv_size] = '\0';
puts(Dynamic_Receive_Buffer);
return 0;
}
|
|
|
|
|
Can I find size of datatype without using sizeof operator ????
|
|
|
|
|
Not that I am aware of. What problem are you trying to solve?
|
|
|
|
|
How about this:
#define NO_SIZEOF_SIZEOF(type) ((long)(((type *)0) + 1))
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Thanks, didn't think of that.
|
|
|
|
|
Even "youngsters" can have a few tricks up their sleeves.
I also wonder why the OP would need such a thing...maybe he's working with some stripped-down version of C for some egzotic platform that doesn't have sizeof...or it's a school-assignment-type question...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Psst!
It's spelled "exotic."
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
what a perfect way!
|
|
|
|
|
Thanks
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
sizeof operator is the right way. I cannot see the reason for avoiding it.
Veni, vidi, vici.
|
|
|
|
|
He thinks he can make the wheel rounder...
|
|
|
|
|
Hi,
I have a loop for which I am tryig to connect on four ports for which I only get two
connections I know sometimes sockets take a while to connect
the Creation of the Socket and connection take place in CWinThread Dervived ::Initinstance after the CAsyncSocket objects have been created
Server is a Dos "C" program on the same Windows Vista machine
below is the loop
I am connected thru a router that is kind of old don't know if thats the issue
or If an imporvment in my hardware might help
I put my derived CAsynSocket class inside a a CWinThread class hoping that if such
issues arise I might raise the priority of the thread
looking for any pointers from the experts out there
// loop in CWinApp::Initinstance
for (i = 0, start_port = 11007; i < 4; start_port++, i++)
{
threadptr[i] = new SockCLeintThread(start_port);
if (threadptr[i] == NULL)
m_pMainWnd->MessageBox("SockClientThreadFail",NULL,MB_ICONERROR);
threadptr[i]->CreateThread(CREATE_SUSPENDED,0,NULL);
threadptr[i]->flags.is_connected = 0;
threadptr[i]->ipaddr = "192.168.1.4";
SetThreadName(threadptr[i]->m_nThreadID,thread[i]);
threadptr[i]->ResumeThread();
}
// My Casynsocket .h file
lass SockClient : public CAsyncSocket
{
DECLARE_SERIAL(SockClient)
public:
SockClient(UINT myport);
SockClient();
~SockClient();
char *sockbuffer; int num_buff;
CWnd *send_wnd;
int thread_no;
UINT port;
private:
int busy; protected:
virtual void OnReceive(int nErrorCode);
virtual void OnSend(int nErrorCode);
virtual void OnConnect(int nErrorCode);
virtual void OnClose(int nErrorCode);
}
IMPLEMENT_SERIAL(SockClient,CAsyncSocket,VERSIONABLE_SCHEMA | 2)
SockClient::SockClient()
{
sockbuffer = new char[300];
}
SockClient::SockClient(UINT myport)
{
port = myport;
sockbuffer = new char[300];
}
SockClient::~SockClient()
{
}
void SockClient :: OnConnect(int nErrorcode)
{
if(nErrorcode == 0)
Sockevent.SetEvent();
UNREFERENCED_PARAMETER(nErrorcode);
CAsyncSocket::OnConnect(nErrorcode);
busy = 1;
AsyncSelect(FD_WRITE);
}
void SockClient::OnClose(int nErrorCode) {
SockCLeintThread* current = dynamic_cast<SockCLeintThread*>(current);
current = (SockCLeintThread*)AfxGetThread();
current->flags.is_connected = 0;
CAsyncSocket::OnClose(nErrorCode);
}
void SockClient :: OnSend(int nErrorcode)
{
int bytes_sent;
if (num_buff > 0)
{
bytes_sent = Send(sockbuffer,num_buff,0);
num_buff = num_buff - bytes_sent;
CAsyncSocket::OnSend(nErrorcode);
AsyncSelect(FD_READ);
}
}
void SockClient::OnReceive(int nErrorcode)
{
static int i=0;
i++;
int nRead;
nRead = Receive(sockbuffer, 4096);
switch (nRead)
{
case 0:
Close();
break;
case SOCKET_ERROR:
if (GetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox ("Error occurred");
Close();
}
break;
default:
num_buff = nRead;
}
CAsyncSocket::OnReceive(nErrorcode);
send_wnd->SendMessage(WM_RECEIVE_SOCK_MESS,0,(LPARAM)sockbuffer);
}
class SockCLeintThread : public CWinThread {
public:
DECLARE_DYNCREATE(SockCLeintThread)
public:
SockCLeintThread(UINT myport);
SockCLeintThread();
~SockCLeintThread();
CWnd *sendwindow;
CWnd *call_wnd;
char *thread_id;
SockClient thisocket;
void Sendit(WPARAM, LPARAM);
void Receiveit(WPARAM, LPARAM);
LPCTSTR ipaddr;
BOOL idle; allexceptions myallexception;
struct {
unsigned int is_connected : 1;
unsigned int busy : 1;
} flags;
protected:
virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(SockCLeintThread,CWinThread)
BEGIN_MESSAGE_MAP(SockCLeintThread, CWinThread)
ON_THREAD_MESSAGE(WM_SEND_SOCK_MESS,Sendit)
END_MESSAGE_MAP()
void SockCLeintThread::Sendit(WPARAM count, LPARAM command)
{
UNREFERENCED_PARAMETER(command);
thisocket.num_buff = count;
thisocket.AsyncSelect(FD_WRITE);
return;
}
void SockCLeintThread::Receiveit(WPARAM count, LPARAM command)
{
UNREFERENCED_PARAMETER(count);
UNREFERENCED_PARAMETER(command);
thisocket.num_buff = 0;
}
SockCLeintThread::SockCLeintThread()
{
m_bAutoDelete = FALSE;
}
SockCLeintThread::SockCLeintThread(UINT myport) : thisocket(myport)
{
m_bAutoDelete = FALSE;
}
SockCLeintThread::~SockCLeintThread()
{
}
BOOL SockCLeintThread::InitInstance()
{
int error_code;
MSG m_msgCur;
extern void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName);
socklock.Lock();
if(thisocket.Create(thisocket.port,SOCK_STREAM,NULL)== 0)
{
error_code = GetLastError();
}
if (thisocket.AsyncSelect(FD_READ|FD_WRITE|FD_CONNECT|FD_CLOSE|FD_OOB|FD_ACCEPT) == 0)
error_code = GetLastError();
if( thisocket.Connect(ipaddr,thisocket.port) == 0)
{
error_code = GetLastError();
}
else
flags.is_connected = 1;
socklock.Unlock();
PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE);
return TRUE; }
|
|
|
|
|
Not sure what you're asking, this looks like a bit of a code dump. Typically connections won't take very long if you're within the same LAN, so you may have another issue with your code. By the way, if you're using an asynchronous socket, the connection is also asynchronous, meaning you don't sit there and wait for a response, the callback will be called when it's either connected or timed out.
ForNow wrote: PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE);
You don't have to manually create a message queue for a CWinThread.
|
|
|
|
|
You are right the CAsynSocket::OnConnect should be called by the framework one way or another at the very least with a WSAETIMEDOUT nErrorCode
I should put a TRACE in to printf the nerrorcode
|
|
|
|
|
Could you post some code?
|
|
|
|
|
I am recieving a buffer which is having unicode and ansi character. How can I read it so that I can get the actual string.
|
|
|
|
|
Please be a little bit more specific (e.g. by providing an example). Do you have a buffer that may contain an ANSI or Unicode (Microsoft wide character UTF16-LE, UTF16-BE, or UTF-8) string and you want to detect the encoding? If so, do you know the length of the buffer?
|
|
|
|
|
Yes you are right and I know the lenght of buffer.
|
|
|
|
|