Answered DHCP - dhcpsapi.dll - DhcpGetClientInfo - error 1781

  • Friday, April 20, 2007 7:16 AM
     
     

    Hello I have a big problem with the api DHCP Server. I would like to use the DhcpGetClientInfo api but sometimes it's work, sometimes not.

     

    this piece of code work very well but when I uncomment "// t_DhcpSetClientInfo _DhcpSetClientInfo=NULL;", DhcpGetClientInfo return an error 1781 "RPC_X_ENUM_VALUE_OUT_OF_RANGE" ??? Or when I put another variable before/after DhcpSetClientInfo. I don't understand why... Please help me.

     

    //---------------------------------------------------------------------------

    #include <vcl.h>
    #include <windows.h>
    #include "dhcpsapi.h"
    #pragma hdrstop

    //---------------------------------------------------------------------------

    typedef DWORD DHCP_API_FUNCTION (*t_DhcpGetClientInfo)(
      LPWSTR ServerIpAddress,
      DHCP_SEARCH_INFO* SearchInfo,
      LPDHCP_CLIENT_INFO *ClientInfo
    );
    typedef VOID DHCP_API_FUNCTION (*t_DhcpRpcFreeMemory)(
        PVOID BufferPointer
        );
    typedef DWORD DHCP_API_FUNCTION (*t_DhcpSetClientInfo)(
        DHCP_CONST WCHAR *ServerIpAddress,
        DHCP_CONST DHCP_CLIENT_INFO *ClientInfo
        );
    #pragma argsused
    WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
      int a;

      t_DhcpGetClientInfo _DhcpGetClientInfo;
      t_DhcpRpcFreeMemory _DhcpRpcFreeMemory;

      HMODULE hMod=LoadLibrary("c:\\windows\\system32\\dhcpsapi.dll");
      DHCP_SEARCH_INFO SearchInfo;
      SearchInfo.SearchType=2;
      SearchInfo.SearchInfo.ClientName=L"fab.";

      _DhcpGetClientInfo=(t_DhcpGetClientInfo)GetProcAddress(hMod,"DhcpGetClientInfo");
      _DhcpRpcFreeMemory=(t_DhcpRpcFreeMemory)GetProcAddress(hMod,"DhcpRpcFreeMemory");

      DHCP_CLIENT_INFO* info;

      a=_DhcpGetClientInfo(L"10.77.1.254",&SearchInfo,&info);
      _DhcpRpcFreeMemory(info);

     // t_DhcpSetClientInfo _DhcpSetClientInfo=NULL;
      FreeLibrary(hMod);
            return 0;

