Trouble creating a thread

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zenon

    Trouble creating a thread

    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
    socketthreadcom mon.h

    typedef struct{
    char szHost[50];
    int nPort;
    DWORD dwLastError;
    BOOL bListening;
    BOOL bCalling;
    BOOL bConnected;
    BOOL bAbort;
    BOOL bTestWithoutSoc ket;
    UINT nMsgSentCount;
    float fHeadingInStatu sMsg;

    HANDLE hEventQueueNotE mpty;
    MsgQueueSocketT ype MsgQueue[MSGQUEUEMAX];
    UINT MsgQueueFreeIdx ;
    UINT MsgQueueUsedIdx ;
    } SOCKET_INFO;


    I create an instance of this struct in a file called realerdlg.h

    SOCKET_INFO m_ServerSocketI nfo;



    realerdlg.cpp sets the value of the nPort member

    m_ServerSocketI nfo.nPort = (int)(dwPort);




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

    CWinThread *lpThread = AfxBeginThread( ServerSocketThr ead, (LPVOID)
    &m_ServerSocket Info);




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

    UINT ServerSocketThr ead( LPVOID lpInf )
    {

    SOCKADDR_IN Addr;
    int AddrLen;
    SOCKET_INFO* lpInfo = (SOCKET_INFO *) lpInf;
    int nRetValue = 0;
    CSocket ServerSocket;
    BOOL bDone = FALSE;
    CSocket ClientSocket;
    MsgQueueSocketT ype 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
  • Petec

    #2
    Re: Trouble creating a thread

    Zenon wrote:[color=blue]
    > Folks,
    > I am having a problem storing a port number read from a registry and
    > creating a thread[/color]
    <snip>[color=blue]
    > This is code I inherited and am trying to debug... Does anyone have
    > any ideas?[/color]

    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.publi c.vc.mfc would be a good one.

    - Pete
    [color=blue]
    >
    > thanks very much,
    >
    > Zenon[/color]



    Comment

    • Victor Bazarov

      #3
      Re: Trouble creating a thread

      Zenon wrote:[color=blue]
      > 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
      > socketthreadcom mon.h
      >
      > typedef struct{
      > char szHost[50];
      > int nPort;
      > DWORD dwLastError;
      > BOOL bListening;
      > BOOL bCalling;
      > BOOL bConnected;
      > BOOL bAbort;
      > BOOL bTestWithoutSoc ket;
      > UINT nMsgSentCount;
      > float fHeadingInStatu sMsg;
      >
      > HANDLE hEventQueueNotE mpty;
      > MsgQueueSocketT ype MsgQueue[MSGQUEUEMAX];
      > UINT MsgQueueFreeIdx ;
      > UINT MsgQueueUsedIdx ;
      > } SOCKET_INFO;
      >
      >
      > I create an instance of this struct in a file called realerdlg.h
      >
      > SOCKET_INFO m_ServerSocketI nfo;[/color]

      Let me guess... It's a data member of some class, isn't it?
      [color=blue]
      > realerdlg.cpp sets the value of the nPort member
      >
      > m_ServerSocketI nfo.nPort = (int)(dwPort);
      >
      >
      >
      >
      > and finally, I am attempting to create a socket with the statement:
      >
      > CWinThread *lpThread = AfxBeginThread( ServerSocketThr ead, (LPVOID)
      > &m_ServerSocket Info);[/color]

      '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...
      [color=blue]
      >
      >
      >
      >
      > The dwPort variable is correct and verified.[/color]

      "Correct and verified" where? Before you call 'AfxBeginThread '?
      [color=blue]
      > In the
      > serversocketthr ead.cpp class, I cannot pick up the
      > value of nPort. The constructor there is
      >
      > UINT ServerSocketThr ead( LPVOID lpInf )
      > {
      >
      > SOCKADDR_IN Addr;
      > int AddrLen;
      > SOCKET_INFO* lpInfo = (SOCKET_INFO *) lpInf;
      > int nRetValue = 0;
      > CSocket ServerSocket;
      > BOOL bDone = FALSE;
      > CSocket ClientSocket;
      > MsgQueueSocketT ype 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?[/color]

      <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.program mer.*

      Victor

      Comment

      Working...