Re: How to call a function of an user defined DLL from Excel?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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. Try
using
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 we
can
discuss this offline. if want further help.


.



Relevant Pages

  • Re: Line too long ???
    ... procedure CorrectLineBreaks(FPN: string); ... Str: string; ...
    (comp.lang.pascal.delphi.misc)
  • Re: How to calculate if it fits
    ... You don't say the string you used ... Str: String; ...
    (comp.lang.pascal.delphi.misc)
  • Re: Question regarding use of TStrings as a function parameter
    ... You don't need to use the var parameter if you're passing an object. ... since I'm not passing an object, but a string type: ... procedure TForm1.ChangeMe(var Str: string); ...
    (borland.public.delphi.language.objectpascal)
  • Re: Abfrage, ob Formular vorhanden ist
    ... Public Function DeleteForm(str As String) As Boolean ... If Isopen(str) Then DoCmd.Close acForm, str, acSaveNo ...
    (microsoft.public.de.access)
  • Re: String replace
    ... Try writting your own replace method and add this method to the String ... var idx = str.indexOf; ... return str; ...
    (comp.lang.javascript)