Results 1 to 4 of 4

Thread: divide by 0 error when calling VC++ dll from VB6

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    divide by 0 error when calling VC++ dll from VB6

    This is very strange to me, and I wonder if someone can tell me whats wrong and how to fix this:

    When I call a VC++ dll from VB6 the call is executed without error. However, any subsequent attempt to access a variable that was passed into and out of the dll results in a "runtime error 11 divide by zero". When I debug to the error, the error has vanished and I can access the variable fine (albeit err.number is still > 1, but the statement will execute. The statement that causes the error 11 is as simple as:

    myDbl = opt

    when in debug mode, just after the dll call I can hover over the passed value and see "opt=<division by zero". Then when I execute "myDBl = opt" it raises the error, but now I can hover over opt and see that it has a value and the statement will now execute.

    I could, of course do some tricks with loops and "on error resume next", but this would be bad practice and inefficient (speed is extremly critical), so I really want to understand the problem and fix it properly instead of tricks or workarounds.

    I have all of the source code for the dll.

    Any ideas?

    Code:
    declaration:
    Private Declare Function Sol Lib "si.dll" ( ...
    
    call:
    ret = Sol(m, 14, obj, func(0), cons(0), valu(0), typ(0), opt, res(0))
    
    dll structure:
    short _stdcall si(	short num_variables, 
    				short num_co,
    				short ob, 
    				double* function_co,
    				double* con_co,
    				double* con_val,
    				short* con_ine,
    				double* op_val,  
    				double* op_var_val 
    							)

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: divide by 0 error when calling VC++ dll from VB6

    How are you returning it out of the DLL? Chances are, you're returning a NULL pointer.. which, will be 0.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: divide by 0 error when calling VC++ dll from VB6

    Thanks for the reply.

    One of our guys just got it fixed. The stated reason for the behavior was that the value considered infinity was set too low and any division result over that value was considered divide by zero . Seems to be working now.

  4. #4
    New Member
    Join Date
    Oct 2010
    Posts
    1

    Re: divide by 0 error when calling VC++ dll from VB6

    I am also facing similar problem.
    Any idea how you got it fixed?
    Is there a way of setting Infinity in VBA?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width