Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7966763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:31:06+00:00 2026-06-04T06:31:06+00:00

Everything I know about .Net programming tells me that the behavior I see here

  • 0

Everything I know about .Net programming tells me that the behavior I see here is completely impossible. So can someone please explain what is going on here? Simple code:

Structure WKSTA_USER_INFO_1
    Dim wkui1_username As Integer
    Dim wkui1_logon_domain As Integer
    Dim wkui1_logon_server As Integer
    Dim wkui1_oth_domains As Integer
End Structure

Declare Function NetWkstaUserGetInfo Lib "Netapi32" (ByVal reserved As Integer, ByVal level As Integer, ByRef lpBuffer As Integer) As Integer
Declare Sub lstrcpyW Lib "kernel32" (ByRef dest As Byte, ByVal src As Integer)
Declare Sub RtlMoveMemory Lib "kernel32" (ByRef dest As WKSTA_USER_INFO_1, ByRef src As Integer, ByVal Size As Integer)
Declare Function NetApiBufferFree Lib "Netapi32" (ByVal Buffer As Integer) As Integer

Function GetDomain() As String
    Dim ret As Integer
    Dim wk1 As WKSTA_USER_INFO_1
    Dim pwk1 As Integer

    Dim test As String = ""

    ret = NetWkstaUserGetInfo(Nothing, 1, pwk1)
    RtlMoveMemory(wk1, pwk1, Len(wk1))

    ret = NetApiBufferFree(pwk1)

    Return "test"
End Function

When I put a break point in here, I see that after RtlMoveMemory, my wk1 contains a pointer to a username, and all the others are 0. This is consistant. Now, if I change Dim test As String = "" to Dim login As String = "" and run it again, wk1 contains pointers to both username and logon_domain.

If I change it to Dim login As String, it contains a pointer to only the username. Depending on what I change that (completely unused) variable name to, I get a different result. How is this possible?

I have always been under the impression that it cannot possibly matter what you choose to name your variable. And that declaring a variable, and then never using it, cannot possible be different from not having a variable there at all.

I’ve tried this on 2 computers, with consistant results (one on .Net 3.5 and one on 4.0). When I tried converting it to C#, however, I was not able to reproduce it.

I am aware, by the way, that I can just use System.Environment to get what I need about the current user information; this was old VB6 code that was automatically upgraded (and I’ve edited it a little to make it more trivial). I’m just trying to understand how this behavior is possible. Obviously I’ve spent many years assuming something about .Net that isn’t quite true.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:31:07+00:00Added an answer on June 4, 2026 at 6:31 am

    Solution, with help from Raymond Chen:

    The declaration for RtlMoveMemory should have src passed as ByVal, instead of as ByRef. Because the src that I’m passing is a pointer to a memory location, passing it ByRef caused it to pass the memory address of where my pointer was stored… in other words, the location of my variable declaration. Thus, having other variables or differently named variables around produced different results.

    A note as to why it was being passed ByRef… in the original VB6 code, it didn’t specify ByVal in the declaration, and ByRef is the default in VB6. So, the declaration itself was expecting ByRef. However, the call to the API specified that it was passing the variable ByVal. This is something that you cannot do in .Net; you have to pass it the same as the declaration is expecting. So the auto-upgrader added ByRef to the declaration, which does keep the declaration the same as VB6, but it ignored the ByVal in the call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

assuming that I know nothing about everything and that I'm starting in programming TODAY
From what I know, everything about OpenGL changed since 3.1 and now I can't
Given that both the client and the server need to know everything about the
I know that almost everything is already said about CMSs, but what interests me
I'm interested in learning about parallel programming in C#.NET (not like everything there is
Ok I know you can use the dir() method to list everything in a
I know that codeIgniter turns off GET parameters by default. But by having everything
As far as I know, everything done in XAML can be done in C#.
I don't know why , i can't override back button: I tried everything I
I know about the viewstate and dopostback and everything, I just don't know where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.