Click here to Skip to main content
15,886,963 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: C++ related question Pin
Nemanja Trifunovic20-Sep-05 2:40
Nemanja Trifunovic20-Sep-05 2:40 
QuestionProblem Creating object and accessing public member function. Pin
karmendra_js20-Sep-05 0:20
karmendra_js20-Sep-05 0:20 
AnswerRe: Problem Creating object and accessing public member function. Pin
Bob Stanneveld20-Sep-05 0:38
Bob Stanneveld20-Sep-05 0:38 
GeneralRe: Problem Creating object and accessing public member function. Pin
karmendra_js20-Sep-05 0:51
karmendra_js20-Sep-05 0:51 
GeneralRe: Problem Creating object and accessing public member function. Pin
Satishkumar.B20-Sep-05 2:11
Satishkumar.B20-Sep-05 2:11 
Questionthreading in networking Pin
ppp00120-Sep-05 0:05
ppp00120-Sep-05 0:05 
AnswerRe: threading in networking Pin
Bob Stanneveld20-Sep-05 0:41
Bob Stanneveld20-Sep-05 0:41 
AnswerRe: threading in networking Pin
Glenn Inman20-Sep-05 2:29
Glenn Inman20-Sep-05 2:29 
See if these code snips help at all - then from your main location you just create one of these and got xx.run. Just an example, hope it helps

Glenn

///
/// Summary description for ThreadEx.
///

/*
***************************************************************************
**
** Class: ThreadEx
**
** Description:
** This is our thread class
**
** Notes:
**
*/
public class ThreadEx
{
/*
** Local Variables
*/
protected Thread m_thread = null;
protected ThreadStart m_start = null;
protected bool m_bStopped = true;

/*
***************************************************************************
**
** Property(bool): Stop
*/
///
/// Set the Stop Flag
///

///
public bool Stop
{
get{return m_bStopped;}
set{m_bStopped = value;}
}

/*
***************************************************************************
**
** Property(bool): isStopped
*/
///
/// Check to see if it is stopped - redundant
///

///
public bool isStopped
{
get{return Stop;}
}

/*
***************************************************************************
**
** Function: Start
*/
///
/// Start the Thread (Run) on the form
///

///<returns>void
///
public void Start()
{
Stop = false;
m_start = new ThreadStart(Run);
m_thread = new Thread(m_start);
m_thread.Start();
}

/*
***************************************************************************
**
** Function: WaitTillDone
*/
///
/// Wait till the thread is done (Infinitely)
///

///<returns>bool - True if thread is done
///
public bool WaitTillDone()
{
return m_thread.Join(Timeout.Infinite);
}

/*
***************************************************************************
**
** Function: WaitTillDone
*/
///
/// Wait for iMilli milliseconds for thread to complete
///

///<param name="iMilli" type="int" />
///<returns>void
///
public void WaitTillDone(int iMilli)
{
m_thread.Join(iMilli);
}

/*
***************************************************************************
**
** Function: IsDone
*/
///
/// Check to see if the thread is completed
///

///<returns>bool
///
public bool isDone
{
get{return m_thread.Join(0);}
}

/*
***************************************************************************
**
** Function: Kill
*/
///
/// Kill the thread
///

///<returns>void
///
public void Kill()
{
m_thread.Abort();
}

/*
***************************************************************************
**
** Function: Run
*/
///
/// This is the overloaded run function
///

///<returns>void
///
public virtual void Run()
{
}
}

