Re: How to call a function of an user defined DLL from Excel?
- From: "kounoike" <kounoike@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 9 May 2006 17:55:09 +0900
I'm not the original questioner, but i'm also interested in this subject
and had tried these referenced here a few weeks ago. What i did was like
this.
My code In VB6 is like this and make mylibtest.dll in C:\
Public Const DLL_PROCESS_DETACH = 0
Public Const DLL_PROCESS_ATTACH = 1
Public Const DLL_THREAD_ATTACH = 2
Public Const DLL_THREAD_DETACH = 3
Public Function DllMain(hInst As Long, fdwReason As Long, lpvReserved As
Long) As Boolean
Select Case fdwReason
Case DLL_PROCESS_DETACH
' No per-process cleanup needed
Case DLL_PROCESS_ATTACH
DllMain = True
Case DLL_THREAD_ATTACH
' No per-thread initialization needed
Case DLL_THREAD_DETACH
' No per-thread cleanup needed
End Select
End Function
Public Function Increment(ByVal var As Integer) As Integer
If Not IsNumeric(var) Then Err.Raise 5
Increment = var + 1
End Function
Public Function Decrement(ByVal var As Integer) As Integer
If Not IsNumeric(var) Then Err.Raise 5
Decrement = var - 1
End Function
Public Function Square(ByVal var As Long) As Long
If Not IsNumeric(var) Then Err.Raise 5
Square = var ^ 2
End Function
Public Function mytrim2(ByVal str As String) As String
Do While InStr(1, str, " ", vbBinaryCompare) > 0
str = Replace(str, " ", " ", 1, -1, vbBinaryCompare)
Loop
mytrim2 = str
End Function
Public Function myrepeat(ByVal str As String, ByVal n As Long) As String
Dim tmp As String
Do While n > 0
tmp = tmp & str
n = n - 1
Loop
myrepeat = tmp
End Function
and decleare these in VB6 and in VBA
Public Declare Function Increment Lib "C:\mylibtest.dll" ( _
ByVal value As Integer) As Integer
Public Declare Function Decrement Lib "C:\mylibtest.dll" ( _
ByVal value As Integer) As Integer
Public Declare Function Square Lib "C:\mylibtest.dll" ( _
ByVal value As Long) As Long
Public Declare Function mytrim2 Lib "C:\mylibtest.dll" ( _
ByVal str As String) As String
Public Declare Function myrepeat Lib "C:\mylibtest.dll" ( _
ByVal str As String, ByVal n As Long) As String
these functions work without any troubles in VB6. so, i tried these
functions in VBA. but only Increment, Decrement, Square work fine and
when i tried myrepeat or mytrim2, Excel always crashes. I can't
understand why these work well in VB but not in VBA. i apreciate any
advice or workaround to work myrepeat and mytrim2 in VBA.
Thanks in advance.
keizi
"Paul" <Paul@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CF39AB6E-C089-49D4-9130-6B762E204CAF@xxxxxxxxxxxxxxxx
Hi, I am doing something similar right now. here is what I know. Tryusing
the following link below.http://www.windowsdevcenter.com/pub/a/windows/2005/04/26/create_dll.html
This next example I got off the web. I don't have the addess but wecan
discuss this offline. if want further help.
.
- References:
- Prev by Date: Re: Using Ms form in Pocket Excel
- Next by Date: Rand function
- Previous by thread: RE: How to call a function of an user defined DLL from Excel?
- Next by thread: Re: How to call a function of an user defined DLL from Excel?
- Index(es):
Relevant Pages
|