Solved

Can't find DLL entry point for homemade dll

Posted on 2000-05-16
9
185 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
  • 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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2815185
did you register your dll and reference it in your calling project?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 400 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now