public class RFC868TimeClient : ThreadEx
{
/*
** Local Variables
*/
protected string m_strTimeServer;
protected int m_iInterval;

#region SystemTime in Kernel32
/*
** Import the Kernel32 Function
*/
[DllImport("kernel32.dll", SetLastError=true)]
protected static extern int SetLocalTime(IntPtr ptrSystemTime);

/*
***************************************************************************
**
** Class: CSystemTime
**
*/
///
/// Class to behave like the SYSTEMTIME Structure in win32
///

///
public class CSystemTime
{
protected enum Var
{
Year = 0,
Month = 1,
DayOfWeek = 2,
Day = 3,
Hour = 4,
Minute = 5,
Second = 6,
Millisecond = 7,
AllocCount = 8
}

protected System.UInt16[] auData = new UInt16[(int)Var.AllocCount];

public System.UInt16[] Data
{
get{return auData;}
}

public System.UInt16 Year
{
get{return auData[(int)Var.Year];}
set{auData[(int)Var.Year] = value;}
}

public System.UInt16 Month
{
get{return auData[(int)Var.Month];}
set{auData[(int)Var.Month] = value;}
}

public System.UInt16 Day
{
get{return auData[(int)Var.Day];}
set{auData[(int)Var.Day] = value;}
}
public System.UInt16 DayOfWeek
{
get{return auData[(int)Var.DayOfWeek];}
set{auData[(int)Var.DayOfWeek] = value;}
}

public System.UInt16 Hour
{
get{return auData[(int)Var.Hour];}
set{auData[(int)Var.Hour] = value;}
}

public System.UInt16 Minute
{
get{return auData[(int)Var.Minute];}
set{auData[(int)Var.Minute] = value;}
}

public System.UInt16 Second
{
get{return auData[(int)Var.Second];}
set{auData[(int)Var.Second] = value;}
}

public System.UInt16 Millisecond
{
get{return auData[(int)Var.Millisecond];}
set{auData[(int)Var.Millisecond] = value;}
}
}

/*
***************************************************************************
**
** Function: SetLocalTime
*/
///
///
///

///<param name="SystemTime" type="TimeService.RFC868Service.RFC868TimeClient.CSystemTime" />
///<returns>bool
///
protected bool SetLocalTime(CSystemTime SystemTime)
{
/*
** Local Variables
*/
bool bOk = true;
GCHandle gch = GCHandle.Alloc(SystemTime.Data, GCHandleType.Pinned);

if(0 == SetLocalTime(gch.AddrOfPinnedObject()))
{
bOk = false;
}

gch.Free();

return bOk;
}

#endregion SystemTime in Kernel32
/*
***************************************************************************
**
** Property(string): TimeServerAddress
*/
///
/// Store the Server Address we want to connect to
///

///
public string TimeServerAddress
{
get{return m_strTimeServer;}
set{m_strTimeServer = value;}
}

/*
***************************************************************************
**
** Property(int): Interval
*/
///
/// Set the Time Interval to wait between client updates
///

///
public int Interval
{
get{return m_iInterval;}
set{m_iInterval = value;}
}

/*
***************************************************************************
**
** Function: Run
*/
///
/// This is the Time Server
///

///<returns>void
///<exception cref="System.Exception">Thrown
///<remarks>
///
///<example>How to use this function
///
<br />
            ///

///
///
public override void Run()
{
/*
** Till we have to stop process here
*/
while(!isStopped)
{
/*
** Local Variables
*/
TcpClient tcpClient = new TcpClient();
NetworkStream sClient = null;
TimeInfo Info = new TimeInfo();
TimeSpan tsWait = new TimeSpan(0, 0, Interval, 0, 0);
DateTime dtWait = DateTime.Now + tsWait;
CSystemTime SystemTime = new CSystemTime();
DateTime dtNow;


try
{
/*
** Connect to the Server
*/
tcpClient.Connect(m_strTimeServer, RFC868PORT);
sClient = tcpClient.GetStream();
sClient.Read(Info.Array, 0, Info.Array.Length);
tcpClient.Close();

/*
** Get us a Date Time thingie
*/
dtNow = TimeInfo.GetDateTime(Info.UTC);

/*
** Here we have to set the Time of the system
*/
SystemTime.Year = (ushort)dtNow.Year;
SystemTime.Month = (ushort)dtNow.Month;
SystemTime.Day = (ushort)dtNow.Day;
SystemTime.DayOfWeek = (ushort)dtNow.DayOfWeek;
SystemTime.Hour = (ushort)dtNow.Hour;
SystemTime.Minute = (ushort)dtNow.Minute;
SystemTime.Second = (ushort)dtNow.Second;
SystemTime.Millisecond = (ushort)dtNow.Millisecond;

/*
** Set the time and hope that it works
*/
SetLocalTime(SystemTime);
}
catch(Exception)
{
}
finally
{
}

/*
** Wait till it is time to do it again
*/
while(!isStopped && (dtWait > DateTime.Now))
{
System.Threading.Thread.Sleep(1000);
System.Windows.Forms.Application.DoEvents();
}
}
}
}
QuestionChanging the BG color of a multiline edit box Pin
Mohammad A Gdeisat19-Sep-05 23:19
Mohammad A Gdeisat19-Sep-05 23:19 
QuestionSeveral pages working for one var, where to save it? Pin
followait19-Sep-05 23:13
followait19-Sep-05 23:13 
AnswerRe: Several pages working for one var, where to save it? Pin
Cedric Moonen19-Sep-05 23:33
Cedric Moonen19-Sep-05 23:33 
GeneralRe: Several pages working for one var, where to save it? Pin
toxcct20-Sep-05 3:23
toxcct20-Sep-05 3:23 
QuestionCompile time info gathering Pin
Rostfrei19-Sep-05 23:06
Rostfrei19-Sep-05 23:06 
QuestionProblem with two views Pin
karmendra_js19-Sep-05 22:53
karmendra_js19-Sep-05 22:53 
AnswerRe: Problem with two views Pin
Calc2019-Sep-05 23:40
Calc2019-Sep-05 23:40 
Questioncdecl or stdcall - foreign dll, no source, headers Pin
Garth J Lancaster19-Sep-05 22:46
professionalGarth J Lancaster19-Sep-05 22:46 
AnswerRe: cdecl or stdcall - foreign dll, no source, headers Pin
Tim Smith20-Sep-05 3:47
Tim Smith20-Sep-05 3:47 
GeneralRe: cdecl or stdcall - foreign dll, no source, headers Pin
Garth J Lancaster20-Sep-05 4:09
professionalGarth J Lancaster20-Sep-05 4:09 
QuestionGUI Architecture. Pin
karmendra_js19-Sep-05 22:41
karmendra_js19-Sep-05 22:41 
AnswerRe: GUI Architecture. Pin
Cedric Moonen19-Sep-05 22:54
Cedric Moonen19-Sep-05 22:54 
GeneralRe: GUI Architecture. Pin
karmendra_js20-Sep-05 0:30
karmendra_js20-Sep-05 0:30 
AnswerRe: GUI Architecture. Pin
Bob Stanneveld20-Sep-05 0:58
Bob Stanneveld20-Sep-05 0:58 
QuestionCreating .hlp file for my MFCApp Pin
anderslundsgard19-Sep-05 22:23
anderslundsgard19-Sep-05 22:23 
AnswerRe: Creating .hlp file for my MFCApp Pin
*Dreamz20-Sep-05 0:00
*Dreamz20-Sep-05 0:00 
QuestionMewtocol header and terminator Pin
Member 216100419-Sep-05 22:09
Member 216100419-Sep-05 22:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.