Improve company productivity with a Business Account.Sign Up

x
?
Solved

Can't find DLL entry point for homemade dll

Posted on 2000-05-16
9
Medium Priority
?
216 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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

606 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