473,785 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DHCP Server Management API Functions with P/Invoke

I'm trying to get the number of clients on every subnet using
DhcpEnumSubnetC lients on every subnet returned by DhcpEnumSubnets . The
problem is that I don't understand how to declare the .Net wrapper from the
win32 C++ functions.

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Runtime. InteropServices ;

namespace DHCPLeases
{
class Program
{
struct DHCP_IP_ARRAY
{
public uint NumElements;
public IntPtr IPAddresses;
}

[DllImport("dhcp sapi.dll")]
private static extern uint DhcpEnumSubnets (
string ServerIP,
ref uint resumeHandle, ulong PerferedMax,
ref DHCP_IP_ARRAY ipAddresses,
ref uint ElementsRead,
ref uint ElementsTotal);

static void Main(string[] args)
{
DHCP_IP_ARRAY ips = new DHCP_IP_ARRAY() ;
uint nr=0,total=0, resumeHandle =0;
DhcpEnumSubnets ("10.100.1.6",r ef resumeHandle , 1000, ref ips,
ref nr,ref total);
}
}
}

Throws:
PInvokeStackImb alance was detected
Message: A call to PInvoke function
'DHCPLeases!DHC PLeases.Program ::DhcpEnumSubne ts' has unbalanced the stack.
This is likely because the managed PInvoke signature does not match the
unmanaged target signature. Check that the calling convention and parameters
of the PInvoke signature match the target unmanaged signature.

Please help.
Apr 19 '06 #1
2 3864
> [DllImport("dhcp sapi.dll")]
private static extern uint DhcpEnumSubnets (
string ServerIP,
ref uint resumeHandle, ulong PerferedMax,
ref DHCP_IP_ARRAY ipAddresses,
ref uint ElementsRead,
ref uint ElementsTotal);


PreferredMax should be an uint.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 19 '06 #2
Hi, Mattias and thanks for your help!

changing PreferredMatx to an uint kind of solved the problem. The wrapper
declaration now seemes to be ok, but I'm not getting any subnets in response.

class Program
{
struct DHCP_IP_ARRAY
{
public uint NumElements;
public IntPtr IPAddresses;
}

[DllImport("dhcp sapi.dll")]
private static extern uint DhcpEnumSubnets (
string ServerIP,
ref uint resumeHandle, uint PerferedMax,
ref DHCP_IP_ARRAY ipAddresses,
ref uint ElementsRead,
ref uint ElementsTotal);

static void Main(string[] args)
{
DHCP_IP_ARRAY ips = new DHCP_IP_ARRAY() ;
uint nr=0,total=0, resumeHandle =0;

DhcpEnumSubnets ("10.100.1.1 ", ref resumeHandle, 1000, ref ips,
ref nr, ref total);
Console.WriteLi ne("Elements read {0} of total {1}", nr, total);

}
}

"Mattias Sjögren" wrote:
[DllImport("dhcp sapi.dll")]
private static extern uint DhcpEnumSubnets (
string ServerIP,
ref uint resumeHandle, ulong PerferedMax,
ref DHCP_IP_ARRAY ipAddresses,
ref uint ElementsRead,
ref uint ElementsTotal);


PreferredMax should be an uint.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Apr 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2148
by: Marco | last post by:
Hi to all I've a simple question...It's possible to configure and manage DHCP and DNS serve via Visual Basic .NET I need to create a simple application in Visual Basic that allow to manage DHCP and DN server Has someone some ideas Thanks in advance, Marco
3
1312
by: Leszek Gruszka | last post by:
How to get static IP adresses from DHCP?
5
6502
by: Steve | last post by:
Hi Folks, I'm trying to create a c# class to manage a DHCP subnet using the win api (dhcpsapi.dll). Currently I can't even instanciate my class, instead I receive the error: System.TypeLoadException. Does anybody have experience working with this API from C# or know of some documentation/examples? Thanks in advance. steve.
2
3053
by: WhatHappend | last post by:
I have converted a .Net 1.0 application to .Net 2.0 and the web service invocations have delay of around 10seconds on each intial access. After the first access subsequent access are fast (After a whild of inactivity the next access will be slow agian). Changing the client to static IP address instead of DHCP makes the initial access about 1 second which is fine. Monitoring the network of the client computer the cleint is sending out 2...
5
7654
by: Richard | last post by:
Hello, I'm working on an application to allow our network team to use a small application to make DHCP reservations on our Microsoft DHCP Server. The problem is you have to use P/Invoke to do it, and from what I've found on the web and in this newsgroup is that it's not easy, however I believe it can/has been done. At the moment I'm just trying to find out information about an existing
0
2970
by: GHUM | last post by:
Hello, I need to get a list of active leases on a windows dhcp server. Experts from Microsoft statet: """" A: Go to the Address leases of each scope in the DHCP snap-in and dump the leases to a text file from the DHCP server snap-in. The text file gives you all the information for every active lease. You might also
1
11142
by: Screenbert | last post by:
After finding nothing anywhere in google I am posting this so everyone can benefit by it. The formating is not pretty since I copied it from my word document, but you should benefit by it. Managing DHCP Servers using C# They said it was impossible. It couldn't be done. But you can in fact manage DHCP servers using C#. This includes creating and deleting Scopes, SuperScopes, Reservations, Exclusions, Options and so forth. Since the dll...
0
12359
by: screenbert | last post by:
Managing DHCP Servers using C# They said it was impossible. It couldn't be done. But you can in fact manage DHCP servers using C#. This includes creating and deleting Scopes, SuperScopes, Reservations, Exclusions, Options and so forth. Since the dll that is used was written several years ago by Microsoft, you cannot manage things on the DNS tab when looking at a reservation and few things such as that however it gives you main things you...
0
1690
cyberking
by: cyberking | last post by:
Hi all, Firstly, I am very little knowledgible when it comes to Windows OS (Client OS or Server OS). But offlate my urge to get myself in terms with it increased and soon I was meddling with the various services offered by Win Server 2003. Ok. Now here s the scenario. Firstly I have a Huawei Router with DHCP enabled in it. And then I have 'bout 5 machines at home which I intended to set up as a network and make one of the machines a Monster...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.