Announcement

Collapse
No announcement yet.

Calling a PB DLL from VB

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

  • Wayne Diamond
    replied
    By george youve done it!!! first crack and all
    I think i had tried every combination except that one, thats the only problem - me
    This will definately come in handy over and over, thanks very much Lance - enjoy the weekend!


    ------------------

    Leave a comment:


  • Lance Edmonds
    replied
    What specific part are you having problems with? Parameter declaration problems, missing export, or...?

    The BYVAL DWORD parameter should work fine provided you pass the string BYVAL from VB (The BYVAL of a dynamic string in VB forces VB to translate VB's internal UNICODE string to a null-terminated ANSI string, and it then passes a pointer to that).

    Therefore, your BYVAL DWORD should receive the pointer address fine as long as you are passing BYVAL dynamicstring$.

    Something like this:
    Code:
    DECLARE FUNCTION CRC32HASH LIB "pbcrc32.dll" _
      ALIAS "CRC32HASH" (BYVAL Buf AS STRING, _
      BYVAL lBuf AS LONG, Crc AS LONG) AS LONG

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

    Leave a comment:


  • Wayne Diamond
    started a topic Calling a PB DLL from VB

    Calling a PB DLL from VB

    Ive put together a little DLL in PB simply to create a CRC32 hash based on the CRC32 code floating around this forum. I can call it easily from PB, but I need to also call it from a VB app...
    Here is the function exported from the PB DLL:
    Code:
    FUNCTION CRC32HASH (BYVAL ptrBuffer AS DWORD, BYVAL lenBuffer AS LONG, szReturn AS LONG) EXPORT AS LONG
    Here is how I call it in PB:
    Code:
    #COMPILE EXE
    #INCLUDE "win32api.inc"
      
    DECLARE FUNCTION CRC32HASH Lib "pbcrc32.dll" ALIAS "CRC32HASH" (BYVAL ptrBuffer AS DWORD, BYVAL lenBuffer AS LONG, szReturn AS LONG) AS LONG
      
    FUNCTION PBMAIN() AS LONG
    ON ERROR RESUME NEXT
    Dim MyString As String
    Dim ResultCrc AS Long
    MyString = "Test" & CHR$(0) & "Test"  'Note - cant use ASCIIZ, as string can have nullchars in it
    Dim Result AS LONG
    Result = CRC32HASH(STRPTR(MyString), LEN(MyString), ResultCrc)
    MSGBOX "Result=" & STR$(Result) & ", CRC=" & HEX$(ResultCrc)   'Should return 45862144
    END FUNCTION
    Ive been trying for the last few hours to call it from VB, but none of my combinations have worked. It seems straight-forward enough, just need to crack the combination! Any ideas anyone?


    [This message has been edited by Wayne Diamond (edited August 31, 2001).]
Working...
X