C++ to C#

29/11/2007 - 11:38 von Frank Matthiesen | Report spam
Hallo NG,

ich habe hier ein C++-CodeSnippet, welches ich nach C# portieren
möchte/muss.
Das ganze geht ums aufrufen zweier (mehr oder weniger undokumentierten)
Unmanaged-C++-Dlls per pinvoke
Kann mir dabei jemand helfen...beisse mir die Zàhne aus und bekomme die
Krise bei diesen "Pointern"
(Am Ende brauch ich's in VB.Net...aber von C# bekomme ich's alleine
portiert)

Gruesse

Frank

Ich benötige "nur" die richtigen Funktionsdeklarationen / Aufrufe

<Code>
#define MAX_ADAPTER_DESCRIPTION_LENGTH 128
#define MAX_ADAPTER_NAME_LENGTH 256
#define MAX_ADAPTER_ADDRESS_LENGTH 8

typedef struct _IP_ADAPTER_INFO {
struct _IP_ADAPTER_INFO* Next;
DWORD ComboIndex;
char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
UINT AddressLength;
BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
DWORD Index;
UINT Type;
UINT DhcpEnabled;
PIP_ADDR_STRING CurrentIpAddress;
IP_ADDR_STRING IpAddressList;
IP_ADDR_STRING GatewayList;
IP_ADDR_STRING DhcpServer;
BOOL HaveWins;
IP_ADDR_STRING PrimaryWinsServer;
IP_ADDR_STRING SecondaryWinsServer;
time_t LeaseObtained;
time_t LeaseExpires;
} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;

typedef enum _SAVEACTION {
POWER_DONT_SAVE = 0,
POWER_PRE_SAVE,
POWER_POST_SAVE
} SAVEACTION;

typedef enum _RADIODEVTYPE {
POWER_MANAGED = 1,
POWER_PHONE,
POWER_BLUETOOTH,
} RADIODEVTYPE;

typedef struct _RDD {
LPTSTR pszDeviceName;
LPTSTR pszDisplayName;
DWORD dwState;
DWORD dwDesired;
RADIODEVTYPE DeviceType;
struct _RDD * pNext;
} RDD;

/////////////////////////////////////////////////////////////////
// functions to get from ossvcs.dll
/////////////////////////////////////////////////////////////////
// HRESULT GetWirelessDevices (RDD **pDevices, DWORD dwFlags) @276
#define GETWIRELESSDEVICES_ORDINAL ((LPCWSTR) 276)
typedef HRESULT (*GetWirelessDevices_type) (RDD **pDevices, DWORD dwFlags);
GetWirelessDevices_type pGetWirelessDevices = NULL;

// HRESULT ChangeRadioState (RDD *pDev, DWORD dwState, SAVEACTION sa) @273
#define CHANGERADIOSTATE_ORDINAL ((LPCWSTR) 273)
typedef HRESULT (*ChangeRadioState_type) (RDD *pDev, DWORD dwState,
SAVEACTION sa);
ChangeRadioState_type pChangeRadioState = NULL;

// void FreeDeviceList (RDD *pRoot) @280
#define FREEDEVICELIST_ORDINAL ((LPCWSTR) 280)
typedef void (*FreeDeviceList_type) (RDD *pRoot);
FreeDeviceList_type pFreeDeviceList = NULL;
/////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////
// functions to get from iphlpapi.dll
/////////////////////////////////////////////////////////////////
// DWORD GetAdaptersInfo (PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
typedef DWORD (*GetAdaptersInfo_type) (PIP_ADAPTER_INFO pAdapterInfo, PULONG
pOutBufLen);
GetAdaptersInfo_type pGetAdaptersInfo = NULL;
/////////////////////////////////////////////////////////////////

</code>
 

Lesen sie die antworten

#1 Carl Schaffert
29/11/2007 - 14:51 | Warnen spam
Hallo Frank,

schaue dir mal diese Namespaces und Klassen an,

http://msdn2.microsoft.com/de-de/li...system.net(VS.80).aspx

http://msdn2.microsoft.com/de-de/li...nformation(VS.80).aspx

http://msdn2.microsoft.com/de-de/li...kinterface(VS.80).aspx

da sind einige dabei die dir einen Teil der Arbeit schon abnehmen,
vielleicht hilfts dir ja ;-). Es sei denn, dass du unbedingt aus diesen
Dll's die Methoden benutzen musst.

Gruß Carl

Ähnliche fragen