VB calling C++ Dll function twice? 
Author Message
 VB calling C++ Dll function twice?

Hi All,

I have created a C++ Dll and an application in VB that uses it. So far
so good... This Dll contains a function FindYourMove() that returns a
BSTR.  The following is the VB code:

Private Declare Function FindYourMove Lib "DraughtsDll.dll" () As
String
.
.
.
Private Sub picSquarePB_DragDrop(Index As Integer, source As Control,
X As Single, Y As Single)
    Dim boardStr As String
    If MustJump(Index) = 0 Then
        boardStr = FindYourMove()
        If (Mid(boardStr, 1, 3) = "END") Then
           'Do action 1
        Else
           'Do action 2
        End If
    End If

End Sub

Something was behaving very strangely and I used Trace to see step by
step what the program is doing.
I noticed that boardStr is always assigned a value returned from
FindYourMove (which is good) but sometimes (not always) FindYourMove()
is called a second time in the line:

If (Mid(boardStr, 1, 3) = "END") Then

I don't want it to do this as it gives a different result.
Does anyone know what's happening?

Thanks alot for your help...



Sat, 02 Oct 2004 02:57:50 GMT  
 VB calling C++ Dll function twice?
Its hard to believe that Mid is doing that, as boardstr is already assinged
a value but............ you never know.

Try 2 things:

1) Take the brackets away as Mid CAN actually be used to assign a value as
well as test a vlaue (i.e. can be used as a statement as well as a function.
2) Use Mid$ instead of Mid

Any other suggestions out there ?


Quote:
> Hi All,

> I have created a C++ Dll and an application in VB that uses it. So far
> so good... This Dll contains a function FindYourMove() that returns a
> BSTR.  The following is the VB code:

> Private Declare Function FindYourMove Lib "DraughtsDll.dll" () As
> String
> .
> .
> .
> Private Sub picSquarePB_DragDrop(Index As Integer, source As Control,
> X As Single, Y As Single)
>     Dim boardStr As String
>     If MustJump(Index) = 0 Then
>         boardStr = FindYourMove()
>         If (Mid(boardStr, 1, 3) = "END") Then
>            'Do action 1
>         Else
>            'Do action 2
>         End If
>     End If

> End Sub

> Something was behaving very strangely and I used Trace to see step by
> step what the program is doing.
> I noticed that boardStr is always assigned a value returned from
> FindYourMove (which is good) but sometimes (not always) FindYourMove()
> is called a second time in the line:

> If (Mid(boardStr, 1, 3) = "END") Then

> I don't want it to do this as it gives a different result.
> Does anyone know what's happening?

> Thanks alot for your help...



Sat, 02 Oct 2004 06:28:52 GMT  
 VB calling C++ Dll function twice?
Thanks alot Clive strangely enough by doing what you told me to do it
did work and Mid was actually calling that function twice... it's true
you never know :)
Thanks once again...
Quote:

> Its hard to believe that Mid is doing that, as boardstr is already assinged
> a value but............ you never know.

> Try 2 things:

> 1) Take the brackets away as Mid CAN actually be used to assign a value as
> well as test a vlaue (i.e. can be used as a statement as well as a function.
> 2) Use Mid$ instead of Mid

> Any other suggestions out there ?



> > Hi All,

> > I have created a C++ Dll and an application in VB that uses it. So far
> > so good... This Dll contains a function FindYourMove() that returns a
> > BSTR.  The following is the VB code:

> > Private Declare Function FindYourMove Lib "DraughtsDll.dll" () As
> > String
> > .
> > .
> > .
> > Private Sub picSquarePB_DragDrop(Index As Integer, source As Control,
> > X As Single, Y As Single)
> >     Dim boardStr As String
> >     If MustJump(Index) = 0 Then
> >         boardStr = FindYourMove()
> >         If (Mid(boardStr, 1, 3) = "END") Then
> >            'Do action 1
> >         Else
> >            'Do action 2
> >         End If
> >     End If

> > End Sub

> > Something was behaving very strangely and I used Trace to see step by
> > step what the program is doing.
> > I noticed that boardStr is always assigned a value returned from
> > FindYourMove (which is good) but sometimes (not always) FindYourMove()
> > is called a second time in the line:

> > If (Mid(boardStr, 1, 3) = "END") Then

> > I don't want it to do this as it gives a different result.
> > Does anyone know what's happening?

> > Thanks alot for your help...



Sat, 02 Oct 2004 16:47:17 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Calling a C++ DLL function which takes an C++ object as parameter

2. VB 5.0 calling C++ 5.0 DLL that calls winsock.dll

3. Calling a VB function from within a C++ DLL interrupt

4. Calling a VB function/procedure from Visual C++ DLL

5. Calling a function in a C++ Win32 Dll from VB 6

6. Calling a VB function from a C++ DLL

7. creating a callback function in c++ dll to callback a VB function in an exe

8. Calling VBA dll functions with C or C++

9. How do you call a Visual C++ (DLL) function from Visual Basic

10. Calling Visual C++ 5.0 DLL Functions From Visual Basic 5.0

11. Call C++ Class member function in a DLL ??

12. calling C++ functions from VB

 

 
Powered by phpBB® Forum Software