symbolic link for createfile and deviceiocontrol query

Hi there,
I need help!
I have a project; I have to write a software for wireless client card.
But i have a couple of problem.

1)symbolic link;
I am advised to get the wireless card key from NetCfgInstanceId key in registry. I can get it.
But I am told to use QueryDosDevice(NetCfgInstanceId, buf, size) to find symbolic link. But i coulndnt make it work.
Here is my code for it;

'***********************
Dim symlink As String
Dim nret As Long

nret = QueryDosDevice(regkey, symlink, 40)
'---------------------------------------------------
nret always gets 0
I could just receive something(nret value changes). When i define  "symlink() as byte".
But still not no symbolic link.

2)I have to use this symbolic link in deviceiocontrol to get NOISE_LEVEL from wireless card.
&HFF03003C stand NOISE_LEVEL
Dim nret As Long
Dim outbuffer() As Byte

oret = DeviceIoControl(hDevice, &HFF03003C, 0&, 0&, buff, Len(buff), lpret, 0&)
'************
oret always returns zero


I am sure i am missing sth in data types or sth.. But i couldnt find out.
I will be pleased if you guys help me to correct the code.
Thank you anyways.
mmuratAsked:
Who is Participating?
 
Erick37Connect With a Mentor Commented:
Dim symlink As String
Dim nret As Long

symlink = Space(255) '<< You need to allocate the buffer first to some size

nret = QueryDosDevice(regkey, symlink, 40)

debug.print err.lastdllerror '<< Check for specific error number here right after the API call
0
 
Erick37Commented:
The third parameter being the length of the receive buffer...
QueryDosDevice(regkey, symlink, Len(symlink))
0
 
mmuratAuthor Commented:
well yes..
regkey's value is {D290989F-E386-4A37-885D-C896B6A34B00}

 I got this for symlink's value. But is it a true symbolic link name? It seems like an alias to the hardware.
\Device\{D290989F-E386-4A37-885D-C896B6A34B00}

Thank you very much
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mmuratAuthor Commented:
So it means maybe my regkey variable holds the symbolic link to the device. Since querydosdevice returns the alias of device.
Could it be?
0
 
mmuratAuthor Commented:
Do u have any recorrection about deviceiocontrol call?
2)I have to use this symbolic link in deviceiocontrol to get NOISE_LEVEL from wireless card.
&HFF03003C stand NOISE_LEVEL
Dim nret As Long
Dim buff() As Byte

oret = DeviceIoControl(hDevice, &HFF03003C, 0&, 0&, buff, Len(buff), lpret, 0&)
'************
oret always returns zero

err.lastdllerror gives error "1"
Thanx anyways
0
 
Erick37Commented:
Error 1 means "Invalid Function" - whatever that means.

I'm not very familiar with this API, but I will try to help.

1. Firstly, reading the documentation from MSDN it says that hDevice is a handle derived from a call to CreateFile.  Make sure that the handle is valid (not 0).

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/deviceiocontrol.asp
0
 
mmuratAuthor Commented:
yes, I receive none zero handler from createfile function. So it works.

something wrong with deviceiocontrol.
Maybe I have to put "IOCTL_NDIS_QUERY_GLOBAL_STATS" as second parametre and 3rd parametre the OID_NOISE_LEVEL and 4th the length of OID.
5th and 6th return value and length and so on.

To make a test i couldnt find IOCTL_NDIS_QUERY_GLOBAL_STATS 's hex code.
&#305; am still searching.
0
 
Erick37Commented:
2. Make sure that NOISE_LEVEL = &HFF03003C is the correct value.  I could not find anything referring to this constant.
0
 
mmuratAuthor Commented:
yep. It is correct value. It is spesific to Javelin.
0
 
Erick37Commented:
IOCTL_NDIS_QUERY_GLOBAL_STATS is defined in the file ntddndis.h which is part of the Windows DDK (which I do not have).
Could not find any value for this const through a search on the internet.
0
 
mmuratAuthor Commented:
I can send the file ntddndis.hif you want. I copied from ntddndis.h.
#define _NDIS_CONTROL_CODE(request,method) \
            CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, request, method, FILE_ANY_ACCESS)

#define IOCTL_NDIS_QUERY_GLOBAL_STATS   _NDIS_CONTROL_CODE(0, METHOD_OUT_DIRECT)
#define IOCTL_NDIS_QUERY_ALL_STATS      _NDIS_CONTROL_CODE(1, METHOD_OUT_DIRECT)
0
 
Erick37Commented:
Does your documentation give any indication of the size of the buffer when you use NOISE_LEVEL?

