Why C# Pinvoke method cannot catch the CTime exception error?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I was using the C++ pointer to functions from the dll to get callback with function below:<br/>

<pre style="font-family:Consolas; color:black; background:none repeat scroll 0% 0% white tTimestamp CAcmComms::ParseTimestamp(byte buffer[])<br/><span style="color:green //-----------------------------------------------------------------------------<br/>{<br/> UINT8 timesource = buffer[0];<br/> UINT16 year = <span style="color:blue static_cast<UINT16>((buffer[2] << 8 | buffer[1]));<br/> UINT8 month = buffer[3];<br/> UINT8 day = buffer[5];<br/> UINT8 hour = buffer[6];<br/> UINT8 minute = buffer[7];<br/> UINT8 seconds = buffer[8];<br/> UINT16 milliseconds = <span style="color:blue static_cast<UINT16>((buffer[10] << 8 | buffer[9]));<br/><br/> UINT8 dayOfWeek = 0;<br/><span style="color:blue try<br/> {<br/> CTime time = CTime(year, month, day, hour, minute, seconds);<br/> dayOfWeek = <span style="color:blue static_cast<UINT8>(time.GetDayOfWeek());<br/> }<br/><span style="color:blue catch (...)<br/> {<br/> CAcmLogger::WriteLogfile(<span style="color:#a31515 "%s AcmComms: Exception getting dayOfWeek source:%d %d-%d-%d %d:%d:%d dayOfWeek:%dn", m_serialNr, timesource, year, month, day, <br/> hour, minute, seconds, dayOfWeek); <br/> } }<br/> It hit the exception error at the construction of CTime as the time parameters are all zeros. And I am able to catch that return with the printout of the exception log. <br/> <br/> However, when I was using the C# PInvoke method to call the same callback function api in the dll, I will get the error as below on the line which constructing the Ctime.... <img alt="" src="file:///C:/Users/MYLIHA/AppData/Local/Temp/moz-screenshot.png <img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/109394 Did somebody have idea why is this happens? [/code]
<br/>


View the full article
 
Back
Top