|
-
Jun 1st, 2000, 02:50 PM
#1
Thread Starter
Addicted Member
Hi,
If I created a ActiveX DLL in VB how can I load it at runtine without refrencing it.
example:
Code:
Public Declare Function MyHello Lib "PLUGIN.dll" Alias "Hello" (ByVal Name As String) As Long
What would the code in the ActiveX DLL and the program look like.
Please
-
Jun 1st, 2000, 03:10 PM
#2
Lively Member
Placing a reference to a dll when designing your project is called early binding. What you are after is late binding which you can do with CreateObject().
Dim objSomething as object
'Create the object based on the project name and
'class name.
Set objSomething = CreateObject("MyDll.MyObject")
'Call a method
objSomething.DoSomething
-
Jun 1st, 2000, 03:39 PM
#3
Thread Starter
Addicted Member
If I knew the path and filename of the DLL file but the DLL file was not registered, how could I create an Object for it.
For example:
In VB if you want to Refrence a DLL file. You could simple go to the Refrences Option and select from the list of already refrenced Objects of you could browse for the file.
How could I write a code that retrieves the information from a DLL file that it can you when you want to use the CreatOBject()
keep in mind that I know the path and filename of the DLL file, I just need to get the information from the DLL file so that I can use the CreateObject Function.
Example
dll_filepath = "c:\mydll.dll"
If I know the path and file name, how do I retrieve the information from the file in order to create an object.
Thanks.
[Edited by omarswan on 06-02-2000 at 04:42 AM]
-
Jun 1st, 2000, 05:47 PM
#4
Frenzied Member
This will populate a list with the classes present in an ActiveX DLL
The class names need to have been included in the resouce file for it to work
Code:
Option Explicit
Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Sub FillClassNameList(FileName As String)
' Get the list of classnames contined with a component from the components
' resource data.
' Set the error handler
'On Error GoTo GetClassNameListErr
Dim ModuleHandle As Long
Dim ClassNames() As String
ModuleHandle = LoadLibrary(FileName)
' Start by getting the number of classnames
Dim StringLength As Integer
Dim Buffer As String
Dim Length As Long
Dim NumClassNames As Long
Length = 255
Buffer = String(Length, vbNullChar)
StringLength = LoadString(ModuleHandle, 2, Buffer, Length)
NumClassNames = Val(Left(Buffer, StringLength))
' Create the storage space
ReDim ClassNames(NumClassNames)
' Loop thorugh all the class names adding them to the array
Dim Counter As Long
For Counter = 0 To NumClassNames - 1
Buffer = String(Length, vbNullChar)
StringLength = LoadString(ModuleHandle, Counter + 3, Buffer, Length)
'ClassNames(Counter) = Left(Buffer, StringLength)
List1.AddItem Left(Buffer, StringLength)
Next Counter
' Free the module
FreeLibrary ModuleHandle
End Sub
-
Jun 1st, 2000, 07:28 PM
#5
Thread Starter
Addicted Member
It's not working Mark
Hi,
Mark thanks for the code but it didn't work when I tried it. What coul I be dooing wrong?
-
Jun 4th, 2000, 02:42 PM
#6
Frenzied Member
omarswan
In what way didn't it work?
-
Jun 4th, 2000, 06:37 PM
#7
Thread Starter
Addicted Member
Hi Mark, This Is What I Did
Hi Mark,
this what I did.
1) I created a new exe Project with form1
2) I added a listbox
then...
Code:
Option Explicit
Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Sub FillClassNameList(FileName As String)
' Get the list of classnames contined with a component from the components
' resource data.
' Set the error handler
'On Error GoTo GetClassNameListErr
Dim ModuleHandle As Long
Dim ClassNames() As String
ModuleHandle = LoadLibrary(FileName)
' Start by getting the number of classnames
Dim StringLength As Integer
Dim Buffer As String
Dim Length As Long
Dim NumClassNames As Long
Length = 255
Buffer = String(Length, vbNullChar)
StringLength = LoadString(ModuleHandle, 2, Buffer, Length)
NumClassNames = Val(Left(Buffer, StringLength))
' Create the storage space
ReDim ClassNames(NumClassNames)
' Loop thorugh all the class names adding them to the array
Dim Counter As Long
For Counter = 0 To NumClassNames - 1
Buffer = String(Length, vbNullChar)
StringLength = LoadString(ModuleHandle, Counter + 3, Buffer, Length)
'ClassNames(Counter) = Left(Buffer, StringLength)
List1.AddItem Left(Buffer, StringLength)
Next Counter
' Free the module
FreeLibrary ModuleHandle
End Sub
Private Sub Form_Load()
Call FillClassNameList("C:\Omar\MyTemp\vbSendMail.dll")
End Sub
-
Jun 4th, 2000, 06:58 PM
#8
Frenzied Member
The code was taken from a project which consists of lots of small DLLs.
Each DLL has a resource file containing the class names
here's one of the resource file source-files
It was designed by another programmer but it works fine
resource.rc
Code:
// The string table
//
// The first entry (number 1) is the file name of the component.
// The second entry (number 2) is the number of class names in the list
// The next set of entries (starting at 3) is a list of all the class
// names in the component
// The remaining entries are application specific
//
// The Components installer looks at the first entries so it can get
// the names of the classes inside the component.
//
STRINGTABLE LOADONCALL MOVEABLE DISCARDABLE
BEGIN
1. "INVOIC Formatter.DLL"
2, "1"
3, "INVOIC2.Format"
END
using the rc.exe resource compiler you create a .RES file which you then include in your project.
Is this any help to you or do you need a more generic Look-inside-a-dll type of thing? if so repost your original question and I'll just mind my own business. 
-
Jun 5th, 2000, 02:18 AM
#9
You could register the dll first.
For this example I created a dll named testproject1.dll containing a class named testclass1.
Code:
Option Explicit
Private Declare Function DllRegisterServer Lib "c:\temp\testproject1.dll" () As Long
Private Sub Command1_Click()
Dim retVal As Long
Dim myClass As Object
retVal = DllRegisterServer
Set myClass = CreateObject("testproject1.testclass1")
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|