Something like this:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include "hb627.h"
#include "time.h"
#define TIMEOUT 5000 //ms
unsigned char Channel_Number=1, Error;
short int Com_Port_Number=5;
short int U;
//int main(void)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
FILE *fp;
char szTmp[100];
//open com port
if( !HB627_Open( Com_Port_Number, TIMEOUT ) )
{
//printf("kan de poort niet openen!\n");
MessageBox(0, "kan de poort niet openen!", 0, MB_OK);
return 1;
}
//read value
if( !HB627_Read_Channel(Channel_Number, &U, &Error) )
{
//printf("Error: %d;\n", Error);
wsprintf(szTmp, "Error: %d;\n", Error);
MessageBox(0, szTmp, 0, MB_OK);
return 2;
}
//printf("%d\n", U);
// time and date in buffer
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"\n%x,%X,",timeinfo);
// write date, time + data to file
fp = fopen("Y:\\jaap\\meetdata.cvs", "a");
fprintf (fp,buffer);
fprintf(fp, "%d",U);
fclose(fp);
return 0;
}