🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
16 messages
16 total messages Started by Jeff Mon, 25 Jun 2007 20:49
TService Compile Error
#1734
Author: Jeff
Date: Mon, 25 Jun 2007 20:49
48 lines
2520 bytes
I've got a service application that doesn't seem to compile anymore (code 
below).  I'm not sure what's going on but it appears that my class 
declaration doesn't work.  I'm using BDS 2006.

UnitService.cpp:
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"

    TsrvMain *srvMain;

I get three errors on the pointer declaration (TsrvMain *srvMain):

    [C++ Error] UnitService.cpp(8): E2141 Declaration syntax error
    [C++ Error] UnitService.cpp(15): E2090 Qualifier 'TsrvMain' is not a 
class or namespace name
    [C++ Error] UnitService.cpp(15): E2040 Declaration terminated 
incorrectly

Here's part of UnitService.h:

    class TsrvMain : public TService
    {
    __published:    // IDE-managed Components
     void __fastcall ServiceExecute(TService *Sender);
     void __fastcall ServiceStart(TService *Sender, bool &Started);
     void __fastcall ServiceAfterInstall(TService *Sender);
     void __fastcall ServiceBeforeUninstall(TService *Sender);
    private:        // User declarations
     bool __fastcall IsTime();
    public:         // User declarations
     WORD wHour;
     WORD wMin;
     bool boolLogUsers;

     __fastcall TsrvMain(TComponent* Owner);
     TServiceController __fastcall GetServiceController(void);

     friend void __stdcall ServiceController(unsigned CtrlCode);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TsrvMain *srvMain;
    //---------------------------------------------------------------------------

I don't understand why it thinks my class is not declared?

Thanks,
Jeff 
Re: TService Compile Error
#1736
Author: Remy Lebeau (TeamB)
Date: Mon, 25 Jun 2007 21:08
14 lines
1380 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:46802aa8$1@newsgroups.borland.com...

> I've got a service application that doesn't seem to compile anymore
> (code below).  I'm not sure what's going on but it appears that
> my class declaration doesn't work.  I'm using BDS 2006.

Are you including UnitService.h in the .cpp file?  If you are not,
then that would account for such errors, as TsrcMain really would be
an undeclared type.


Gambit
Re: TService Compile Error
#1737
Author: Jeff
Date: Mon, 25 Jun 2007 21:28
16 lines
1545 bytes
> Are you including UnitService.h in the .cpp file?  If you are not,
> then that would account for such errors, as TsrcMain really would be
> an undeclared type.

Yes here's the top of the cpp file:
//---------------------------------------------------------------------------
#include "UnitService.h"
#include "Registry.hpp"
#include "UnitLogThread.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TsrvMain *srvMain;

I'm sorry I guess I should have included that part. 
Re: TService Compile Error
#1739
Author: Remy Lebeau (TeamB)
Date: Mon, 25 Jun 2007 22:54
13 lines
1378 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:468033ac$1@newsgroups.borland.com...

> #include "UnitLogThread.h"

Does that header include UnitService at all, either directly or
indirectly?  Since you are including UnitService.h in UnitService.cpp,
what you describe might be caused by circular references in your
header files.


Gambit
Re: TService Compile Error
#1740
Author: Bob Gonder
Date: Mon, 25 Jun 2007 23:07
28 lines
1981 bytes
Jeff wrote:

>Here's part of UnitService.h:
>    //---------------------------------------------------------------------------
>    extern PACKAGE TsrvMain *srvMain;
>    //---------------------------------------------------------------------------

>UnitService.cpp:
>    //---------------------------------------------------------------------------
>    #pragma package(smart_init)
>    #pragma resource "*.dfm"
>
>    TsrvMain *srvMain;
In the header this is listed as being a PACKAGE, but here you leave that off.
>
>I get three errors on the pointer declaration (TsrvMain *srvMain):
>
>    [C++ Error] UnitService.cpp(8): E2141 Declaration syntax error

Which line is (8) ?
From your other post, line 8 seems to be blank.

TsrvMain *srvMain; seems to be (15)

>    [C++ Error] UnitService.cpp(15): E2090 Qualifier 'TsrvMain' is not a 
>class or namespace name
>    [C++ Error] UnitService.cpp(15): E2040 Declaration terminated 
>incorrectly
Re: TService Compile Error
#1741
Author: Remy Lebeau (TeamB)
Date: Mon, 25 Jun 2007 23:27
11 lines
1200 bytes
"Bob Gonder" <notbg@notmindspring.invalid> wrote in message
news:j8i0835n4iuh6kbhep8slq2ouf96v601am@4ax.com...

> In the header this is listed as being a PACKAGE, but here you leave
that off.

That is normal.


Gambit
Re: TService Compile Error
#1742
Author: Jeff
Date: Tue, 26 Jun 2007 14:28
7 lines
1455 bytes
> Does that header include UnitService at all, either directly or
> indirectly?  Since you are including UnitService.h in UnitService.cpp,
> what you describe might be caused by circular references in your
> header files.

Excellent thought, but UnitLogThread.h doesn't include UnitService.h.  I 
checked the other includes and couldn't find a circular reference either. 
Re: TService Compile Error
#1744
Author: Jeff
Date: Tue, 26 Jun 2007 14:32
18 lines
1535 bytes
> Which line is (8) ?
> From your other post, line 8 seems to be blank.

I'm sorry for the confusion but the error line 8 is on the pointer 
declaration (TsrvMain *srvMain).

>>    [C++ Error] UnitService.cpp(15): E2090 Qualifier 'TsrvMain' is not a
>>class or namespace name
>>    [C++ Error] UnitService.cpp(15): E2040 Declaration terminated
>>incorrectly


The other two errors are occurring on the constructor:

    __fastcall TsrvMain::TsrvMain(TComponent* Owner)
     : TService(Owner)
    {
    } 
Re: TService Compile Error
#1647
Author: Remy Lebeau (TeamB)
Date: Tue, 26 Jun 2007 16:47
15 lines
1485 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:468122e3$1@newsgroups.borland.com...

> Excellent thought, but UnitLogThread.h doesn't include
UnitService.h.  I
> checked the other includes and couldn't find a circular reference
either.

Then the only other possibility I can think of right now without
seeing more of your code is that you are likely missing a closing '}'
bracket somewhere.


Gambit
Re: TService Compile Error
#1649
Author: Remy Lebeau (TeamB)
Date: Tue, 26 Jun 2007 17:06
18 lines
1738 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:46814809@newsgroups.borland.com...

> here is my entire UnitService.cpp file:

That is not enough to diagnose your problem with.  It is being caused
by one of your header files that the .cpp is including.  The contents
of UnitService.cpp are irrelevant since the error is occuring at the
top of the file immediately after the header includes.  Either
UnitService.h, UnitMainThread.h, or UnitLogThread.h (or any of the
header that they include themselves) are faulty somewhere.  I am
guessing that it is UnitLogThread.h as it is the last file included in
UnitService.cpp, but it could very well be any of the other files as
well.


Gambit
Re: TService Compile Error
#1648
Author: Jeff
Date: Tue, 26 Jun 2007 17:07
264 lines
8397 bytes
> Then the only other possibility I can think of right now without
> seeing more of your code is that you are likely missing a closing '}'
> bracket somewhere.

I double checked my brackets and found none missing, so here is my entire 
UnitService.cpp file:

//---------------------------------------------------------------------------
#include "UnitService.h"
#include "Registry.hpp"
#include "UnitMainThread.h"
#include "UnitLogThread.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TsrvMain *srvMain;
//---------------------------------------------------------------------------
const char *REGKEY = "\\Software\\XXXX\\Main";
const char *SRVDESC = "Testing Service application";
const int DEFHOUR = 21; //Default to 9:00 PM
const int DEFMIN = 0;
//---------------------------------------------------------------------------
__fastcall TsrvMain::TsrvMain(TComponent* Owner)
 : TService(Owner)
{
}

TServiceController __fastcall TsrvMain::GetServiceController(void)
{
 return (TServiceController) ServiceController;
}

void __stdcall ServiceController(unsigned CtrlCode)
{
 srvMain->Controller(CtrlCode);
}
//---------------------------------------------------------------------------

void __fastcall TsrvMain::ServiceExecute(TService *Sender)
{
 thdMain *ptr_thdMain;
 thdLogUsers *ptr_thdLog;

 try
 {
  while (!Terminated)
  {
   if (IsTime())
   {
    ptr_thdMain = new thdMain(true); //Run the worker thread
    Sleep(1000); //Ensure time has passed, so we don't get hundreds of 
threads
    ptr_thdMain->Resume();

    //Log database usage if we should
    if (boolLogUsers)
    {
     ptr_thdLog = new thdLogUsers(strEmailRecip, strServer, true);
     Sleep(1000);
     ptr_thdLog->Resume();
    }
   }

   Sleep(10);
   srvMain->ServiceThread->ProcessRequests(false);
  }
 }__finally {
  ptr_thdMain->Terminate();
  ptr_thdLog->Terminate();
  delete ptr_thdMain;
  delete ptr_thdLog;
  }
}
//---------------------------------------------------------------------------

bool __fastcall TsrvMain::IsTime()
{
 SYSTEMTIME stTime;

 GetLocalTime(&stTime);

 if ((stTime.wHour == wHour) && (stTime.wMinute == wMin) && (stTime.wSecond 
== 0))
  return true;
 else
  return false;
}
//---------------------------------------------------------------------------

void __fastcall TsrvMain::ServiceStart(TService *Sender, bool &Started)
{
 TRegistry *ptr_Reg = new TRegistry();

 try
 {
  ptr_Reg->RootKey = HKEY_LOCAL_MACHINE;
  ptr_Reg->OpenKey(REGKEY, true);

  if (ptr_Reg->ValueExists("Hour"))
   wHour = ptr_Reg->ReadInteger("Hour");
  else
  {
   wHour = DEFHOUR; //Default
   ptr_Reg->WriteInteger("Hour", DEFHOUR);
  }

  if (ptr_Reg->ValueExists("Minute"))
   wMin = ptr_Reg->ReadInteger("Minute");
  else
  {
   wMin = DEFMIN; //Default
   ptr_Reg->WriteInteger("Minute", DEFMIN);
  }

  if (ptr_Reg->ValueExists("LogUsers"))
  {
   boolLogUsers = ptr_Reg->ReadBool("LogUsers");
   if (boolLogUsers)
   {
    if (ptr_Reg->ValueExists("EmailRecip"))
     strEmailRecip = ptr_Reg->ReadString("EmailRecip");
    if (ptr_Reg->ValueExists("EmailServer"))
     strServer = ptr_Reg->ReadString("EmailServer");
   }
  }
  else
   boolLogUsers = false;

 }__finally {
  ptr_Reg->CloseKey();
  delete ptr_Reg;
  }
}
//---------------------------------------------------------------------------

void __fastcall TsrvMain::ServiceAfterInstall(TService *Sender)
{
 LPSERVICE_DESCRIPTION sdService = (LPSERVICE_DESCRIPTION) LocalAlloc(LPTR, 
4096);
 SERVICE_STATUS_PROCESS ssStatus;
    DWORD dwOldCheckPoint;
 DWORD dwStartTickCount;
    DWORD dwWaitTime;
 DWORD dwBytesNeeded;
 SC_HANDLE schManager; //Service Control Manager Handle
 SC_HANDLE schService; //Service Handle

 try
 {
  try
  {
   schManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
   schService = OpenService(schManager, srvMain->Name.c_str(), 
SERVICE_ALL_ACCESS);

   //Set the service description
   sdService->lpDescription = (char *)SRVDESC;
   ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, sdService); 
//Set the description

   //Start the service
   StartService(schService, 0, NULL);

   //Check the pending status
   QueryServiceStatusEx(schService, SC_STATUS_PROCESS_INFO, (unsigned char 
*)&ssStatus, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded);

   //Save the tick count and initial checkpoint.
   dwStartTickCount = GetTickCount();
   dwOldCheckPoint = ssStatus.dwCheckPoint;

   while (ssStatus.dwCurrentState == SERVICE_START_PENDING)
   {
    //Do not wait longer than the wait hint. A good interval is
    //one tenth the wait hint, but no less than 1 second and no
    //more than 10 seconds.

    dwWaitTime = ssStatus.dwWaitHint / 10;

    if(dwWaitTime < 1000)
     dwWaitTime = 1000;
    else if (dwWaitTime > 10000)
     dwWaitTime = 10000;

    Sleep(dwWaitTime);

    //Check the status again.
    if (!QueryServiceStatusEx(schService, SC_STATUS_PROCESS_INFO, 
(LPBYTE)&ssStatus, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded))
     break;

    if (ssStatus.dwCheckPoint > dwOldCheckPoint) //The service is making 
progress.
    {
     dwStartTickCount = GetTickCount();
     dwOldCheckPoint = ssStatus.dwCheckPoint;
    }
    else
    {
     if(GetTickCount()-dwStartTickCount > ssStatus.dwWaitHint) //No progress 
made within the wait hint
      break;
    }
   }
  } __finally {
   LocalFree(sdService); //Free allocated memory
   //Close any open handles
   if (schService)
    CloseServiceHandle(schService);
   if (schManager)
    CloseServiceHandle(schManager);
   }
 } catch (Exception &exception) {
  Sysutils::ShowException(&exception, System::ExceptAddr());
  }
}
//---------------------------------------------------------------------------

