same code doesn't work,please tell the error

i made two code the code no 1 works fine when i put the code no1 in an application it breaks,can u tell me the error.I have mentioned in code no 2 where it breaks at "return 0".
Here are two code:-
code no 1:-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	
ServerMediaSession* sms[2];

UsageEnvironment* env;

Boolean reuseFirstSource = False;

Boolean iFramesOnly = False;

TaskScheduler* scheduler;
UserAuthenticationDatabase* authDB;
char const* streamName[2];
char const* inputAddressStr[2];
int inputPortNum[2];
int i = 0,j = 0;

DWORD WINAPI START_STREAM();

char const* descriptionString[2] ={"Session streamed by \"testOnDemandRTSPServer1\"","Session streamed by \"testOnDemandRTSPServer2\""};
RTSPServer* rtspServer;

char* url[2];
HANDLE Th1;
DWORD Tid1=NULL; 
int main()
{
	streamName[0] = "test";		
	inputAddressStr[0] = "239.255.42.42";	
	inputPortNum[0] = 4444;		

	streamName[1] = "stream2";		
	inputAddressStr[1] = "237.255.42.42";	
	inputPortNum[1] = 5043;	
        scheduler = BasicTaskScheduler::createNew();
	env = BasicUsageEnvironment::createNew(*scheduler);
	UserAuthenticationDatabase* authDB = NULL;
rtspServer = RTSPServer::createNew(*env,554, authDB);

	while(1)
	{
		printf("\nEnter any key to STRAT_STREAMER\n");
		getch();
		Th1=CreateThread(NULL,0(LPTHREAD_START_ROUTINE)START_STREAM,NULL,0,&Tid1);
		if(Th1 == NULL)
			*env<< "\nTh1 failed..\n";

	}
	return 0;
}
DWORD WINAPI START_STREAM()
{
	Boolean const inputStreamIsRawUDP = False; 

	printf("\nIn Start Stream\n");
	sms[i] = ServerMediaSession::createNew(*env, streamName[i], streamName[i],descriptionString[i]);
	sms[i]->addSubsession(MPEG2TransportUDPServerMediaSubsession::createNew(*env,inputAddressStr[i],inputPortNum[i],inputStreamIsRawUDP));
	rtspServer->addServerMediaSession(sms[i]);

	url[i] = rtspServer->rtspURL(sms[i]);
	printf("\n\"%s \" stream, from a UDP Transport Stream input source\n\t(",streamName[i]);
	//*env[i] << "\n\"" << streamName[i] << "\" stream, from a UDP Transport Stream input source \n\t(";
	if (inputAddressStr[i] != NULL)
	{
		printf("\nIP multicast address %s,",inputAddressStr[i]);
		//*env[i] << "IP multicast address " << inputAddressStr[i] << ",";
	} 
	else 
	{
		printf("unicast;");
		//*env[i] << "unicast;";
	}
	printf("port %d \n",inputPortNum[i]);
	//*env[i] << " port " << inputPortNum[i] << ")\n";
	printf("Play this stream using the URL \" %s \"",url[i]);
	//*env[i] << "Play this stream using the URL \"" << url[i] << "\"\n";
	delete[] url[i];
	if(j == 0)
	{
	if (rtspServer->setUpTunnelingOverHTTP(http_port[i]) || rtspServer->setUpTunnelingOverHTTP(http_port[i]) || rtspServer->setUpTunnelingOverHTTP(http_port[i]))
		{
			printf("\n\n\n(We use port %d for optional RTSP-over-HTTP tunneling.)\n",rtspServer->httpServerPortNum());
			
		} 
		else
		{
			printf("\n(RTSP-over-HTTP tunneling is not available.)");
		}
		j++;
	}
	else
	printf("\n\n\n(We use port %d for optional RTSP-over HTTPtunneling.)\n",rtspServer->httpServerPortNum());
	
	i++;
	if(i == 1)
	env->taskScheduler().doEventLoop(); // does not return

	return 0;
}
	



Here is mine code no 2:-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
ServerMediaSession* sms[50];

UsageEnvironment* env;
Boolean reuseFirstSource = False;
Boolean iFramesOnly = False;
TaskScheduler* scheduler;

UserAuthenticationDatabase* authDB;
char const* descriptionString ="Session streamed by \"testOnDemandRTSPServer1\"";
RTSPServer* rtspServer;
char* url[50]
static int k=0,j=0,z=0,w=0;
char const* descriptionString ="Session streamed by \"testOnDemandRTSPServer1\"";
RTSPServer* rtspServer;
char* url[50];
char const* streamName[2];
char const* inputAddressStr[2];
int inputPortNum[2];


int main()
{

StartRtspServer();
	b.OnRun();

}
BOOL CFIServerDlg::OnRun()
{
	OnStartFIServer();
return TRUE;  // ret
}

