By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

Trouble creating a thread

P: n/a
Folks,
I am having a problem storing a port number read from a registry and
creating a thread, and I cannot figure out why. Here are the relevant
details:

I have a struct called SOCKET_INFO in a header file called
socketthreadcommon.h

typedef struct{
char szHost[50];
int nPort;
DWORD dwLastError;
BOOL bListening;
BOOL bCalling;
BOOL bConnected;
BOOL bAbort;
BOOL bTestWithoutSocket;
UINT nMsgSentCount;
float fHeadingInStatusMsg;

HANDLE hEventQueueNotEmpty;
MsgQueueSocketType MsgQueue[MSGQUEUEMAX];
UINT MsgQueueFreeIdx;
UINT MsgQueueUsedIdx;
} SOCKET_INFO;
I create an instance of this struct in a file called realerdlg.h

SOCKET_INFO m_ServerSocketInfo;

realerdlg.cpp sets the value of the nPort member

m_ServerSocketInfo.nPort = (int)(dwPort);


and finally, I am attempting to create a socket with the statement:

CWinThread *lpThread = AfxBeginThread(ServerSocketThread, (LPVOID)
&m_ServerSocketInfo);


The dwPort variable is correct and verified. In the
serversocketthread.cpp class, I cannot pick up the
value of nPort. The constructor there is

UINT ServerSocketThread( LPVOID lpInf )
{

SOCKADDR_IN Addr;
int AddrLen;
SOCKET_INFO* lpInfo = (SOCKET_INFO *) lpInf;
int nRetValue = 0;
CSocket ServerSocket;
BOOL bDone = FALSE;
CSocket ClientSocket;
MsgQueueSocketType MsgQueue;
int nBytes;
CRegistry Registry; // Registry object
PROGRAM_TYPE Program;

CTime CurrentTime;

}

This is code I inherited and am trying to debug... Does anyone have
any ideas?

thanks very much,

Zenon
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Zenon wrote:
Folks,
I am having a problem storing a port number read from a registry and
creating a thread <snip> This is code I inherited and am trying to debug... Does anyone have
any ideas?
Standard C++ (the topic of this group) does not support threading, so please
ask in a group dedicated to your platform.
In your case it appears to be Microsoft Windows with MFC, so
microsoft.public.vc.mfc would be a good one.

- Pete

thanks very much,

Zenon


Jul 22 '05 #2

P: n/a
Zenon wrote:
Folks,
I am having a problem storing a port number read from a registry and
creating a thread, and I cannot figure out why. Here are the relevant
details:

I have a struct called SOCKET_INFO in a header file called
socketthreadcommon.h

typedef struct{
char szHost[50];
int nPort;
DWORD dwLastError;
BOOL bListening;
BOOL bCalling;
BOOL bConnected;
BOOL bAbort;
BOOL bTestWithoutSocket;
UINT nMsgSentCount;
float fHeadingInStatusMsg;

HANDLE hEventQueueNotEmpty;
MsgQueueSocketType MsgQueue[MSGQUEUEMAX];
UINT MsgQueueFreeIdx;
UINT MsgQueueUsedIdx;
} SOCKET_INFO;
I create an instance of this struct in a file called realerdlg.h

SOCKET_INFO m_ServerSocketInfo;
Let me guess... It's a data member of some class, isn't it?
realerdlg.cpp sets the value of the nPort member

m_ServerSocketInfo.nPort = (int)(dwPort);


and finally, I am attempting to create a socket with the statement:

CWinThread *lpThread = AfxBeginThread(ServerSocketThread, (LPVOID)
&m_ServerSocketInfo);
'AfcBeginThread' is not a standard C++ function. You would be much better
off asking in a newsgroup where it's on topic, like a Windows programming
newsgroup or an MFC one...


The dwPort variable is correct and verified.
"Correct and verified" where? Before you call 'AfxBeginThread'?
In the
serversocketthread.cpp class, I cannot pick up the
value of nPort. The constructor there is

UINT ServerSocketThread( LPVOID lpInf )
{

SOCKADDR_IN Addr;
int AddrLen;
SOCKET_INFO* lpInfo = (SOCKET_INFO *) lpInf;
int nRetValue = 0;
CSocket ServerSocket;
BOOL bDone = FALSE;
CSocket ClientSocket;
MsgQueueSocketType MsgQueue;
int nBytes;
CRegistry Registry; // Registry object
PROGRAM_TYPE Program;

CTime CurrentTime;

}

This is code I inherited and am trying to debug... Does anyone have
any ideas?


<offtopic>
The simplest idea I have is that your thread does not share the address
space with the rest of the program. When you pass in the pointer value,
it gets the pointer, but it's a pointer in a completely different area of
the process memory.
</offtopic>

Try asking in a Microsoft newsgroup, like comp.os.ms-windows.programmer.*

Victor
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.