Solved

symbolic link for createfile and deviceiocontrol query

Posted on 2004-09-09
21
505 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:mmurat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 10
21 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 12020620
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12020643
The third parameter being the length of the receive buffer...
QueryDosDevice(regkey, symlink, Len(symlink))
0
 

Author Comment

by:mmurat
ID: 12020688
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:mmurat
ID: 12020751
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
 

Author Comment

by:mmurat
ID: 12022256
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12022755
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
 

Author Comment

by:mmurat
ID: 12022790
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12022801
2. Make sure that NOISE_LEVEL = &HFF03003C is the correct value.  I could not find anything referring to this constant.
0
 

Author Comment

by:mmurat
ID: 12022808
yep. It is correct value. It is spesific to Javelin.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12022927
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
 

Author Comment

by:mmurat
ID: 12022951
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12023220
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
 

Author Comment

by:mmurat
ID: 12024125
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12025530
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
 

Author Comment

by:mmurat
ID: 12026947
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12028339
OK,

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

IOCTL_NDIS_QUERY_GLOBAL_STATS = &H170002

Hope it helps!
0
 

Author Comment

by:mmurat
ID: 12029212
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12030091
Great, glad it's working.

Good luck!
0
 

Author Comment

by:mmurat
ID: 12092442
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12104079
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
 

Author Comment

by:mmurat
ID: 12251610
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

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question