|
Thanks it works fine.
what do i need to do to use netapi32.dll in win9x/NT.
More help please.
Thanks.
|
|
|
|
|
NB: Please post any responses to the forum, so that other users get the chance to answer them!
Vipul Bhatt wrote:
Thanks a lot.
It worked.
Can you please tell me how i point to next memory location as
TempBufPtr = TempBufPtr + SIZE_SI_101
gives me an compile time error saying datatype conversion error where
TempBufPtr As IntPtr AND
Public Const SIZE_SI_101 = 24
Thanks in advance.
Also where can i find info about these API functions as i was unable to find the correct declaration info.
THANKS ONCE AGAIN.
To move an IntPtr in VB.NET, you need to re-create it:
TempBufPtr = New IntPtr(TempBufPtr.ToInt32() + SI_SIZE_101)
The best place to find information about any API is MSDN:
http://msdn.microsoft.com/[^]
Also, take a look at this article, which makes extensive use of the NetServerEnum function:
http://www.codeproject.com/csharp/ServerComboBox.asp[^]
|
|
|
|
|
Thanks Richard. Great help.
Can U pls. tell me how can i use the RtlMoveMemory in VB.NET and also do i need to convert pointer to string later. If yes please tell how do i do that.
I tried using marshal.PtrToStringUni but in vain.
hope i will get similar response as earlier.
Thanks in advance.
|
|
|
|
|
Vipul Bhatt wrote:
tell me how can i use the RtlMoveMemory in VB.NET
Don't! For most cases, using the MarshalAs and StructLayout attributes will be sufficient. In cases when these don't work, the Marshal class provides functions to convert between managed types and IntPtr s.
For example:
Imports System.Runtime.InteropServices
'
Public Enum PlatformID
DOS = 300
OS2 = 400
NT = 500
OSF = 600
VMS = 700
End Enum
'
<Flags> _
Public Enum ServerType
None = &H00000000
Workstation = &H00000001
Server = &H00000002
SQLServer = &H00000004
DomainController = &H00000008
DomainBackupController = &H00000010
TimeSource = &H00000020
AFP = &H00000040
Novell = &H00000080
DomainMember = &H00000100
PrintQueue = &H00000200
Dialin = &H00000400
Xenix = &H00000800
Unix = Xenix
NT = &H00001000
WFW = &H00002000
MFPN = &H00004000
NTServer = &H00008000
PotentialBrowser = &H00010000
BackupBrowser = 0x00020000
MasterBrowser = &H00040000
DomainMaster = &H00080000
OSF = &H00100000
VMS = &H00200000
Windows = &H00400000
DFS = &H00800000
ClusterNT = &H01000000
TerminalServer = &H02000000
DCE = &H10000000
AlternateXPort = &H20000000
ListOnly = &H40000000
DomainEnum = &H80000000
All = &HFFFFFFFF
End Enum
'
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure SERVER_INFO_101
'
Public dwPlatformID As PlatformID
'
<MarshalAs(UnmanagedType.LPWStr)> _
Public lpszServerName As String
'
Public dwVersionMajor As Integer
Public dwVersionMinor As Integer
'
Public dwType As ServerType
'
<MarshalAs(UnmanagedType.LPWStr)> _
Public lpszComment As String
End Structure
In this case, fields of type DWORD map to Integer s, or Enum s based on Integer (the default). Fields of type LPWSTR map to String s with the MarshalAs(UnmanagedType.LPWStr) attribute.
Then, assuming TempBufPtr is an IntPtr pointing to the current item, you can use:
Imports System.Runtime.InteropServices
...
Dim tS As Type = GetType(SERVER_INFO_101)
Dim currentItem As SERVER_INFO_101
currentItem = DirectCast(Marshal.PtrToStructure(TempBufPtr, tS), tS)
Dim ServerName As String = currentItem.lpszServerName
No need to call RtlMoveMemory , no need to convert pointers to strings!
For more information on marshalling between managed and unmanaged code, have a look at http://msdn.microsoft.com/library/en-us/cpguide/html/cpconmarshalingdatawithplatforminvoke.asp[^]
|
|
|
|
|
It worked
A BIG THANKS RICHARDS.
Great help.
God bless you.
|
|
|
|
|
Thanks Richard,
only one change required:
currentItem = DirectCast(Marshal.PtrToStructure(TempBufPtr, tS), tS)
Just replace tS with Object as below
currentItem = DirectCast(Marshal.PtrToStructure(TempBufPtr, tS), Object)
A big thanks to you.
|
|
|
|
|
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
|
|
|
|
|