|
A VB code snippet that uses RegEnumKeyEx runs OK on Win'98 (the function returns ERROR_SUCCESS) but fails on WinXP! Any ideas?
Thanks in advance,
Stefan B.
|
|
|
|
|
Try this, it works on WinXP:
Const ERROR_NO_MORE_ITEMS = 259&
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Sub Form_Load()
Dim hKey As Long, Cnt As Long, sName As String, sData As String, Ret As Long, RetData As Long
Const BUFFER_SIZE As Long = 255
'Set the forms graphics mode to persistent
Me.AutoRedraw = True
Me.Print "RegEnumKeyEx"
Ret = BUFFER_SIZE
'Open the registry key
If RegOpenKey(HKEY_LOCAL_MACHINE, "Hardware", hKey) = 0 Then
'Create a buffer
sName = Space(BUFFER_SIZE)
'Enumerate the keys
<font color="red">
While RegEnumKeyEx(hKey, Cnt, sName, Ret, ByVal 0&, vbNullString, ByVal 0&, ByVal 0&) <> ERROR_NO_MORE_ITEMS
'Show the enumerated key
Me.Print " " + Left$(sName, Ret)
'prepare for the next key
Cnt = Cnt + 1
sName = Space(BUFFER_SIZE)
Ret = BUFFER_SIZE
Wend
</font>
'close the registry key
RegCloseKey hKey
Else
Me.Print " Error while calling RegOpenKey"
End If
Me.Print vbCrLf + "RegEnumValue"
Cnt = 0
'Open a registry key
If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion", hKey) = 0 Then
'initialize
sName = Space(BUFFER_SIZE)
sData = Space(BUFFER_SIZE)
Ret = BUFFER_SIZE
RetData = BUFFER_SIZE
'enumerate the values
While RegEnumValue(hKey, Cnt, sName, Ret, 0, ByVal 0&, ByVal sData, RetData) <> ERROR_NO_MORE_ITEMS
'show data
If RetData > 0 Then Me.Print " " + Left$(sName, Ret) + "=" + Left$(sData, RetData - 1)
'prepare for next value
Cnt = Cnt + 1
sName = Space(BUFFER_SIZE)
sData = Space(BUFFER_SIZE)
Ret = BUFFER_SIZE
RetData = BUFFER_SIZE
Wend
'Close the registry key
RegCloseKey hKey
Else
Me.Print " Error while calling RegOpenKey"
End If
End Sub
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
Many, many thanks!!!!
It's (almost) tha same code snippet I have played with, but I insisted to open HKEY_LOCAL_MACHINE\Enum (as in APIGuide's example), subkey that doesn't exist in WinXP, and when I noticed that, I forgot to restore some other unsuccesfull hacks
best regards,
stefan b.
|
|
|
|
|
Hi,
I know it quite simple but how can I declare constants that should be used in my all vb library.
Thx.
|
|
|
|
|
Move them all into a module and delare them as 'Public Const'.
|
|
|
|
|
I have a string which should have either the substring ID in it, or the substring ID_NUMBER (it looks like
s = abc;adf;ID;ghj;ID_NUMBER;jjj
if at least one of these values is there, then I want to continue. But if neither is there, I want to exit the function. I've done:
If Not InStr(s, "ID") Or Not InStr(s, "ID_NUMBER") Then
MakeDB = -1
Exit Function
End If
but I think I'm wrong.
Thanks,
ns
|
|
|
|
|
ns wrote:
If Not InStr(s, "ID") Or Not InStr(s, "ID_NUMBER") Then
If it doesn't find "ID" then it isn't going to find "ID_NUMBER". I think that Or is wrong anyway but it's not even necessary, If Not InStr(s, "ID") Then would suffice.
As a side note, I don't personally trust VBs handling of intesgers in boolean expressions. I'd be tempted to add a > 0 to be sure.
Paul
|
|
|
|
|
Thanks very much. I didnt see your point at first then it dawned on me ....duh
Appreciate your help !
Thanks,
ns
|
|
|
|
|
Paul Riley wrote:
As a side note, I don't personally trust VBs handling of intesgers in boolean expressions. I'd be tempted to add a > 0 to be sure.
VB will *handle* them correctly, however sometimes it is best to litterally check the value of what is being returned. I agree.
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
Nick Parker wrote:
VB will *handle* them correctly, however sometimes it is best to litterally check the value of what is being returned. I agree.
I guess this is what comes of using many different languages that all act differently, you get to the point where you don't trust any of them and end up being as specific as possible at all times. C(++) has left me using parentheses absolutely everywhere .
This is all a good thing, in my humblest opinion. More precise coding is more readable coding.
Contrary to popular opinion, it is possible to code VB well
Paul
|
|
|
|
|
Paul Riley wrote:
Contrary to popular opinion, it is possible to code VB well
Fully agreed, I suppose we should watch how we talk about VB here in C++ country though.
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
plz can anybody tell me how to implement progress bar or searching icon for a sub call or procedure call.
thnx
--goodbye
|
|
|
|
|
hi all,
when i used FindFirstFile() i got the file name as ".",for the first
FindNextFile() call i got the name as ".." and for the third i got the correct one..how can i avoid the first two cases..
|
|
|
|
|
File_Name = Dir$(File_Path, vbDirectory)
Do While File_Name <> ""
If File_Name <> "." And File_Name <> ".." Then
.....
Your statements go here
.....
End If
Loop
This way i avoided the first two cases
Thanks & Regards,
Bhaskar.G
|
|
|
|
|
i think if the query is like
sCategory = "SELECT CATEGORY.CATEGORY FROM CATEGORY ORDER BY CATEGORY.CATEGORY"
in this the return type is a string and I could bind the output to a textbox and to a combobox.
now if the query is like
sCategory = "SELECT CATEGORY.* FROM CATEGORY"
then how to view the results ??
I think Datagrid should be used....well not sure
plz tell me how to bind and get the output in a datagrid ....
and do tell me how to get a value from a particular cell to use it in another query.
==thnx
waiting for a reply
|
|
|
|
|
In this example I am using the datadapter, as you can bind the whole resultset to the grid in one command, with the datareader you have to loop through the resultset.
Dim oConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection()
Dim oCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
Dim oDataTableResources As Data.DataTable = New Data.DataTable()
Dim oDataTableSites As Data.DataTable = New Data.DataTable()
Dim oDataAdapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter()
Dim sSiteName As String
Dim sResourceName As String
Const iDayLength As Integer = 86400
sSQL = "Select * from Category"
gsConnectString = " Initial Catalog=" & UCase(Trim(Me.txtDB.Text)) & _
";Data Source=" & UCase(Trim(Me.txtSVR.Text)) & _
";User ID=" & UCase(Trim(Me.txtUID.Text)) & _
";Password=" & Trim(Me.txtPWD.Text) & ";"
oConnection.ConnectionString = gsConnectString
Try
oConnection.Open()
Catch o As System.Exception
MsgBox(o.Message, MsgBoxStyle.Critical, gsMessageBoxHeader)
Me.Cursor = Cursors.Default
Exit Sub
End Try
Try
oCommand.Connection = oConnection
oCommand.CommandText = sSQL
oDataAdapter.SelectCommand = oCommand
'fill the data adapter
oDataAdapter.Fill(oDataTableResources)
'bind to the datagrid
dbgrdDataGrid.DataSource = oDataTableResources
dbgrdDataGrid.ParentRowsVisible = False
Catch o As System.Exception
MsgBox(o.Message)
Me.Cursor = Cursors.Default
End Try
I do not have any code of getting a specific cell from the grid. I am sure you will be able to find samples on the web.
YASP
|
|
|
|
|
runtime error "class does not support..."
"Class does not support automation or does not support expected interface"
I've double checked that the correct dll is being referenced, so thats not the problem, plus it works fine on my machine. On a win98 and a win2k that I've tried so far I get the above error.
Any ideas? I installed the dll with PDW so all files should be present on the users machines.....
Thanks,
ns
|
|
|
|
|
hmmm.... Is the .dll registered, that is different than just being present.
If not try this at the command prompt:
C:\[location of .dll]\ <code>regsvr32 myComponent.dll</code>
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
It is registered because I'm building it on my machine locally...
Thanks,
ns
|
|
|
|
|
ns wrote:
"Class does not support automation or does not support expected interface"
Bizarrely, this usually means that the build version of the DLL is different from the build version expected by the program.
If you have a test program for a DLL that you've rebuilt, you need to rebuild the program too.
Paul
|
|
|
|
|
Really I am rebuilding each time, and I know its connnected to the new dll because I'll put in identifying msgboxes in the new dll. But thanks for the answer....
Thanks,
ns
|
|
|
|
|
No problem.
I still think you'll find it's something along these lines. I had a bizarre fault once with an InstallShield Automation DLL.
I wrote a couple of programs using v7.0.1. When I upgraded to v7.0.2, the austomation programs stopped working; the two DLLs were byte-for-byte identical except for the version number. I tried rebuilding with no luck.
Eventually, I switched the DLL back to v7.0.1 and everything worked fine.
When I later upgraded to 7.0.3, the programs rebuilt and worked fine.
Go figure.
Paul
|
|
|
|
|
This is a dll that I wrote though. It gets into the dll, executes one step of the loop, then the error pops up. I have a progress bar in the calling app thats getting updated bythe dll, so thats why I know its gone one step...because the bar has one little block in it...
Thanks,
ns
|
|
|
|
|
Very bizarre. Sorry, you're out of my depth
Paul
|
|
|
|
|
see my latest post --maybe it'll be clear to you exactly whats happening...
Thanks,
ns
|
|
|
|
|