Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can't find DLL entry point for homemade dll

Posted on 2000-05-16
9
Medium Priority
?
199 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

916 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