API found in C# but not VB?

G

Guest

i really hope im just overlooking something very simple bc i have an API call
in VB.net that doesnt work, yet the same call in C# works....in VB i get an
error saying the Entry Point cannot be found....code below

[DllImport("setupapi.dll", SetLastError=true)]
static extern unsafe int SetupDiGetDeviceInterfaceDetail(
int DeviceInfoSet,
ref SP_DEVICE_INTERFACE_DATA lpDeviceInterfaceData,
int* aPtr,
int detailSize,
ref int requiredSize,
int* bPtr);


[DllImport("setupapi.dll", SetLastError=true)]
static extern unsafe int SetupDiGetDeviceInterfaceDetail(
int DeviceInfoSet,
ref SP_DEVICE_INTERFACE_DATA lpDeviceInterfaceData,
ref PSP_DEVICE_INTERFACE_DETAIL_DATA myPSP_DEVICE_INTERFACE_DETAIL_DATA,
int detailSize,
ref int requiredSize,
int* bPtr);

SetupDiGetDeviceInterfaceDetail(
hDevInfo,
ref mySP_DEVICE_INTERFACE_DATA,
null,
DeviceInterfaceDetailDataSize,
ref RequiredSize,
null);


Friend Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll"
(ByVal DeviceInfoSet As Integer, _

ByRef lpDeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, _

ByRef myPSP_DEVICE_INTERFACE_DETAIL_DATA As
PSP_DEVICE_INTERFACE_DETAIL_DATA, _

ByVal detailSize As Integer, ByRef requiredSize As Integer, _

ByRef bPtr As Integer) As Integer

Friend Declare Function SetupDiGetDeviceInterfaceDetail Lib
"setupapi.dll" (ByVal DeviceInfoSet As Integer, _

ByRef lpDeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, _

ByRef aPtr As Integer, ByVal detailSize As Integer, _

ByRef requiredSize As Integer, ByRef bPtr As Integer) As Integer

Dim results As Integer = SetupDiGetDeviceInterfaceDetail(hDevInfo,
myInfo, myPspInfo, DeviceInterfaceDetailDataSize, _

RequiredSize, Nothing)
 
C

Cor Ligthert [MVP]

iwdu,

There is one big difference between C# and VB .Net. C# can handle unsafe
code.

You are sure that this is not your problem.

Cor
 
J

Jay B. Harlow [MVP - Outlook]

iwdu15,
Consider using IntPtr rather then unsafe int* in your C#; as Cor suggests VB
doesn't allow unsafe per se. Instead VB relies on IntPtr & the
System.Runtime.InteropServices.Marshal class to safely do "unsafe" things...

Normally I use www.pinvoke.net to find my DllImport/Declare statements. For
example your routine taken from:

http://www.pinvoke.net/default.aspx/setupapi/SetupDiGetDeviceInterfaceDetail.html

would be:

[DllImport(@"setupapi.dll", CharSet=CharSet.Auto, SetLastError = true)]
public static extern Boolean SetupDiGetDeviceInterfaceDetail( IntPtr
hDevInfo, ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData, IntPtr
deviceInterfaceDetailData, UInt32 deviceInterfaceDetailDataSize, out UInt32
requiredSize, IntPtr deviceInfoData );


Which then translates into something like (untested, manually translated):


Public Declare Auto Function SetupDiGetDeviceInterfaceDetail Lib
"setupapi.dll" (ByVal hDevInfo As IntPtr, ByRef deviceInterfaceData As
SP_DEVICE_INTERFACE_DATA, ByVal deviceInterfaceDetailData As IntPtr, ByVal
deviceInterfaceDetailDataSize As UInt32, ByRef requiredSize As UInt32, ByVal
deviceInfoData As IntPtr) As Boolean



--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
|i really hope im just overlooking something very simple bc i have an API
call
| in VB.net that doesnt work, yet the same call in C# works....in VB i get
an
| error saying the Entry Point cannot be found....code below
|
| [DllImport("setupapi.dll", SetLastError=true)]
| static extern unsafe int SetupDiGetDeviceInterfaceDetail(
| int DeviceInfoSet,
| ref SP_DEVICE_INTERFACE_DATA lpDeviceInterfaceData,
| int* aPtr,
| int detailSize,
| ref int requiredSize,
| int* bPtr);
|
|
| [DllImport("setupapi.dll", SetLastError=true)]
| static extern unsafe int SetupDiGetDeviceInterfaceDetail(
| int DeviceInfoSet,
| ref SP_DEVICE_INTERFACE_DATA lpDeviceInterfaceData,
| ref PSP_DEVICE_INTERFACE_DETAIL_DATA myPSP_DEVICE_INTERFACE_DETAIL_DATA,
| int detailSize,
| ref int requiredSize,
| int* bPtr);
|
| SetupDiGetDeviceInterfaceDetail(
| hDevInfo,
| ref mySP_DEVICE_INTERFACE_DATA,
| null,
| DeviceInterfaceDetailDataSize,
| ref RequiredSize,
| null);
|
|
| Friend Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll"
| (ByVal DeviceInfoSet As Integer, _
|
| ByRef lpDeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, _
|
| ByRef myPSP_DEVICE_INTERFACE_DETAIL_DATA As
| PSP_DEVICE_INTERFACE_DETAIL_DATA, _
|
| ByVal detailSize As Integer, ByRef requiredSize As Integer, _
|
| ByRef bPtr As Integer) As Integer
|
| Friend Declare Function SetupDiGetDeviceInterfaceDetail Lib
| "setupapi.dll" (ByVal DeviceInfoSet As Integer, _
|
| ByRef lpDeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, _
|
| ByRef aPtr As Integer, ByVal detailSize As Integer, _
|
| ByRef requiredSize As Integer, ByRef bPtr As Integer) As Integer
|
| Dim results As Integer = SetupDiGetDeviceInterfaceDetail(hDevInfo,
| myInfo, myPspInfo, DeviceInterfaceDetailDataSize, _
|
| RequiredSize, Nothing)
| --
| -iwdu15
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top