how to solve unhandled exception error when using visual C++ 2008?
- by make
Hi,
Could someone please help me to solve unhandled exception error when using visual C++ 2008? the error is displayed as follow: Unhandled exception at 0x00411690 in time.exe: 0xC0000005: Access violation reading location 0x00000008
Actually when I used visual c++ 6 in the past, there weren't any error and the program was running fine. But now ehen I use visual 2008, I am getting this Unhandled exception error.
Here is the program:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifdef _WIN32
// #include <winsock.h>
#include <windows.h>
#include "stdint.h"
// typedef __int64 int64_t // Define it from MSVC's internal type
// typedef unsigned __int32 uint32_t
#else
#include <stdint.h> // Use the C99 official header
#include <sys/time.h>
#include <unistd.h>
#endif
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
#define TEST
#ifdef TEST
uint32_t stampstart();
uint32_t stampstop(uint32_t start);
int main() {
uint32_t start, stop;
start = stampstart();
/* Your code goes here */
stop = stampstop(start);
return 0;
}
#endif
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag = 0;
if (NULL != tv)
{
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
tmpres /= 10; /*convert into microseconds*/
/*converting file time to unix epoch*/
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
if (NULL != tz)
{
if (!tzflag)
{
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}
uint32_t stampstart()
{
struct timeval tv;
struct timezone tz;
struct tm *tm;
uint32_t start;
gettimeofday(&tv, &tz);
tm = localtime(&tv.tv_sec);
printf("TIMESTAMP-START\t %d:%02d:%02d:%d (~%d ms)\n", tm->tm_hour,
tm->tm_min, tm->tm_sec, tv.tv_usec,
tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
tm->tm_sec * 1000 + tv.tv_usec / 1000);
start = tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
tm->tm_sec * 1000 + tv.tv_usec / 1000;
return (start);
}
uint32_t stampstop(uint32_t start)
{
struct timeval tv;
struct timezone tz;
struct tm *tm;
uint32_t stop;
gettimeofday(&tv, &tz);
tm = localtime(&tv.tv_sec);
stop = tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
tm->tm_sec * 1000 + tv.tv_usec / 1000;
printf("TIMESTAMP-END\t %d:%02d:%02d:%d (~%d ms) \n", tm->tm_hour,
tm->tm_min, tm->tm_sec, tv.tv_usec,
tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
tm->tm_sec * 1000 + tv.tv_usec / 1000);
printf("ELAPSED\t %d ms\n", stop - start);
return (stop);
}
thanks for your replies: