Announcement

Collapse
No announcement yet.

Codeprt - Pointers - Callback, Can anyone help?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Codeprt - Pointers - Callback, Can anyone help?

    I have C proggram as follow:
    BOOL Init(FARPROC scDone, FARPROC fpError)
    This inisialise one of Mydll which will callback fpError procedure when it detectes some error.
    The fpError procedure is as follows:
    void fpError(DWORD MyError, DWORD MyType)
    { }

    Now I wanted to convert this code to Powerbasic so I did the following:
    ' Declare the Function
    Declare FUNCTION Init LIB "Mydll.dll" ALIAS "Init" (ByVal scDone AS long, ByVal fpError AS long) AS LONG
    'Do the inisialisation
    i = Init(CODEPTR(scDone),CODEPTR(fpError))
    'fpError Procedure
    FUNCTION fpError(MyError As long, MyType As long) As long
    MSGBOX Str$(TypeErr) & "-" & Str$(MyError)
    FUNCTION = 1
    END FUNCTION

    Now I have tried changing the long Type to DWord but with both types

    Whenever there is a callback my progg. crashes.
    This works fine in VB with Addressof but I wanted to use PB.
    If I do not put the parameters MyError and MyType it does not crash.

    Can anyone understand this and help me out.

    Thank You




    -------------
    Niraj Bhatt

  • #2
    As C uses BYVAL parameters per default and PB uses BYREF, you have to specify BYVAL explicitly in your fpError() function.

    Regards

    -------------
    Daniel
    [email protected]

    Comment


    • #3
      Daniel,

      Thank you...

      I have gone past one phase.. Initially it was crashing as soon as there was a callback without proceding inside the procedure now that I have make the correcting as follows:

      FUNCTION fpError(ByVal MyErr As Dword, ByVal ErrType As Dword) As long
      'OR
      'FUNCTION fpError(ByVal MyErr As Long, ByVal ErrType As Long) As long
      MSGBOX Str$(MyErr) & "-" & Str$(ErrType)
      FUNCTION = 1
      END FUNCTION

      Now it crashes after going through the procedure, thatis after displaying the msgbox.

      If somebody can understand this is the error I am getting:
      PRINTE~1 caused an invalid page fault in
      module <unknown> at 00de:8178af08.
      Registers:
      EAX=00000000 CS=015f EIP=8178af08 EFLGS=00010202
      EBX=00000000 SS=0167 ESP=0117ff00 EBP=0117ff38
      ECX=00000000 DS=0167 ESI=10001f00 FS=4f9f
      EDX=8000a310 ES=0167 EDI=8178af08 GS=0000
      Bytes at CS:EIP:
      07 00 01 00 70 d6 a3 d0 dc fc 17 01 00 00 18 01
      Stack dump:
      00000008 00000000 00000000 00000000 00000001 8178af08 00000001 d0a45e14 81782b1c 0117fd30 0117ff88 bffbfe14 bff791f0 00000000 0117ff98 bff88ba5


      -------------
      Niraj Bhatt

      Comment


      • #4
        void fpError(DWORD MyError, DWORD MyType)
        =
        Sub fpError(Byval MyError as DWord,Byval MyType as DWord)

        -------------
        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se

        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se

        Comment


        • #5
          Tried that as well but same result, it still crashes after the msgbox

          -------------
          Niraj Bhatt

          Comment


          • #6
            Try using CDECL for your declaration.

            -------------
            Daniel
            [email protected]

            Comment


            • #7
              Where's your code for scDone? Perhaps that's where it's crashing.

              --Dave


              -------------
              PowerBASIC Support
              mailto:[email protected][email protected]</A>

              Home of the BASIC Gurus
              www.basicguru.com

              Comment


              • #8
                Thank you very much Daniel
                Actuly I have to use CDECL in the procedure so it is like this

                SUB fpError Cdecl (ByVal MyError As Dword,ByVal MyType As Dword)

                End Sub

                As the Dll which makes the call back is written in C++, I think it was crashing while trying to clear the stack while leaving the procedure and that is why I was able to see the msgbox and then it was crashing.

                Thank you everyone for the support.

                -------------
                Niraj Bhatt

                Comment

                Working...
                X