如何不弹出控制面板的选项,而直接在VB5程序中获得modem名称?

bobu 2000-01-24 05:14:00
如在VB5程序中List中列出控制面板上配置的所有modem名称.
mabu@163.net
...全文
233 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
maple 2000-01-25
  • 打赏
  • 举报
回复
MSDN 对RasEnumDevices的完全解释:
RasEnumDevices
The RasEnumDevices function returns the name and type of all available RAS-capable devices.

DWORD RasEnumDevices(
LPRASDEVINFO lpRasDevInfo, // buffer to receive information about
// RAS devices
LPDWORD lpcb, // size, in bytes, of the buffer
LPDWORD lpcDevices // receives the number of entries
// written to the buffer
);

Parameters
lpRasDevInfo
Pointer to a buffer that receives an array of RASDEVINFO structures, one for each RAS-capable device. Before calling the function, set the dwSize member of the first RASDEVINFO structure in the buffer to sizeof(RASDEVINFO) to identify the version of the structure.
lpcb
Pointer to a variable that contains the size, in bytes, of the lpRasDevInfo buffer. On return, the function sets this variable to the number of bytes required to enumerate the devices.
To determine the required buffer size, call RasEnumDevices with the lpRasDevInfo parameter set to NULL and the variable pointed to by lpcb set to zero. The function returns the required buffer size in the variable pointed to by lpcb.

lpcDevices
Pointer to a variable that the function sets to the number of RASDEVINFO structures written to the lpRasDevInfo buffer.
Return Values
If the function succeeds, the return value is zero.

If the function fails, the return value is a nonzero RAS error value or one of following error codes.

Value Meaning
ERROR_BUFFER_TOO_SMALL The lpRasDevInfo buffer is not large enough. The function returns the required buffer size in the variable pointed to by lpcb.
ERROR_NOT_ENOUGH_MEMORY Indicates insufficient memory.
ERROR_INVALID_PARAMETER Indicates an invalid parameter value.
ERROR_INVALID_USER_BUFFER The address or buffer specified by lpRasDevInfo is invalid.


QuickInfo
Windows NT: Requires version 4.0 or later.
Windows: Requires Windows 95 OSR2 or later.
Windows CE: Unsupported.
Header: Declared in ras.h.
Import Library: Use rasapi32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

maple 2000-01-25
  • 打赏
  • 举报
回复
用PORT控件,向各个COM口发出ATI1指令,收到的信息就用MODEM的型号
zm 2000-01-25
  • 打赏
  • 举报
回复
可以查询注册表来取得Modem的名称,将以下代码粘贴至Form中试一试:
Option Explicit
Const REG_SZ As Long = 1
Const REG_DWORD As Long = 4
Const REG_BINARY As Long = 3
Const HKEY_LOCAL_MACHINE = &H80000002
Const KEY_ALL_ACCESS = &H3F
Const REG_OPTION_NON_VOLATILE = 0
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As_ Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias_ "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal_ ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias_ "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String,_ ByVal lpReserved As Long, lpType As Long, ByVal lpData As String,_ lpcbData As Long) As Long
Private Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias_ "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String,_ ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As_ Long) As Long
Private Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias_ "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String,_ ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData_ As Long) As Long
Private Sub Command1_Click()
Dim ret As Variant
Dim i As Integer
For i = 0 To 9
QueryValue "System\CurrentControlSet\Services\Class\Modem\000" & i,_ "DriverDesc", HKEY_LOCAL_MACHINE, ret
If Len(ret) > 0 Then
ret = Left(ret, Len(ret) - 1)
MsgBox (ret)
End If
Next i '假设最多有10个Modem,你见过装有11个Modem的计算机吗?
End Sub

Public Function QueryValue(sKeyName As String, sValueName As String,_ lPredefinedKey As Long, zm As Variant) As Variant
Dim lRetVal As Long '
Dim hKey As Long
Dim vValue As Variant
lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS,_ hKey)
lRetVal = QueryValueEx(hKey, sValueName, vValue)
QueryValue = vValue
zm = vValue
RegCloseKey (hKey)
End Function
Private Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As_ String, vValue As Variant) As Long
Dim cch As Long
Dim lrc As Long
Dim lType As Long
Dim lValue As Long
Dim sValue As String
lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
sValue = String(cch, 0)
lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
vValue = Left$(sValue, cch)
End Function
'如有问题给我来信:coolzm@sohu.com
littletao 2000-01-25
  • 打赏
  • 举报
回复
应该支持win98的,以下是msdn中RasEnumDevices的说明:

QuickInfo
Windows NT: Requires version 4.0 or later.
Windows: Requires Windows 95 OSR2 or later.
Windows CE: Unsupported.
Header: Declared in ras.h.
Import Library: Use rasapi32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.
在api viewer里没有,可以自己写api的声明。

bobu 2000-01-24
  • 打赏
  • 举报
回复
对于rmh的说明,我想window's98 or 95上应当有,我曾试着用modem.cpl 添加一调制解调器,发现在sytem.dat中产生了变化,可惜找不着规律.
rmh 2000-01-24
  • 打赏
  • 举报
回复
在WindowNT上有,Windows 95 不支持
bobu 2000-01-24
  • 打赏
  • 举报
回复
win32api中没有RasEnumDevices函数,Where? Thanks
xubin_sh 2000-01-24
  • 打赏
  • 举报
回复
用RasEnumDevices函数

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