Using C++ Dll library

G

Guest

I have a C++ DLL libarary (not COM) that I want to use in
VBA. Is it possible to use this library in VBA. If so,
how?
 
J

Jim Rech

I don't think it matters terribly what language a DLL was created in. As
far as I know you need to know what functions a DLL exports, what parameters
it expects, what it returns and then you need to "declare" these things.

Here's an example of using a Windows DLL (advapi32.dll):

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

Sub ShowUserName()
MsgBox UserName
End Sub

Function UserName() As String
Dim Buffer As String * 256
Dim BuffLen As Long
BuffLen = 256
If GetUserName(Buffer, BuffLen) Then _
UserName = Left(Buffer, BuffLen - 1)
End Function

--
Jim Rech
Excel MVP
|I have a C++ DLL libarary (not COM) that I want to use in
| VBA. Is it possible to use this library in VBA. If so,
| how?
 
C

Chip Pearson

Its worth noting that the C++ DLL function(s) must have been
compiled with the __stdcall option. Otherwise, you can't call
them.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top