int StartRtspServer()
{
	char buffer[2500];
	wLog->WriteDebugLog("Entering in StartRtspServer().");
	
	// Begin by setting up our usage environment:
	scheduler = BasicTaskScheduler::createNew();
	env = BasicUsageEnvironment::createNew(*scheduler);

	UserAuthenticationDatabase* authDB = NULL;
portNumBits rtspServerPortNum = 554;

	rtspServer = RTSPServer::createNew(*env,rtspServerPortNum, authDB);
if (rtspServer == NULL)
	{
		sprintf(buffer,"Failed to create RTSP server with Port:%d %s",rtspServerPortNum,env->getResultMsg());
		wLog->WriteErrorLog(buffer);
		*env << "Failed to create RTSP server: " <<env->getResultMsg()<<"\n";
			return 1;
		
	}
	else
	{
		wLog->WriteInfoLog("Created RTSP server..");
		*env << "Created RTSP server.."<<"\n.";
			return 0;
	}
void CFIServerDlg::OnStartFIServer() 
{
	wLog->WriteDebugLog("Entering in OnStartFIServer()");


	int success = m_FINetCom->StartFIServer();
	if(success == 0)
	{		
		
		m_FINetCom->StartFICom();
		
	}
}
DWORD CFINetCom::StartFIServer()
{
//AL VARIABLES ARE DEFINED NO ISSUE REGARDING VARIABLES
m_ThreadHandle[2] = CreateThread(NULL,0, (LPTHREAD_START_ROUTINE)MessageHandleThread, this, 0, &ThreadId3);

	if(m_ThreadHandle[2] == NULL)
	{
		wLog->WriteErrorLog("StartFIServer() Error while creating MessageHandleThread thread.");
		cout<<"Debug: StartFIServer() Error while creating MessageHandleThread thread.\n";

	}
}
*************************************************************************
*
* NAME        : MessageHandleThread()
*
* DESCRIPTION : The message handle thread for handling various messages comming from 
client and streamer.
*
* PARAMETERS  : CFINetCom*
*
* RETURN      : DWORD 
*
**************************************************************************/

DWORD WINAPI CFINetCom::MessageHandleThread(CFINetCom* MyServ)
{
	case START_STREAM:
   {
      HANDLE th1;
      DWORD tid=NULL;
      th1 = CreateThread(NULL,0, (LPTHREAD_START_ROUTINE)StartStreamingThread,&ip_port, 0, &tid);
	if(th1 == NULL)
	{
	wLog->WriteDebugLog("StartFIServer() Error while creating MessageReplyThread .");
									cout<<"Debug: StartFIServer() Error while creating MessageReplyThread .\n";
	}
break;
}

DWORD WINAPI StartStreamingThread(Parameters ip_port)
{
	streamName[0] = "test";		
	inputAddressStr[0] = "239.255.42.42";	
	inputPortNum[0] = 4444;		

	streamName[1] = "stream2";		
	inputAddressStr[1] = "237.255.42.42";	
	inputPortNum[1] = 5043;
Boolean const inputStreamIsRawUDP = False; 
sms[w] = ServerMediaSession::createNew(*env, streamName[w], streamName[w],descriptionString);
	sms[w]->addSubsession(MPEG2TransportUDPServerMediaSubsession::createNew(*env, inputAddressStr[w], inputPortNum[w], inputStreamIsRawUDP));
	rtspServer->addServerMediaSession(sms[w]);

	url[w] = rtspServer->rtspURL(sms[w]);
if (inputAddressStr[w] != NULL)
	{
		
		sprintf(buffer,"IP multicast address %s",inputAddressStr[w]);
		wLog->WriteDebugLog(buffer);
		*env << "IP multicast address " << inputAddressStr[w] << ",";
	}
	else
	{
		//printf("\nunicast;\n");
		wLog->WriteDebugLog("unicast;");
		*env << "unicast;";
	}
	delete[] url[w];
if(j==0)
	{
		if (rtspServer->setUpTunnelingOverHTTP(TunnelingPort) || rtspServer->setUpTunnelingOverHTTP(TunnelingPort) || rtspServer->setUpTunnelingOverHTTP(TunnelingPort))
		{
			
			sprintf(buffer,"(We use port %d for optional RTSP-over-HTTP tunneling.)", rtspServer->httpServerPortNum());
			wLog->WriteDebugLog(buffer);
			*env << "\n(We use port " << rtspServer->httpServerPortNum() << " for optional RTSP-over-HTTP tunneling.)\n";
		} 
		else 
		{
			
			wLog->WriteDebugLog("(RTSP-over-HTTP tunneling is not available.)");
			*env << "\n(RTSP-over-HTTP tunneling is not available.)\n";
		}
		j++;
	}
	else
	{
		printf("(We use port %d for optional RTSP-over-HTTP tunneling.)", rtspServer->httpServerPortNum());
		sprintf(buffer,"(We use port %d for optional RTSP-over-HTTP tunneling.)", rtspServer->httpServerPortNum());
		wLog->WriteDebugLog(buffer);
	}

	
	
	w++;
	wLog->WriteDebugLog("Leaving StartStreamingThread");
	if(w == 1)
		env->taskScheduler().doEventLoop(); // does not return

	return 0; // only to prevent compiler warning,IT BREAKS HERE

}	

IT BREAKS HERE


No. No it doesn't. I don't have the time to read through all of this right now, but it's not the return that's the problem.
IN CODE NO 1 also it does not return when the second thread is created,and the code no 1 works
I find I keep saying this. Don't use CreateThread(), use _beginthreadex() instead.
Sir CreateThread() works good in code no 1
You may think it works, but don't use it. It doesn't initialise the per thread static data in the C runtime library.
Topic archived. No new replies allowed.