473,394 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
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
2 1370
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DPhelps | last post by:
I have a multithreaded Python shell server (base on the sample code 'pysvr.py') that uses a C-based extension class. The trouble I'm having is that I cannot figure out a way to create a Python...
12
by: Winbatch | last post by:
Hi, I'm trying to learn multithreading and it doesn't seem to be working for me. I have a feeling it has to do with the fact that I'm writing to files rather than to printf, but maybe not. ...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
6
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create...
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
8
by: Flack | last post by:
Hey guys, In my app I have a bitmap where drawing is done and in the form's paint method I show the bitmap: private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {...
1
by: John Wright | last post by:
I am running a console application that connects to an Access database (8 million rows) and converts it to a text file and then cleans and compacts the database. When it runs I get the following...
1
by: Derrick | last post by:
Hello all; I'm having a bit of trouble with .NET remoting. Here's my scenario: I have a "remotable" type which is served by a Windows Service. I have a WinForms app which consumes the...
3
by: prashfire2000 | last post by:
This is a code i wrote to play a video file usin JMF..... the applet gets started but not initialized..... is the code correct or is there any mistake?????? please help me out as soon as u...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.