Problem: Can dhcp callout dll insert new row into

cpp.net Malaysia
  • 15 years ago

    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 (ul
    reasonforcall)
    {
    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( am
    pm, "PM" );
    if( newtime->tmhour > 12 ) /* Convert from 24-hour */
    newtime->tm
    hour -= 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!!!

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Engineers are all basically high-functioning autistics who have no idea how normal people do stuff.” - Cory Doctorow