void __fastcall TsrvMain::ServiceBeforeUninstall(TService *Sender)
{
 SERVICE_STATUS ssStatus;
 SERVICE_STATUS_PROCESS sspStatus;
 DWORD dwStartTime = GetTickCount();
 DWORD dwBytesNeeded;
 SC_HANDLE schManager; //Service Control Manager Handle
 SC_HANDLE schService; //Service Handle

 try
 {
  try
  {
   schManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
   schService = OpenService(schManager, srvMain->Name.c_str(), 
SERVICE_ALL_ACCESS);

   //Stop the service
   ControlService(schService, SERVICE_CONTROL_STOP, &ssStatus);

   //Wait for the service to stop
   while (ssStatus.dwCurrentState != SERVICE_STOPPED)
   {
    Sleep(ssStatus.dwWaitHint);

    if (ssStatus.dwCurrentState == SERVICE_STOPPED)
     break;

    QueryServiceStatusEx(schService, SC_STATUS_PROCESS_INFO, 
(LPBYTE)&sspStatus, sizeof(SERVICE_STATUS_PROCESS), &dwBytesNeeded);
    if (GetTickCount() - dwStartTime > (unsigned)srvMain->WaitHint)
     break;
   }
  } __finally {
   //Close any open handles
   if (schService)
    CloseServiceHandle(schService);
   if (schManager)
    CloseServiceHandle(schManager);
   }
 } catch (Exception &exception) {
  Sysutils::ShowException(&exception, System::ExceptAddr());
  }
}
//--------------------------------------------------------------------------- 
Re: TService Compile Error
#1650
Author: Jeff
Date: Tue, 26 Jun 2007 17:20
48 lines
3073 bytes
> That is not enough to diagnose your problem with.  It is being caused
> by one of your header files that the .cpp is including.  The contents
> of UnitService.cpp are irrelevant since the error is occuring at the
> top of the file immediately after the header includes.  Either
> UnitService.h, UnitMainThread.h, or UnitLogThread.h (or any of the
> header that they include themselves) are faulty somewhere.  I am
> guessing that it is UnitLogThread.h as it is the last file included in
> UnitService.cpp, but it could very well be any of the other files as
> well.

