Direct DLL reference?

X

XP

Is there a way, using VBA to directly reference a DLL?

Please note, I'm NOT looking for code that selects a reference in Tools then
References, but instead allows a direct DLL call.

If so, your example code would be appreciated.

Thanks much.
 
C

Chip Pearson

See the Declare statement. E.g.,

Public Declare Function MyFunction Lib "FileName.dll" (Args As Whatever) As
Long

Sub AAA()
Dim Res As Long
Res = MyFunction(123,456)
End Sub

Note that (1) you cannot call functions in a DLL created in VB with this
syntax. VB can create only ActiveX DLLs that must be created as objects. (2)
the DLL function must have been compiled with the __stdcall directive, (3)
the function must have been included in the DEF file.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
E

ewm

Will this work to reference a .dll that was created using VS2008 and not
registered for COM interop?
 
C

Chip Pearson

Will this work to reference a .dll that was created using VS2008 and not
registered for COM interop?

No. The Declare statement is used for Win32 DLLs.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
Top