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

x
?
Solved

Can't find DLL entry point for homemade dll

Posted on 2000-05-16
9
Medium Priority
?
195 Views
Last Modified: 2008-03-17
I made a dll that is a wrapper for a win api function (GetUserName). The purpose of my dll is to shelter the users from all the complications of win api calls and only call my function and get back a string with the name. Good in theory, but it doesn't work. I keep getting Can't find DLL entry point error message.

The dll has 1 class and 1 module (to make the declarations). There is nothing in either the Class Terminate or Class Initialize functions. There is one function GetUser which is the call to the winapi.

So is the problem that I messed up somewhere in the dll or am I calling it wrong from my app or ???

If you need to see the code, I can post that too.

I've seen this question circulating around here, but I haven't found the answer. I'm sure one of you gurus is willing to score some big points on this one.

Ramon
0
Comment
Question by:CodeCommando
[X]
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
  • 2
  • 2
  • +1
9 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 2815044
You forgot the 'alias' part in your declaration.

.... Alias "GetUserNameA" (ByVal ...
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2815076
I want to see your code. Please post it here.
0
 

Author Comment

by:CodeCommando
ID: 2815138
Here is the dll(kelco_api_calls.dll) code:

Module code:
Option Explicit

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

Class code:
Public Function GetUser() As String
Dim sName As String
Dim iLength As Integer
Dim iResult As Long

    iLength = 254
    sName = String(254, "*")
   
    iResult = GetUserName(sName, iLength)
   
    If Len(sName) > 0 Then
        GetUser = sName
    Else
        GetUser = "UNKNOWN"
    End If
       
End Function

That's it for the dll.


Calling app code:

Option Explicit

Module declaration:
Declare Function GetUserA Lib "kelco_api_calls.dll" Alias "GetUser" () As String

Code inside the button:
Dim s As String
s = GetUserA()
MsgBox s

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2815185
did you register your dll and reference it in your calling project?
0
 
LVL 15

Expert Comment

by:ameba
ID: 2815202
>>>
Module declaration:
Declare Function GetUserA Lib "kelco_api_calls.dll" Alias "GetUser" () As String
<<<
No, you don't declare functions for ActiveX DLL you created.

The declaration you used is for 'normal' windows DLLs. VB cannot produce 'normal' windows DLL, but only ActiveX DLLs.

To use your DLL, you just add reference to your DLL (menu Project, References). If your DLL project is 'Project2', you'll see checked 'Project2' when you select your DLL in References dialog.

Code inside the button:
 ' your class has name 'clsUtils' or 'Project2.clsUtils'
  Dim myUtils as clsUtils
  Set myUtils = New clsUtils
  Dim s As String
  s = myUtils.GetUserA()
  MsgBox s
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2815231
Have a look at:
http://www.vb2themax.com/HtmlDoc.asp?Table=Articles&ID=60

When you can create an ActiveX dll,
you need to add a reference in the project -References project, and you use it by declaring a variable of the type of a class in your dll. Just say you created a DLL called "kelco_api_calls"

Dim YourDll as new kelco_api_calls


http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_calling_dll_functions_from_visual_basic_applications.htm

http://support.microsoft.com/support/kb/articles/Q142/8/40.ASP

http://visualbasic.about.com/compute/visualbasic/gi/dynamic/offsite.htm?site=http://mspress.microsoft.com/prod/books/sampchap/231.htm
0
 
LVL 15

Accepted Solution

by:
ameba earned 1600 total points
ID: 2815309
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 MachineName() As String
    Dim pos As Long
    On Error Resume Next
   
    MachineName = Space$(255) ' prepare buffer
    GetComputerName MachineName, 255 ' call windows API
    ' trim unneeded characters
    pos = InStr(MachineName, vbNullChar)
    MachineName = Left$(MachineName, 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"
    Else
        ' 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.MachineName & vbCrLf & _
        "User: " & Utils.GetUser
End Sub
0
 

Author Comment

by:CodeCommando
ID: 2815497
Thanks all for your help. ameba hit it right on the nose (do amoebas have noses?).

Dll is running fine and it can be called from another vb app.

Thanks again.

Ramon
0
 
LVL 15

Expert Comment

by:ameba
ID: 2815642
:)
GetNose() returns False here

Thanks for the points!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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