PC Review


Reply
 
 
Doug Bell
Guest
Posts: n/a
 
      20th Jul 2004
Hi
In VB I used to call a Windows API from VB to get the User's Name and
Workstation Name

I have just started to try and pick up some Dot Net by rewriting one of my
small Applications and I can't see how to invoke these calls in Dot Net.

Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)
As Long

Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal pBuffer As String, nSize As
Long) As Long


Function dacUser() As String
If Len(gstrUserName) = 0 Then
Dim stUser As String
Dim lngCnt As Long, lngDL As Long
Dim sngPos As Single
lngCnt = 199
stUser = String(200, 0)
lngDL = GetUserName(stUser, lngCnt)
stUser = Left(stUser, lngCnt) & lngCnt
sngPos = InStr(1, stUser, Chr(0))
If sngPos > 0 Then
gstrUserName = Left(stUser, sngPos - 1)
End If
End If
dacUser = gstrUserName
End Function

I tried replacing String with StrDup but can't get it to work

Can someone help?


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      20th Jul 2004
Hi,

No need for an api call anymore. Take a look at the environment and
systeminformation classes.

Trace.WriteLine(Environment.UserName)

Trace.WriteLine(Environment.MachineName)

Trace.WriteLine(SystemInformation.UserName)

Trace.WriteLine(SystemInformation.ComputerName)



Ken

-------------------

"Doug Bell" <dug@bigpond> wrote in message
news:(E-Mail Removed)...
Hi
In VB I used to call a Windows API from VB to get the User's Name and
Workstation Name

I have just started to try and pick up some Dot Net by rewriting one of my
small Applications and I can't see how to invoke these calls in Dot Net.

Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)
As Long

Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal pBuffer As String, nSize As
Long) As Long


Function dacUser() As String
If Len(gstrUserName) = 0 Then
Dim stUser As String
Dim lngCnt As Long, lngDL As Long
Dim sngPos As Single
lngCnt = 199
stUser = String(200, 0)
lngDL = GetUserName(stUser, lngCnt)
stUser = Left(stUser, lngCnt) & lngCnt
sngPos = InStr(1, stUser, Chr(0))
If sngPos > 0 Then
gstrUserName = Left(stUser, sngPos - 1)
End If
End If
dacUser = gstrUserName
End Function

I tried replacing String with StrDup but can't get it to work

Can someone help?



 
Reply With Quote
 
Doug Bell
Guest
Posts: n/a
 
      20th Jul 2004
Thanks Ken,

That is too easy!

What about a File Open/ File Save Box Dialogue Box?

I used always call that as an API, is there a Namespace solution for that?

Also can you recommend best way to really get up to speed with all these
changes?

Doug


"Ken Tucker [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> No need for an api call anymore. Take a look at the environment

and
> systeminformation classes.
>
> Trace.WriteLine(Environment.UserName)
>
> Trace.WriteLine(Environment.MachineName)
>
> Trace.WriteLine(SystemInformation.UserName)
>
> Trace.WriteLine(SystemInformation.ComputerName)
>
>
>
> Ken
>
> -------------------
>
> "Doug Bell" <dug@bigpond> wrote in message
> news:(E-Mail Removed)...
> Hi
> In VB I used to call a Windows API from VB to get the User's Name and
> Workstation Name
>
> I have just started to try and pick up some Dot Net by rewriting one of my
> small Applications and I can't see how to invoke these calls in Dot Net.
>
> Declare Function GetComputerName Lib "kernel32" Alias _
> "GetComputerNameA" (ByVal lpBuffer As String, nSize As

Long)
> As Long
>
> Declare Function GetUserName Lib "advapi32.dll" Alias _
> "GetUserNameA" (ByVal pBuffer As String, nSize As
> Long) As Long
>
>
> Function dacUser() As String
> If Len(gstrUserName) = 0 Then
> Dim stUser As String
> Dim lngCnt As Long, lngDL As Long
> Dim sngPos As Single
> lngCnt = 199
> stUser = String(200, 0)
> lngDL = GetUserName(stUser, lngCnt)
> stUser = Left(stUser, lngCnt) & lngCnt
> sngPos = InStr(1, stUser, Chr(0))
> If sngPos > 0 Then
> gstrUserName = Left(stUser, sngPos - 1)
> End If
> End If
> dacUser = gstrUserName
> End Function
>
> I tried replacing String with StrDup but can't get it to work
>
> Can someone help?
>
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      20th Jul 2004
Hi David,

As Ken did, are we trying to give the right dotNet program parts in this
newsgroup, which will have all the benefits of the framework.

What is the sense when there are good framework classes to show the API
code, when this is done people are easy converting API's which is not that
hell of a job when you know the tricks, however can have mabye give problems
in short or long future?

I am curious about your thought about this?

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      20th Jul 2004
* "Doug Bell" <dug@bigpond> scripsit:
> What about a File Open/ File Save Box Dialogue Box?
>
> I used always call that as an API, is there a Namespace solution for that?


'System.Windows.Forms.OpenFileDialog'/'System.Windows.Forms.SaveFileDialog'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling SQL from code has different behaviour than calling it from MS SQL Server Management Studio jeeji Microsoft C# .NET 1 29th Jun 2006 10:43 AM
Calling DoCmd.RunCommand acCmdSaveRecord, after calling an API function Savvoulidis Iordanis Microsoft Access Form Coding 2 19th Mar 2005 06:34 PM
Fail to send fax when making international fax calling / calling c =?Utf-8?B?c2Ftd2lzZQ==?= Windows XP Help 1 28th Dec 2004 02:31 PM
Calling FormsAuthentication.SignOut() after calling Response.Flush =?Utf-8?B?TWFydGluIExlZQ==?= Microsoft ASP .NET 1 28th Sep 2004 01:47 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier Microsoft ASP .NET 4 29th Jul 2004 02:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 PM.