Calling customized DLL function fails

M

maribet

Hello everybody,

I have a problem with calling a DLL, writen in C++, from my Excel
macro.
The function calls work with 90% of all our users but there are two
customers, where the functions are simply not executed. No error occurs
and the function returnvalue is set to 0, meaning OK.
They are both working with different machines, OS and excel versions,
so I don't think it's a version problem.

I made a special diagnosis version, showing messageboxes before and
after the function call and also from the DLL functions.
My customers get the messages from the excel macro but no messages from
the dll. Nevertheless the returnvalue is changed from 5 to 0. There is
no error message at all.

Here is, how I call the function:

Public Declare Function CalcPlanetCoordinates Lib "SemRaumTest4" (v()
As Double, ByRef x As Double, ByRef y As Double, ByVal lpName As
String) As Long

Public Sub CalculatePlanets()

Dim ret As Long
Dim x As Double
Dim y As Double
Dim vals As Range

ReDim v(0 To anzAttribs - 1) As Double

For pl = 1 To anzPlanets

'Fill vector v() with double values from spreadsheet
Set vals = Range(ActiveCell.Offset(1, pl),
ActiveCell.Offset(anzAttribs, pl))
For at = 0 To anzAttribs - 1
v(at) = CDbl(vals.Range("A" & (at + 1)).Value)
Next at

'x and y are passed by reference and after the function call
contain the results!
x = 99.99
y = 88.88
ret = 5

MsgBox "Start calling SemRaumTest4.Dll" & vbNewLine & _
"Parameter x = " & CStr(x) & vbNewLine & _
"Parameter y = " & CStr(y) & vbNewLine & _
"returnvalue = " & CStr(ret), vbOKOnly

ret = CalcPlanetCoordinates(v, x, y, "")

MsgBox "End calling SemRaumTest4.Dll" & vbNewLine & _
"Parameter x = " & CStr(x) & vbNewLine & _
"Parameter y = " & CStr(y) & vbNewLine & _
"returnvalue = " & CStr(ret), vbOKOnly

If ret = 5 Then
MsgBox "DLL function was not executed!", vbOKOnly
ret = 0
End If

'Write results to spreadsheet
If ret = 0 Then
ActiveCell.Offset(21, pl).Value = x
ActiveCell.Offset(22, pl).Value = y
Dim name As String
name = ActiveCell.Offset(0, pl).Text
CreateNewPlanetPoint x, y, name, pl
Else
ActiveCell.Offset(21, pl).Value = "DLL-Fehler " & CStr(ret)
ActiveCell.Offset(22, pl).Value = "DLL-Fehler " & CStr(ret)
End If
Next pl

Application.ScreenUpdating = True

End Sub

Has somebody an idea, what is happening here? I am totaly clueless at
the moment and would appreciate any help.
 

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