I can comment out all the includes except UnitService.h and the error still 
occurs...here's UnitService.h:

//---------------------------------------------------------------------------
#ifndef UnitServiceH
#define UnitServiceH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <SvcMgr.hpp>
#include <vcl.h>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TsrvMain : public TService
{
__published:    // IDE-managed Components
 void __fastcall ServiceExecute(TService *Sender);
 void __fastcall ServiceStart(TService *Sender, bool &Started);
 void __fastcall ServiceAfterInstall(TService *Sender);
 void __fastcall ServiceBeforeUninstall(TService *Sender);
private:        // User declarations
 bool __fastcall IsTime();
public:         // User declarations
 WORD wHour;
 WORD wMin;
 bool boolLogUsers;
 String strEmailRecip;
 String strServer;

 __fastcall TsrvMain(TComponent* Owner);
 TServiceController __fastcall GetServiceController(void);

 friend void __stdcall ServiceController(unsigned CtrlCode);
};
//---------------------------------------------------------------------------
extern PACKAGE TsrvMain *srvMain;
//---------------------------------------------------------------------------
#endif 
Re: TService Compile Error
#1652
Author: Remy Lebeau (TeamB)
Date: Tue, 26 Jun 2007 18:41
17 lines
1743 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:46814b2e$1@newsgroups.borland.com...

