add extern C to maintain compatibility with C++
authorgreg
Wed, 16 Sep 2009 15:19:14 +0200
changeset 591 513f5ec8b628
parent 590 aba1bf1defc6
child 592 b98df76c6fd5
add extern C to maintain compatibility with C++
fix warnings with msvc compiler
drivers/timers_win32/timers_win32.c
drivers/win32/win32.c
--- a/drivers/timers_win32/timers_win32.c	Wed Sep 16 15:18:23 2009 +0200
+++ b/drivers/timers_win32/timers_win32.c	Wed Sep 16 15:19:14 2009 +0200
@@ -25,13 +25,18 @@
 #include <stdlib.h>
 #include <sys/timeb.h>
 
-extern "C"
-{
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "applicfg.h"
 #include "can_driver.h"
 #include "timer.h"
 #include "timers_driver.h"
+
+#ifdef __cplusplus
 };
+#endif
 
 struct _timeb timebuffer;
 
@@ -142,7 +147,7 @@
 		LARGE_INTEGER liDueTime;
 
 		/* arg 2 of SetWaitableTimer take 100 ns interval */
-		liDueTime.QuadPart = -value;
+		liDueTime.QuadPart = (-1 * value);
 		//printf("SetTimer(%llu)\n", value);
 
 		if (!SetWaitableTimer(timer, &liDueTime, 0, NULL, NULL, FALSE))
--- a/drivers/win32/win32.c	Wed Sep 16 15:18:23 2009 +0200
+++ b/drivers/win32/win32.c	Wed Sep 16 15:19:14 2009 +0200
@@ -26,12 +26,19 @@
 */
 
 #include <windows.h>
-extern "C"
-{
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "canfestival.h"
 #include "timer.h"
 #include "timers_driver.h"
+
+#ifdef __cplusplus
 };
+#endif
+
 // GetProcAddress doesn't have an UNICODE version for NT
 #ifdef UNDER_CE
   #define myTEXT(str) TEXT(str)
@@ -138,6 +145,8 @@
 CAN_HANDLE canOpen(s_BOARD *board, CO_Data * d)
 {
 	int i;
+    CAN_HANDLE fd0;
+
 	for(i=0; i < MAX_NB_CAN_PORTS; i++)
 	{
 		if(!canports[i].used)
@@ -152,7 +161,7 @@
 	}
 	#endif
 
-	CAN_HANDLE fd0 = m_canOpen(board);
+	fd0 = m_canOpen(board);
 	if(fd0)
 	{
 		canports[i].used = 1;
@@ -173,16 +182,24 @@
 int canClose(CO_Data * d)
 {
 	UNS8 res;
-
-	((CANPort*)d->canHandle)->used = 0;
-	CANPort* tmp = (CANPort*)d->canHandle;
+	CANPort* tmp;
+
+	if((CANPort*)d->canHandle)
+	{
+	  ((CANPort*)d->canHandle)->used = 0;
+	}
+
+	tmp = (CANPort*)d->canHandle;
 	d->canHandle = NULL;
 
-	// close CAN port
-	res = m_canClose(tmp->fd);
-
-	// kill receiver task
-	WaitReceiveTaskEnd(&tmp->receiveTask);
+	if(tmp)
+	{
+	  // close CAN port
+	  res = m_canClose(tmp->fd);
+
+	  // kill receiver task
+	  WaitReceiveTaskEnd(&tmp->receiveTask);
+	}
 	return res;
 }