Problem with call a WinAPI Function Dhcpcsvc.dll DhcpRequest

Announcements and discussion for PInvoke

Moderators: Luke Jefferson, Robert

Problem with call a WinAPI Function Dhcpcsvc.dll DhcpRequest

Postby live2 » Sat Feb 23, 2008 4:00 pm

Problem with call a WinAPI Function Dhcpcsvc.dll DhcpRequestParams

Error Message Sorry i have it only in German
Ein Aufruf an die PInvoke-Funktion "WindowsApplication1!WindowsApplication1.Form1::DhcpRequestParams" hat das Gleichgewicht des Stapels gestört. Wahrscheinlich stimmt die verwaltete PInvoke-Signatur nicht mit der nicht verwalteten Zielsignatur überein. Überprüfen Sie, ob die Aufrufkonvention und die Parameter der PInvoke-Signatur mit der nicht verwalteten Zielsignatur übereinstimmen.



Code: Select all
        const byte DHCPCAPI_REQUEST_PERSISTENT = 0x01;
        const byte DHCPCAPI_REQUEST_SYNCHRONOUS = 0x02;
        const byte DHCPCAPI_REQUEST_ASYNCHRONOUS = 0x04;
        const byte DHCPCAPI_REQUEST_CANCEL = 0x08;
        const byte DHCPCAPI_REQUEST_MASK = 0x0F;

        public struct DHCPCAPI_CLASSID
        {
            public int Flags;
            public byte Data;
            public int nBytesData;
        }

        public struct DHCPCAPI_PARAMS
        {
            public int Flags;
            public int OptionId;
            public bool IsVendor;
            public byte Data;
            public int nBytesData;
        }

        public struct DHCPCAPI_PARAMS_ARRAY
        {
            public int nParams;
            public DHCPCAPI_PARAMS Params;
        }

        [DllImport("Dhcpcsvc.dll")]
        public static extern int DhcpRequestParams(uint Flags, IntPtr Reserved, [MarshalAs(UnmanagedType.LPWStr)] string AdapterName, DHCPCAPI_CLASSID ClassId, DHCPCAPI_PARAMS_ARRAY SendParams, ref DHCPCAPI_PARAMS_ARRAY RecdParams, string Buffer, ref uint pSize, [MarshalAs(UnmanagedType.LPWStr)] string RequestIdStr);

        private void button1_Click(object sender, EventArgs e)
        {

            DHCPCAPI_PARAMS DhcpApiHostNameParams = new DHCPCAPI_PARAMS();
            DhcpApiHostNameParams.Flags = 0;
            DhcpApiHostNameParams.OptionId = 66;
            DhcpApiHostNameParams.IsVendor = false;
            DhcpApiHostNameParams.Data = new byte();
            DhcpApiHostNameParams.nBytesData = 0;

            DHCPCAPI_PARAMS_ARRAY SendParams = new DHCPCAPI_PARAMS_ARRAY();
            SendParams.nParams = 0;
            SendParams.Params = new DHCPCAPI_PARAMS();

            DHCPCAPI_PARAMS_ARRAY RecdParams = new DHCPCAPI_PARAMS_ARRAY();
            RecdParams.nParams = 1;
            RecdParams.Params = DhcpApiHostNameParams;

            IntPtr Reserved = new IntPtr();
            DHCPCAPI_CLASSID ClassId = new DHCPCAPI_CLASSID();
            uint pSize = 1;

            DhcpRequestParams(1, Reserved, "VMWare Accelerated AMD PCNet Adapter", ClassId, SendParams, ref RecdParams, "", ref pSize, "1");
live2
 
Posts: 1
Joined: Sat Feb 23, 2008 3:55 pm

Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests