Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with calling dll

Status
Not open for further replies.

engrfurqan

Programmer
Jan 5, 2009
20
I have two standard dll developed in VB and I am calling one of them in vba for word. This dll has a function which calls the other dll and returns an integer which should be passed to vba, code is bellow
/////
Public Declare Function Increment Lib "D:\VBA\VB Library Files\MathLib2.dll" (var2 As Integer) As Integer

Public Declare Function Decrement Lib "D:\VBA\VB Library Files\MathLib2.dll" (var2 As Integer) As Integer

Sub test()
MsgBox (Decrement(2))
MsgBox (Increment(1))
End Sub
/////

Decrement is a function present inside MathLib2.dll and it is not making any call to the other dll "MathLib3.dll" and its working fine
Increment is fucntion which is making a call to the other dll "MathLib3.dll" and returns an integer value. when this statement is excuting word has stoped working and after a while restarts automatically. I have used the same function in exe file and for that its working fine
can anybody help me in this regard.

Regards,
Furqan
 
Is the DLL Registered on the machine and refrenced in your project?

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
The dll is referenced in the project and registered on my pc
 
Increment is fucntion which is making a call to the other dll "MathLib3.dll" and returns an integer value. "

Perhaps posting the actual code may help. Please use the TGML code tags when posting code. Thanks.

Gerry
 
Here are the code

Mathlib2.dll
Code:
Option Explicit

Public Declare Function Increment1 Lib "D:\VBA\VB Library Files\MathLib3\MathLib3.dll" (var1 As Integer) As Integer
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(var As Integer) As Integer
   If Not IsNumeric(var) Then Err.Raise 5
   var = Increment1(var)
   Increment = var + 2
End Function

Public Function Decrement(var As Integer) As Integer
   If Not IsNumeric(var) Then Err.Raise 5
   
   Decrement = var - 1
End Function

Mathlib3.dll
Code:
Option Explicit

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 Increment1(var As Integer) As Integer
   If Not IsNumeric(var) Then Err.Raise 5
   Increment1 = var + 2
End Function

VBA for Word
Code:
Public Declare Function Increment Lib "D:\VBA\VB Library Files\MathLib2.dll" (var2 As Integer) As Integer

Public Declare Function Decrement Lib "D:\VBA\VB Library Files\MathLib2.dll" (var2 As Integer) As Integer

Sub test()
MsgBox (Decrement(2))
MsgBox (Increment(1))
End Sub
 
Have you tried to add the following in your Word VBA module ?
Public Declare Function Increment1 Lib "D:\VBA\VB Library Files\MathLib3\MathLib3.dll" (var1 As Integer) As Integer

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I have already tried it, not working but if I directly use function 'Increment1' that is inside Mathlib3.dll then it is working fine. The problem arises when one dll is calling other dll
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top