Click here to Skip to main content
15,890,897 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: need help in visual basic.net Pin
Christian Graus24-Jun-08 19:08
protectorChristian Graus24-Jun-08 19:08 
QuestionHow to call RegEx from compiled .DLL Pin
Er2345624-Jun-08 15:55
Er2345624-Jun-08 15:55 
AnswerRe: How to call RegEx from compiled .DLL Pin
Christian Graus24-Jun-08 16:17
protectorChristian Graus24-Jun-08 16:17 
QuestionHow to integrate VB.NET with C++ Pin
boyindie24-Jun-08 8:32
boyindie24-Jun-08 8:32 
AnswerRe: How to integrate VB.NET with C++ Pin
Christian Graus24-Jun-08 11:49
protectorChristian Graus24-Jun-08 11:49 
QuestionDatabase Login window... Pin
CCG324-Jun-08 7:50
CCG324-Jun-08 7:50 
AnswerRe: Database Login window... Pin
Kschuler24-Jun-08 12:11
Kschuler24-Jun-08 12:11 
QuestionHow to call netapi32.dll and extract data from buffer? Sigh... Pin
Jon_Boy24-Jun-08 5:27
Jon_Boy24-Jun-08 5:27 
I need to call NetAPI32 to get domain info on legacy workstations (IE: Win98, etc - DirectoryServices is not avail in 98).

I have the following code. The call to DsGetDcNameAWin5 doesn't error off, but the values are 0. I've tried changing the function declare to (using a pointer) as the last param with no success also:
Private Declare Function DsGetDcNameAWin5 Lib "netapi32.dll" Alias "DsGetDcNameA" (ByVal ComputerName As String, ByVal DomainName As String, ByRef DomainGuid As GUID, ByVal SiteName As String, ByVal Flags As Integer, ByRef lpDomainControllerInfo As IntPtr) As Integer

Could someone please show how to properly call and then extract the data from this .dll?





Sample code:
Private Const NO_ERROR As Short = 0
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef pTo As Integer, ByRef uFrom As Integer, ByVal lSize As Integer)
Private Declare Function lstrlenA Lib "kernel32" (ByVal lpString As Integer) As Integer
Private Declare Function DsGetDcNameAWin5 Lib "netapi32.dll" Alias "DsGetDcNameA" (ByVal ComputerName As String, ByVal DomainName As String, ByRef DomainGuid As GUID, ByVal SiteName As String, ByVal Flags As Integer, ByRef lpDomainControllerInfo As Integer) As Integer

Private Structure GUID
Dim Data1 As Integer
Dim Data2 As Short
Dim Data3 As Short
<vbfixedarray(7)> Dim Data4() As Byte

Public Sub Initialize()
ReDim Data4(7)
End Sub
End Structure

Private Structure DOMAIN_CONTROLLER_INFO
Dim DomainControllerName As Integer
Dim DomainControllerAddress As Integer
Dim DomainControllerAddressType As Integer
Dim DomainGuid As GUID
Dim DomainName As Integer
Dim DnsForestName As Integer
Dim Flags As Integer
Dim DcSiteName As Integer
Dim ClientSiteName As Integer

Public Sub Initialize()
DomainGuid.Initialize()
End Sub
End Structure

Private Function SetDcNameA(Optional ByVal strDomain As String = vbNullString, Optional ByVal strComputer As String = vbNullString) As Boolean
Dim lpBuffer As Integer
Dim dci As DOMAIN_CONTROLLER_INFO
dci.DomainGuid.Initialize()

m_LastError = DsGetDcNameAWin5(strComputer, strDomain, dci.DomainGuid, vbNullString, m_Flags, lpBuffer)

If m_LastError <> NO_ERROR Then
GoTo ErrorHandler
End If

' Recover structure into one we can deal with in VB
'Call CopyMemory(dci, lpBuffer, Len(dci)) 'Doesn't compile



' Transfer contents to member structure.
m_DCI.DomainControllerName = PointerToStringA(dci.DomainControllerName)
m_DCI.DomainControllerAddress = PointerToStringA(dci.DomainControllerAddress)
m_DCI.DomainControllerAddressType = dci.DomainControllerAddressType
m_DCI.DomainGuid = dci.DomainGuid
m_DCI.DomainName = PointerToStringA(dci.DomainName)
End Sub

Private Function PointerToStringA(ByVal lpStringA As Integer) As String
Dim Buffer() As Byte
Dim nLen As Integer

On Error GoTo ErrorHandler

If CBool(lpStringA) Then
nLen = lstrlenA(lpStringA)
If CBool(nLen) Then
ReDim Buffer((nLen - 1))
CopyMemory(Buffer(0), lpStringA, nLen)
'Not sure if this line is correct as well.
PointerToStringA = StrConv(System.Text.UnicodeEncoding.Unicode.GetString(Buffer), VbStrConv.None)
End If
End If
Exit Function

ErrorHandler:
PointerToStringA = ""
End Function
QuestionIs there any way(s) to do this? Pin
cshong24-Jun-08 3:47
cshong24-Jun-08 3:47 
AnswerRe: Is there any way(s) to do this? Pin
jzonthemtn24-Jun-08 6:34
jzonthemtn24-Jun-08 6:34 
QuestionHow can I set my simple VB.NET program to start in minimized mode? Pin
cshong24-Jun-08 2:47
cshong24-Jun-08 2:47 
AnswerRe: How can I set my simple VB.NET program to start in minimized mode? Pin
Christian Graus24-Jun-08 2:51
protectorChristian Graus24-Jun-08 2:51 
AnswerRe: How can I set my simple VB.NET program to start in minimized mode? Pin
Ahamed Azeem1-Jul-08 23:44
Ahamed Azeem1-Jul-08 23:44 
Questionview in design time but problem in runtime using Infragistic [modified] Pin
rohit tiwary24-Jun-08 1:58
rohit tiwary24-Jun-08 1:58 
AnswerRe: view in design time but problem in runtime using Infragistic Pin
Ashfield24-Jun-08 3:15
Ashfield24-Jun-08 3:15 
GeneralRe: view in design time but problem in runtime using Infragistic Pin
rohit tiwary24-Jun-08 4:26
rohit tiwary24-Jun-08 4:26 
Questionvb6 migration to .net Pin
costavo24-Jun-08 1:54
costavo24-Jun-08 1:54 
AnswerRe: vb6 migration to .net Pin
Christian Graus24-Jun-08 2:51
protectorChristian Graus24-Jun-08 2:51 
AnswerRe: vb6 migration to .net Pin
Chaitanya kumar CVSS25-Jun-08 2:59
Chaitanya kumar CVSS25-Jun-08 2:59 
Questionconverting from SQL server to MySql Pin
ttilque24-Jun-08 1:49
ttilque24-Jun-08 1:49 
AnswerRe: converting from SQL server to MySql Pin
Christian Graus24-Jun-08 1:53
protectorChristian Graus24-Jun-08 1:53 
AnswerRe: converting from SQL server to MySql Pin
jzonthemtn24-Jun-08 6:38
jzonthemtn24-Jun-08 6:38 
GeneralRe: converting from SQL server to MySql Pin
ttilque24-Jun-08 10:42
ttilque24-Jun-08 10:42 
GeneralRe: converting from SQL server to MySql Pin
jzonthemtn24-Jun-08 10:54
jzonthemtn24-Jun-08 10:54 
GeneralRe: converting from SQL server to MySql Pin
ttilque25-Jun-08 3:22
ttilque25-Jun-08 3:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.