#include<windows.h>
#include<stdio.h>
#include<tchar.h>
#include<iostream>
using
namespace
std;
#include"LoadPlugin.h" //implementation to load the interfaces
#include"ISQLQueryAS.h" //Interfaces to the exported objects
cLoadPlugin g_plugins;
//this is a wrapper object to dynamically link to the dll
/*
oConnection: is an implementation of the IConnectionObserver
this is optional it's not needed but shows that you can implement functionality
based on connections
*/
class
oConnection :
public
IConnectionObserver
{
public
:
virtual
BOOL
ClientConnected(
DWORD
dwUniqueID ,
const
char
* szIP ,
int
iPort )
{
cout<<
"Client : "
<< szIP <<
" port : "
<<iPort<<
" status: connected"
<<endl;
return
( TRUE );
//if false is returned the client will get disconnected/rejected
}
virtual
void
ClientDisconnected(
DWORD
dwUniqueID ,
const
char
* szIP ,
int
iPort )
{
cout<<
"Client : "
<< szIP <<
" port : "
<<iPort<<
" status: disconnected"
<<endl;
}
};
int
_tmain(
int
argc, _TCHAR* argv[])
{
oConnection notify;
ISQLiteServer *psql = NULL;
TCHAR
szBasePath[1024];
_tstring base;
_tstring sdll;
size_t
found;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Get this modules path
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if
( !GetModuleFileName( GetModuleHandle(NULL) , szBasePath , 1024 ) )
return
( 0 );
base = szBasePath;
if
( (found = base.rfind( TEXT(
"\\"
) )) == base.npos )
return
( 0 );
base.erase( base.begin()+found+1 , base.end() );
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Get Interface to IID_ISQLiteServer
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sdll = base;
sdll+= TEXT(
"SQLQueryAS.dll"
);
if
( !g_plugins.LoadPlugin(sdll.c_str() , IID_ISQLiteServer , (
void
**)&psql ) )
{
cout<<
"error loading plugin"
<<endl;
}
if
( !psql )
return
( 0 );
//set path to the security database
psql->SetSecurityDatabase(
"c:\\databases\\security.db"
);
//[optional] adding the above interface to see who connects to the server
psql->observer_add( (IConnectionObserver*)?ify );
//start server port 6603 and true to start a new thread
//if the second parameter is fase the function locks
//6603 is the default port and true is the default
psql->StartServer( 6603 ,
true
);
cout<<
"Enter q to exit"
<<endl;
while
( _gettch() != (
int
)
'q'
);
psql->StopServer();
psql->Release();
psql = NULL;
return
( 0 );
}