Answers

  • Tuesday, April 24, 2007 7:35 AM
     
     Answered

    Thanks a lot Eliot,

    your help was very invaluable :-) I have found my problem (you're right, I'm using borland c++ builder)...

     

    in dhcpsapi.h :

     

    #if (_MSC_VER >= 800)

    #define DHCP_API_FUNCTION    __stdcall

    #else

    #define DHCP_API_FUNCTION

    #endif

     

    DWORD DHCP_API_FUNCTION

    DhcpSetClientInfo(

    DHCP_CONST WCHAR *ServerIpAddress,

    DHCP_CONST DHCP_CLIENT_INFO *ClientInfo

    );

     

    _MSC_VER is not defined in the environement c++ builder !!! So all declaration of function header was wrong... Now yet I put a define like (#define _MSC_VER 1200) at the top of my code and all work very well :-)

     

    bye, bye

    Fabrice

All Replies

  • Sunday, April 22, 2007 9:33 PM
     
     

    Hi Fabrice,

     

    I'm sorry to hear you're having trouble with the DHCP server management API.  However, this forum is for Windows Peer-to-Peer networking related questions.  I'm trying to figure out which forum can best address your question (I'll probably have to wait until Monday when people are back at work).  In the meantime you can try posting your question on the microsoft.public.win32.programmer.networks newsgroup (web interface is - http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.win32.programmer.networks).

     

    There are a couple of things I don't understand in your code sample.  For example, why do you set SearchInfo.SearchType=2 instead of SearchInfo.SearchType = DhcpClientName?  Also, you appear to be using Borland C++ builder (judging by the #include <vcl.h>).  I don't have access to any Borland software so I can't try building your sample code in that environment.  I tried things out using the Microsoft Visual C++ Compiler (version  14.00.50727.220) and everything worked as expected.  Because I'm not running this on a DHCP server nothing much happened.  However, I could not get DhcpGetClientInfo() to return RPC_X_ENUM_VALUE_OUT_OF_RANGE.  According to MSDN documentation, if the value of a variable of type enum exceeds 32,767 then the RPC_X_ENUM_VALUE_OUT_OF_RANGE error will occur and the only enum you are using is SearchInfo.SearchType.  Have you checked the value of SearchInfo.SearchType in a debugger?  This might help you narrow down the source of the problem.

     

    Hopefully I can connect you with someone who can be more helpful tomorrow,

    Eliot

     

     

     

  • Monday, April 23, 2007 7:57 AM
     
     

    Hi Eliot,

    Thanks a lot for your response.

     

    I Have take a look about SearchInfoSearchInfo and his size in memory and everything seems oK. I don't know if that will be helpfully but I have take a look about dhcpcmd.exe and the function DhcpGetClientInfo is not reported. Why ???

     

    I took your advice and opened a new thread on http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.win32.programmer.networks. Must I close this one? If you can connect me with someone who can help me, that will be very nice from you.

     

    Fabrice

  • Monday, April 23, 2007 9:16 PM
     
     

    I assume you mean that you checked that SearchInfo.SearchType did not exceed 32,767 immediately before the call to DhcpGetClientInfo().  If this is the case then I don't know enough about your development environment (Borland C++ I assume?) or your execution environment (Windows Server 2003 I guess?) to suggest how to proceed.

     

    As for dhcpcmd.exe, DhcpGetClientInfo should not be reported as an available command.  dhcpcmd.exe is not meant to allow you to interactively call any particular function exported by dhcpsapi.dll.  It is intended to allow administrators to manage a DHCP server.  According to the documentation "EnumClients [some address scope] -v -h" is probably the closest thing to what you are trying to do.

     

    Apparently there is no forum for general networking related questions so microsoft.public.win32.programmer.networks is probably your best bet.  However, your problem does not seem to be related to any of the networking APIs.  Instead it appears to be an issue with your development environment.  You should probably try a forum/newsgroup for developer's using your particular compiler or IDE in addition to the microsoft newsgroup (if my guess that you are using Borland C++ is correct then http://support.borland.com/entry.jspa?entryID=292 might be a place to start).  You can also try an alternative compiler to see if it exhibits the same problem (for example, Visual Studio Express Editions are free to download - http://msdn.microsoft.com/vstudio/express/downloads/default.aspx).

     

    I hope this helps, your situation seems quite frustrating.  You don't have to close this thread but I don't think anyone in this forum knows enough about your particular problem to be able to help you very much.

     

    Sorry,

    Eliot

  • Tuesday, April 24, 2007 7:35 AM
     
     Answered

    Thanks a lot Eliot,

    your help was very invaluable :-) I have found my problem (you're right, I'm using borland c++ builder)...

     

    in dhcpsapi.h :

     

    #if (_MSC_VER >= 800)

    #define DHCP_API_FUNCTION    __stdcall

    #else

    #define DHCP_API_FUNCTION

    #endif

     

    DWORD DHCP_API_FUNCTION

    DhcpSetClientInfo(

    DHCP_CONST WCHAR *ServerIpAddress,

    DHCP_CONST DHCP_CLIENT_INFO *ClientInfo

    );

     

    _MSC_VER is not defined in the environement c++ builder !!! So all declaration of function header was wrong... Now yet I put a define like (#define _MSC_VER 1200) at the top of my code and all work very well :-)

     

    bye, bye

    Fabrice