Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling DLLs from VB

Posted on 1999-06-23
14
Medium Priority
?
166 Views
Last Modified: 2010-05-02
I've made an ActiveX dll with some public methods.
Now I want to use these methods from within my VB program.
I try to declare the methods in the following manner:

Private Declare Function Method1 Lib "DllName" (ByVal Arg1 As String, ByVal Arg2 As Integer) As Boolean

Running my program and calling Method1 causes the following error:
Run-time error '453':
Can't find DLL entry point in Method1 in DllName

How come? There are no case-sensitivity problems here and the dll is obviously found.

Thanks!
0
Comment
Question by:mawe
[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
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 2

Expert Comment

by:thew00d
ID: 1519184
go into References and reference the DLL from there
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 300 total points
ID: 1519185
It is a general misunderstanding that VB dll can export function.
Public functions in a dll are not exported.
VB cannot export functions like C that can. I repeat CANNOT do that.
The only DLL's that VB can make are ActiveX dll's.

What you can do is put your functions that your want to export in a class which is "globalmultiuse" Now application that use this DLL can make a reference to this DLL like any ActiveX dll. They can now use the functions.

BTW: Using a class to reference your functions has the advantage that the location of the DLL is not important anymore. If your are referencing exported functions, that you need the location of the DLL or the DLL should be in your path.

1) Create two projects:
       a) Tstclient (Standard Exe)
       b) TstServer (ActiveX dll)

2) Add a class TstClass to TstServer

3) Change property of class to "GlobalMultiUse"

4) Add functions to TstClass
          TstMyFunction1
          TstMyFunction2

5) Add TstServer as reference to TstClient

6) Now you can use TstMyFunction1 and TstMyFunction anywhere in TstClient.
0
 
LVL 6

Expert Comment

by:simonbennett
ID: 1519186
You are doing this the wrong way. An active x dll is *different* from a C dll.

Like thew00d says. Register your dll (from command promt, type 'regsvr32 mydll.dll'). Now go to the Project, References menu and look for your dll (it will be called the name of your original project) and tick it. Now use the code below...

Dim object as new mydll

object.method1

HTH

Simon
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mawe
ID: 1519187
Yeah, but how do I access the DLL from there?

res = DllName.ClassName.Method (arg1, arg2)

or what??

0
 
LVL 2

Expert Comment

by:thew00d
ID: 1519188
as simonbennett said

Dim Object as New classname

object.method arg1,arg1

etc etc

if the dll is referenced you refer to Classnames within the DLL
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1519189
With my method, you don't need to do new and you can skip the classname...
0
 
LVL 2

Expert Comment

by:thew00d
ID: 1519190
......... yeah but use of GlobalMultiUse (and I think its slower) is frowned upon if doing 'proper' Object Oriented design......... but lets not start a debate on that one!
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1519191
He wants global functions. That means no state at all between the functions.
Why not use a stateless system like globalmultiuse?

0
 
LVL 2

Expert Comment

by:thew00d
ID: 1519192
if he wants to call his methods that way then, errr, well there isn't really any reason not to use it.
0
 

Author Comment

by:mawe
ID: 1519193
Doing as you suggest Simon Bennett causes "Compile Error: Expected user-defined type, not project"
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1519194
Did you reference the DLL like theWood said.
0
 
LVL 2

Expert Comment

by:thew00d
ID: 1519195
It sounds like you're still declaring it in some way outside of the main code
0
 
LVL 2

Expert Comment

by:thew00d
ID: 1519196
It sounds like you're still declaring it in some way outside of the main code
0
 

Author Comment

by:mawe
ID: 1519197
Oops, Wait a minute, forgot to add the class name...now it seems to work properly!

Thank u all!

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses

715 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