[SOLVED]qtcreator under Wine ( MinGw compilant ) windows.h program
-
Hello. I am trying again to compile a windows exe under wine+qtcreator. I am wondering why this code does not compile and reports an error.
@
#ifdef _WIN32
#include "Service.h"
#include <stdio.h>
SERVICE_STATUS ServiceStatus;
SERVICE_STATUS_HANDLE hStatus;
int InitService() {
int result = WriteToLog("Monitoring started.");
return result;
}int WriteToLog(char str) {
FILE fp;
fp = fopen(LOG_FILE, "a+");
if ( ! fp) return -1;
fprintf(fp, "%s\n", str);
fclose(fp);
return 0;
}int ServiceMain(int argc, char argv[]) {
int error = InitService();
if ( error ) {
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = -1;
SetServiceStatus(hStatus, &ServiceStatus);
return 1;
}
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(hStatus, &ServiceStatus);
return 0;
}
int mainO(int argc, char* argv) {
SERVICE_TABLE_ENTRY ServiceTable[2];
ServiceTable[0].lpServiceName = "MemoryStatus" ;
ServiceTable[0].lpServiceProc = (LP_SERVICE_MAIN_FUNCTION) ServiceMain ;
printf("%d is status \n", StartServiceCtrlDispatcher(ServiceTable));
}
@
qtcreator reports errors in mainO ServiceTable[0].lpServiceName and lpServiceProc. The errors are as follows:
@
cannot convert 'const char[13]' to LPWSTR {aka wchar_t*} in assignment
LP_SERVICE_MAIN_FUNCTION was not declared in this scope
@
Should I include something in pro file? -
OK, I was able to just cast to wchar_t* the string. I
ve added to pro file windows.h which for god sake, I
ve found in Qt Dir :) This is nice feat. But I still got that weird err:
@
ServiceTable[0].lpServiceProc = (LP_SERVICE_MAIN_FUNCTION) ServiceMain ;
@
@
Z:\home\ilian\QT5\SampleGame\Service.cpp:38: error: 'LP_SERVICE_MAIN_FUNCTION' was not declared in this scope
ServiceTable[0].lpServiceProc = (LP_SERVICE_MAIN_FUNCTION) ServiceMain ;
^
Z:\home\ilian\QT5\SampleGame\Service.cpp:38: error: expected ';' before 'ServiceMain'
ServiceTable[0].lpServiceProc = (LP_SERVICE_MAIN_FUNCTION) ServiceMain ;
^
@ -
Thank you very much! I`ve figured it by casting the string to wchar_t* but never got the idea it was LPSERVICE not LP_SERVICE... damn windows.
[quote author="hskoglund" date="1410538438"]Hi, try change lines 35 and 36 to:
@
ServiceTable[0].lpServiceName = L"MemoryStatus" ;
ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION) ServiceMain ;
@[/quote]