I current working on this dll, but i found the dll doesn't response to any of the cdatabase execute response? I have try all the cdatabase and sql in c++ console and found that it can be run. The database is open success and the sql statement is correct.
After then i put it into the dhcp callout dll, and compile success.
When i add it into the registry and try the dhcp server, it doesn't have any response database table. And i using sql server for the dsn.
Here is my code
include "stdafx.h"
include "callout.h"
ifdef _DEBUG
define new DEBUG_NEW
endif
CDatabase dbCallout;
struct tm *newtime;
char ampm[] = "AM";
_time64t longtime;
CString strCmd, strPrimaryKey, strTime;
int nRetCode = 0;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ulreasonforcall,
LPVOID lpReserved )
{
switch (ulreasonforcall)
{
case DLLPROCESSATTACH:
break;
case DLLTHREADATTACH:
break;
case DLLTHREADDETACH:
break;
case DLLPROCESSDETACH:
break;
} return TRUE;
}
DWORD CALLBACK DhcpControlHook(DWORD dwControlCode,LPVOID lpReserved)
{
switch (dwControlCode)
{
case DHCPCONTROLSTART: {
time64( &longtime ); /* Get time as long integer. /
newtime = _localtime64(&long_time); / Convert to local time. */
if( newtime->tmhour > 12 ) /* Set up extension. */
strcpy( ampm, "PM" );
if( newtime->tmhour > 12 ) /* Convert from 24-hour */
newtime->tmhour -= 12; /* to 12-hour clock. /
if( newtime->tm_hour == 0 ) /Set hour to 12 if midnight. */
newtime->tm_hour = 12;
strPrimaryKey.Format("C%.2d%.2d%.2d%.2d%.2d%.2d", newtime->tmyear - 100, newtime->tmmon, newtime->tmmday, newtime->tmhour, newtime->tmmin, newtime->tmsec);
strTime = asctime(newtime);
strCmd = "INSERT INTO CalloutControl (controlid, controldesc, controldate) VALUES ('" + strPrimaryKey + "', 'DHCP server have started!', '" + strTime + "')";
dbCallout.ExecuteSQL(strCmd);
dbCallout.Close();
break;
}
case DHCPCONTROLSTOP:
{
break;
}
case DHCPCONTROLPAUSE:
{
break;
}
case DHCPCONTROLCONTINUE:
{
break;
}
}
return ERROR_SUCCESS;
}
DWORD CALLBACK DhcpServerCalloutEntry(LPWSTR ChainDlls,DWORD CalloutVersion,LPDHCPCALLOUTTABLE CalloutTbl)
{
CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpControlHook=DhcpControlHook;
CalloutTbl->DhcpDeleteClientHook=DhcpDeleteClientHook;
CalloutTbl->DhcpPktDropHook=DhcpPktDropHook;
CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpNewPktHook=DhcpNewPktHook;
CalloutTbl->DhcpPktSendHook=DhcpPktSendHook;
dbCallout.Open(_T("CALLOUT"), FALSE, FALSE, _T("ODBC;"));
return ERROR_SUCCESS;
}
What wrong in this code? Can dll file insert new row into dsn? Some expert please help me!!!
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).