> I can comment out all the includes except UnitService.h and the
error still
> occurs...

That does not negate what I have described so far.  SOMETHING in your
code somewhere is broken, causing the compiler to not close up
everything properly.  I suggest you create a new service project from
scatch and copy your code to it one piece at a time, recompiling on
each one, until you hit the error again.  Then you will know which
piece is actually breaking it.


Gambit
Re: TService Compile Error
#1653
Author: Jeff
Date: Tue, 26 Jun 2007 19:04
8 lines
1699 bytes
> That does not negate what I have described so far.  SOMETHING in your
> code somewhere is broken, causing the compiler to not close up
> everything properly.  I suggest you create a new service project from
> scatch and copy your code to it one piece at a time, recompiling on
> each one, until you hit the error again.  Then you will know which
> piece is actually breaking it.

Good idea, I'll give that a go...Thanks 
Re: TService Compile Error
#1654
Author: Jeff
Date: Tue, 26 Jun 2007 22:46
10 lines
1827 bytes
> I suggest you create a new service project from
> scatch and copy your code to it one piece at a time, recompiling on
> each one, until you hit the error again.  Then you will know which
> piece is actually breaking it.

OK, I created a new service and pasted in my code compiling every step of 
the way.  Everything works fine until you save the project and unit files 
over the existing ones.  As soon as you save the files the compilation 
errors show up.  I saved the project with the same names but in a clean new 
directory and everything works. 
Re: TService Compile Error
#1655
Author: Remy Lebeau (TeamB)
Date: Tue, 26 Jun 2007 23:33
16 lines
1904 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:46819796$1@newsgroups.borland.com...

> OK, I created a new service and pasted in my code compiling
> every step of the way.  Everything works fine until you save the
> project and unit files over the existing ones.  As soon as you save
> the files the compilation errors show up.  I saved the project with
> the same names but in a clean new directory and everything works.

Then you probably have a file somewhere on the search path of the old
project that is getting pulled in and mucking around with the code,
such as via precompiled macros.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads