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
Solved

Can't find DLL entry point for homemade dll

Posted on 2000-05-16
9
188 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…

860 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