|
I am trying to call the Windows API function "GetUserName" from VB 6, and it always returns 0 for failure. However, I can call this exact same function from Visual C++ 6.0 and it works just fine...
Here is the code:
Declare Function _
GetUserName Lib "Advapi32.dll" Alias "GetUserNameA" _
(ByRef lpBuffer As String, ByRef nSize As Integer) As Long
Dim strUserName As String
Dim nUserLen As long
Dim nRetVal as long
nUserLen = 32
strUserName = Space(nUserLen)
retVal = GetUserName(strUserName, nUserLen)
There are 10 kinds of people - those that get binary and those that don't.
|
|
|
|
|
What do you mean by "it doesn't work"? What happens?
Also, you are declaring nUserLen as Long and the variable nSize as Integer. They should both be the same type as each other (either type is fine, but you don't really need it to be as big as a Long).
You might consider making the buffer be bigger than 32 characters, because if the UserName happens to be longer than this (but it generally isn't) the function will fail.
When you are done calling this function you should do:
strUserName=Left(strUserName, nUserLen)
This will cut off the unnecessary bytes.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
jdunlap wrote:
What do you mean by "it doesn't work"? What happens?
I mean it just returns 0 for failure, the string contains the 32 spaces that I initilialized it with and nUserLen is still 32.
Oddly enough, when I call "GetLastError" afterwards to find out the exact reason it failed, that too returns 0, for no error!
jdunlap wrote:
Also, you are declaring nUserLen as Long and the variable nSize as Integer
I have tried all combinations of integer/long with the exact same results.
Just above this section of code (in the same sub actually), I am calling another API function, "GetPrivateProfileString", and it works just fine. I can also call "GetUserName" from C++ and it works as expected.
I am wondering if there's some other library or something that I need instead of kernel32, as we are on a Novell network here and not the standard MS networking... It's still strange how it works from C++ though...
jdunlap wrote:
You might consider making the buffer be bigger than 32 characters
Yeah, you're probably right, but since my user name is only 3 characters I figured it would be big enough for testing...
There are 10 kinds of people - those that get binary and those that don't.
|
|
|
|
|
Declare Function _
GetUserName Lib "Advapi32.dll" Alias "GetUserNameA" _
(ByRef ByVal lpBuffer As String, ByRef nSize As Integer) As Long
If you pass it ByVal, then VB does the marshalling for you, and it acts like a ByRef byte array. VB does unicode BSTRs, so if you pass it ByRef, it passes the unicode BSTR, which Windows doesn't understand.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Thanks! It works fine now
There are 10 kinds of people - those that get binary and those that don't.
|
|
|
|
|
How can you validate a user login to your application against the local machines windows user database? Against a domain?
|
|
|
|
|
|
Thank you for the link. I tried it and it works fine in VB6. Do you know if there is a .net class or anything that will achieve the same thing?
|
|
|
|
|
I have some vb.NET code at home that does htis. I can get it to you latter today.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
Thank you very much! That would be extremly helpful!
|
|
|
|
|
i have server client program working using one of the tutorials but i would like to be able to save the log that the server produces for everytime a client logs on i have managed to save and load from text boxes using:
Dim hFile As Long
Dim sFilename As String
sFilename = "c:\log.txt"
'obtain the next free file handle from the
'system and and save the text box contents
hFile = FreeFile
Open sFilename For Output As #hFile
Print #hFile, txtReceive.Text
Close #hFile
but i was wondering if there was a similar way to save all the items in a list box to a log and a way that it could be called back again! any help would be great!
.: Lister :.
|
|
|
|
|
it looks like you are using VB 6.0, you should try using the FileSystemObject
Steve
|
|
|
|
|
thanx steve but i dont really know much about FileSystemObject i had a look on msdn libraries to find out some stuff and found how to create a file and add text to it but not what ever was in the list box thanx for trying tho!
.: Lister :.
|
|
|
|
|
Any body know how to use (make) a bit array.
Thanks
|
|
|
|
|
What's the question?
BitArray stores as many boolean values as you want, well, up to 2,147,483,647 of them anyway. First you declare a BitArray object with the number of bits you want to store, say, 100 of them:
Dim myBitArray As New BitArray(100)
Then you use the Item Property to get/set individual values:
For Index = 0 to 99<br />
myBitArray.Item(Index) = True<br />
Next Index
RageInTheMachine9532
|
|
|
|
|
OK, thanks for your answer.
specificaly my question is : How construct the "Binary Blob" from this string "1234567-8".
thanks.
|
|
|
|
|
What are you doing with the blob? Are you doing something with a database?
RageInTheMachine9532
|
|
|
|
|
Pombo wrote:
bit array (BSTR)
A BSTR is different than a bit array. A BSTR is a string data type that stored the length of the string is stored with the data.
-Nick Parker
|
|
|
|
|
I'm new to programming so please don't laugh when you see my question.
What code do I use to open a form in a project when I click a button another form?
It's got to be something really simple and in Access I've used "DoCmd.OpenForm" but apprently it doesn't work in VB.Net. Thanks for any help!
Nathan
|
|
|
|
|
Dim newForm as Form1 = New Form1
newForm.Show()
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
Hi All,
I have the following scenario:
in a Bound windows form, I have a master-detail relationship, the first part of the form is the Master(represented by text and combo boxes) and retrives it's Data from a single SQL data table, The Details Section is represented by a DataGrid, and retrives its Data from Multi Tables Sql Query.
I wand to Add/ Insert/ Update and Delete from this Related sections at once, but still facing some problems affecting the Details Section, the modifications are done on the Master only.
The relation between them is build in the run time.
plz, if you have any Idea how to solve such a problem, that will be appreciated.
Thanx All.
I.M.A
|
|
|
|
|
Hi Gang,
I was just wondering if anybody here has done VBA work in professionally released packages.
Here's the deal, part of our program is using Excel/VBA as an add into to our software. We are trying to come up with a way where the code signed projects don't have to ask about macros all of the time.
We are trying to find a way around this. No, not in the sense of by-passing all security, but a way where the user only needs to acknowledge "Trust These Files" from our company.
Anybody have any ideas?
Nick
|
|
|
|
|
Hello
I want to execute a string value in VB.NET
e.g.
dim a as string
a = "msgbox "Emre""
.. a
When I execute this statement it must show the messagebox.
In VB6 I was using Script ActiveX Component.
How can I do that in VB.NET?
Thanks
Best Regards
Emre YAZICI
|
|
|
|
|
Hi,
I used this code on button1_click of a button in Windows form and it displayed me with the messagebox
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strMsg As String
Dim strMsgNew As String = "Pritpal Singh Bumrah"
strMsg = MsgBox(strMsgNew)
strMsg.ToString()
End Sub
I hope this should solve your problems
dickysingh
Nothing New
|
|
|
|
|
Thank you for your answer
My problem is more complicated.
Please consider there is a textbox and a button in my form
When i click to the button the code that i wrote it into textbox , must be executed. But i will not use only msgbox. I will use all of the Vb.NET functions like (int - left - mid ....)
I used to develop it in vb6 using scripting control object
it was able to use ...
script1.execute text1.text
like this..
It executes the code that i have written into textbox.
Thanks
Best Regards
Emre YAZICI
|
|
|
|