Private Declare Function DeviceIoControl Lib "kernel32" _
  (ByVal hDevice As Long, _
   ByVal dwIoControlCode As Long, _
   lpInBuffer As Any, _
   ByVal nInBufferSize As Long, _
   lpOutBuffer As Any, _
   ByVal nOutBufferSize As Long, _
   lpBytesReturned As Long, _
   lpOverlapped As Any) As Long

Private Const NOISE_LEVEL = &HFF03003C
Private Const BUFFER_SIZE = '??? < need this value

Dim Buff(BUFFER_SIZE) As Byte
Dim oret As Long, lpret As Long

oret = DeviceIoControl(hDevice, NOISE_LEVEL, ByVal 0&, 0&, Buff(0), BUFFER_SIZE, lpret, ByVal 0&)

Debug.Print err.getlastdllerror 'Hope it's 0
0
 
mmuratAuthor Commented:
well, I dont have  NOISE_LEVEL buffer size.
I have found OIDscope software to test this NOISE_LEVEL. And IT was working.It gives me the right value.
So I am sure it is right hex code. But i dont have any idea about buffer size.
0
 
Erick37Commented:
Well, since lpret will contain the number of bytes returned from the call, maybe you can set BUFFER_SIZE to some arbitrary large number (255) just to test.  Then check the value of lpret.  This number will tell you how much data was placed in the buffer.
0
 
mmuratAuthor Commented:
well,lpret returns zero.
I have found this syntax;
DeviceIoControl(m_hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, &m_oid, sizeof(m_oid), m_buffer,m_bufLen,    &neededLen, NULL);

So, I think i have to modify my deviceiocontrol syntax. But how should i define IOCTL_NDIS_QUERY_GLOBAL_STATS?
do you have any idea?
0
 
Erick37Commented:
OK,

I compiled a CPP program and this is the value it spit out:

IOCTL_NDIS_QUERY_GLOBAL_STATS = &H170002

Hope it helps!
0
 
mmuratAuthor Commented:
Hi Erick,
And thank you very much.
I am getting happy now. Since Finally I get Err.LastDllError as "0".:)
And it returns me correct value i took it from  Hex(outbuffer(0)).
I had changed to code to the following.

Private Const IOCTL_NDIS_QUERY_GLOBAL_STATS = &H170002
Private Const OID_NOISE_LEVEL = &HFF03003C

Dim nret As Long
Dim outbuffer(4096) As Byte
nret = DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, OID_NOISE_LEVEL, 4, outbuffer(0), 4096, lpret, 0&)

msgbox Hex(outbuffer(0))

It is the real value what i want
Now i can write my software...
0
 
Erick37Commented:
Great, glad it's working.

Good luck!
0
 
mmuratAuthor Commented:
Hello again,

Everything works fine when querying by deviceiocontrol.
But now i have another problem to solve. IT is; i need to associate the card to a network and get the noise.
getting noise is not a problem But association is the problem. Since after my tests i could just make card disconnect from a network even I give the SSID correct. But it is coz of data types. I use prism OID. They work for both SET and Querying.

This is the data type of  802_11_SSID OID.

Public Const OID_802_11_SSID = &HFF030102

typedef UCHARNDIS_802_11_SSID;
{
  ULONG  SsidLength;
  UCHAR  Ssid[32];
} NSID_802_11_SSID, *PNDIS_802_11_SSID;

'vb form
Public Type testssid
    length As long
    ssid(32) As Byte
End Type

dim setssid as testssid

     setssid.length = 7
     setssid.ssid(0) = &H41
     setssid.ssid(1) = &H69
     setssid.ssid(2) = &H72
     setssid.ssid(3) = &H74
     setssid.ssid(4) = &H69
     setssid.ssid(5) = &H65
     setssid.ssid(6) = &H73

' ssid is Airties
nret = DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, OID_802_11_SSID, 4, setssid, 36, lpret, 0&)
when i run this code, card disconnects from network. But it doesnt connect to Airties network either.
so what did i define wrong?
0
 
Erick37Commented:
You may try this:

1. There is a difference between how arrays are declared in C and in VB.
C:   UCHAR ssid[32]  means 32 bytes (indices 0 to 31)
VB: ssid(32) means 33 bytes (0 to 32)

So your type declaration may be incorrect. Try using:

'vb form
Public Type testssid
    length As long
    ssid(31) As Byte
End Type

2. Instead of hard coding the value of 36 for nOutBufferSize, use LenB(setssid).

Hope it helps!
0
 
mmuratAuthor Commented:
thank you.

I have another question. How can i detect an ADSL modem via ethernet interface. here is the link. Erick, I think you can give me an idea.
thank you anyway.
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21156943.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.