Current code - API ASync Lookup error


2006-12-08 12:45:27 PM
cppbuilder76
Current Code for Server Service,
produces error about API ASync Lookup in event viewer
//---------------------------------------------------------------------------
#include "DateSvc.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFileDateService *FileDateService;
//---------------------------------------------------------------------------
__fastcall TFileDateService::TFileDateService(TComponent* Owner)
: TService(Owner)
{
}
TServiceController __fastcall TFileDateService::GetServiceController(void)
{
return (TServiceController) ServiceController;
}
void __stdcall ServiceController(unsigned CtrlCode)
{
FileDateService->Controller(CtrlCode);
}
//---------------------------------------------------------------------------
// ServerSocketClientRead - called when data available for reading from client
void __fastcall TFileDateService::ServerSocketClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
AnsiString FileName, FileResult;
TSearchRec sr;
// copy filename from client
FileName = Socket->ReceiveText();
// Lookup file date
if( FindFirst(FileName, faAnyFile, sr) == 0 )
{
// File found - return date/time
FindClose(sr);
// Convert file time to date/time
SYSTEMTIME st = {0};
::FileTimeToSystemTime(&sr.FindData.ftLastWriteTime, &st);
// Generate result
FileResult = FileName + " date: " + SystemTimeToDateTime(st).DateTimeString();
}
else
{
// File Not found
FileResult = FileName + " : File Not Found";
}
// Now return the result to the client
Socket->SendText(FileResult);
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceStart(TService *Sender,
bool &Started)
{
ServerSocket->Active = true;
LogMessage("Socket activated", EVENTLOG_INFORMATION_TYPE, 0, 0);
Started = true;
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceStop(TService *Sender, bool &Stopped)
{
ServiceShutdown(Sender);
Stopped = true;
LogMessage("Socket DE-activated", EVENTLOG_INFORMATION_TYPE, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServicePause(TService *Sender, bool &Paused)
{
// Check if socket has active connections
if( ServerSocket->Socket->ActiveConnections == 0 )
{
// No connections, de-activate
ServerSocket->Active = false;
LogMessage("Socket de-activated for Svc pause",
EVENTLOG_INFORMATION_TYPE, 0, 0);
Paused = true;
}
else
{
// Active connections - cannot pause
ErrCode = 5555; // use whatever you want
LogMessage("Cannot pause Svc while clients are connected to the Socket",
EVENTLOG_WARNING_TYPE, 0, 0);
Paused = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceContinue(TService *Sender,
bool &Continued)
{
// If socket is not active, turn it on
if( !ServerSocket->Active )
{
ServerSocket->Active = true;
LogMessage("Socket re-activated for continue",
EVENTLOG_INFORMATION_TYPE, 0, 0);
}
Continued = true;
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceShutdown(TService *Sender)
{
// If socket is active, shut it down
if( ServerSocket->Active )
{
// Handle exception in socket de-activate
try
{
// Shutdown the socket
ServerSocket->Active = false;
LogMessage("Socket de-activated",
EVENTLOG_INFORMATION_TYPE,0, 0);
}
catch(const Exception &e)
{
// Exception occured in shutodnw
ErrCode = 5556; // use whatever you want
LogMessage("Socket not de-activated: " + e.Message,
EVENTLOG_ERROR_TYPE, 0, 0);
}
}
}