Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


DLL almost works

Posted on 2000-05-17
Medium Priority
Last Modified: 2010-05-18
This question has two parts.
Part I.
I created a wrapper dll (calls the GetUserName) to shield my users from the complexities of api functions. With the help of ameba (if you're out there, here's some more points for you), I got it to work on a Win 95 machine. When I run it on an NT machine, it gives me the following error:

The instruction at "0x77dc3e5f" referenced memory at
"0x000000ff". The memory could not be "read".

Click OK to terminate application.

I seem to remember that NT handles text strings differently from Win 95. It's supposed to make text strings more versatile for international users (I forget what it's called). Anyway, I
suspect that could be the problem.

That finishes Part I.

Part II.
I'm interested in wrapping many api calls in a series of dlls. I seen references to already made wrapper classes for vb. Anyone know where I can find them?


Question by:CodeCommando
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +2
LVL 28

Expert Comment

ID: 2818991
there are several at planet source code...here are a couple

"cOSNT_ChangePassword -A WinNT NETApi Class wrapper"


"cFindFile - A Windows API wrapper for FindNext"


LVL 28

Expert Comment

ID: 2819008
btw whats your code look like

Expert Comment

ID: 2819038
Just an off note:

referencing memory @ 0x000000ff

Have you stepped through your code to see exactly witch function is producing this? If you do/have then the syntax lies within that function

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 2819058
Here is ameba's solution. I made that work. The only change to his original code was that a function was named MachineName and I renamed it GetMachineName to make it consistent with the other function.

Here is 'optimized' version of your class. Note that you don't need module for declarations.
' clsUtils class
Option Explicit
Private Declare Function GetComputerName Lib "kernel32" Alias _
    "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserName& Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, ByVal nSize As Long)
'Get the local computer name
Public Function GetMachineName() As String
    Dim pos As Long
    On Error Resume Next
    GetMachineName = Space$(255) ' prepare buffer
    GetComputerName GetMachineName, 255 ' call windows API
    ' trim unneeded characters
    pos = InStr(GetMachineName, vbNullChar)
    GetMachineName = Left$(GetMachineName, pos - 1)
End Function

Public Function GetUser() As String
    Dim pos As Long
    On Error Resume Next
    GetUser = Space(255) ' prepare buffer
    GetUserName GetUser, 255 ' call windows API
    pos = InStr(GetUser, vbNullChar)
    If pos = 0 Then
        GetUser = "UNKNOWN"
        ' trim unneeded characters
        GetUser = Left$(GetUser, pos - 1)
    End If
End Function

' You can test your class with this form
' Form1 code
Option Explicit

Private Sub Form_Click()
    Dim Utils As clsUtils
    Set Utils = New clsUtils ' create instance
    MsgBox "Machine: " & Utils.GetMachineName & vbCrLf & _
        "User: " & Utils.GetUser
End Sub


Author Comment

ID: 2819078
Good call for orbitech. The problem only exists in the GetUser function. The GetMachineName is working fine.

Any ideas?
LVL 28

Expert Comment

ID: 2819080
is it just the getuser function?  try this one:

Public Function NTDomainUserName() As String
Dim strBuffer As String * 255
Dim lngBufferLength As Long
Dim lngRet As Long
Dim strTemp As String

    lngBufferLength = 255
    lngRet = GetUserName(strBuffer, lngBufferLength)
    strTemp = UCase(Trim$(strBuffer))
    NTDomainUserName = Left$(strTemp, Len(strTemp) - 1)

End Function

LVL 15

Expert Comment

ID: 2819162
Hi, again!

MS suggest creating setups for NT on NT machine, i.e. ideally you'll need one Vb machine per OS, but;
I don't think the API declarations or anything is different for *these* 2 functions on NT.
The only suggestion I have at a moment is:

Do a regular setup by using PDW, then INSTALL your package. Installation will copy and register everything your dll and exe needs.

Expert Comment

ID: 2819198
If you have not read this white paper you should try it

LVL 15

Expert Comment

ID: 2819207
Ok, 2 things you can try:

1. Pass nSize argument ByRef (your declaration is passing it ByVal)

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

2. Use GetUserNameW API instead of GetUserName

Public Declare Function GetUserNameW Lib "advapi32.dll" (lpBuffer As Byte, nSize As Long) As Long

Author Comment

ID: 2819258
Ok ameba, you got it working again. I have to go back later tonight and test again on my Win 95 machine to see if it will still work.

Will adding the "W" make it always compatible between 95 and NT? Or would it be safer to include an OS checker and then have different functions based on which OS is being used?

I get back later and tell you whether it works.

Azrasound gets partial credit of 50 points for finding the wrapper sites.

LVL 28

Expert Comment

ID: 2819278
two more classes to give you:

"Class Wrapper for the Common Dialog Functions"


"Wrapper class for mouse API calls"

LVL 15

Accepted Solution

ameba earned 1200 total points
ID: 2819323
I'm glad it worked.

>Will adding the "W" make it always compatible between 95 and NT?

I would use the other, 'non-Wide' version, it should work OK on both OS-es.

But, everything should be tested, since OS changes too often, too fast, not enough beta testing by MS, many surprises ... e.g. passing variables that include Chr(0), between components on Windows 2000 might not work.
LVL 15

Expert Comment

ID: 2819677
Thanks for the points, CodeCommando

Good luck with your wrappers. I'll see if I can find something that Azrasound didn't mention.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question