Announcement

Collapse
No announcement yet.

C to PB help

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

  • C to PB help

    Need to convert these two from C to PB

    Declare's

    void Upload( void *loadDat, unsigned int ULSize )

    void *DownLoad( unsigned int request_size)

    Call's

    char request[] = “\5\0\2\0\0\16\0\0”;

    Upload( request, 8 );

    char *response = DownLoad( 4096 );


    Thank you, Sorry I just don't know C

    Doug

    ------------------
    Doug McDonald
    KD5NWK
    www.redforksoftware.com

  • #2

    Doug, Try this:

    Code:
    Declare Sub Upload Lib "CDLL.DLL" Alias "Upload" (ByVal loadDat As Dword, ByVal ULSize As Dword)
     
    Declare Function DownLoad Lib "CDLL.DLL" Alias "DownLoad" (ByVal request_size As Dword) As Dword
     
    Function PBMain
        
      Local request As String
      request = Chr$(5,0,2,0,0,16,0,0)
      Upload(ByVal StrPtr(request), 8)
     
      Local response As Asciiz Ptr
      response = DownLoad(4096)
     
    End Function
    Since you are calling C, the functions a probably in a DLL, so I've used "CDLL.DLL" as a placeholder.

    ------------------
    kgpsoftware.com - Downloads
    kgpsoftware.com - Development and Consulting
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #3
      Thank you Kev, it gives me a great starting point

      Thanks again

      ------------------
      Doug McDonald
      KD5NWK
      www.redforksoftware.com

      Comment


      • #4
        Thanks again for your help.

        I keep getting "can't find DLL entry point" for both the
        sub & function

        I've tried with & without the ByVal's. I tried to get the
        source code for the .dll but no go. They only would give me
        the C code above.

        Any other thoughts?

        Thank You

        ------------------
        Doug McDonald
        KD5NWK
        www.redforksoftware.com

        Comment


        • #5
          One option would be to use a tool like pexports to dump the table of exported functions in the DLL. You can use that to determine what you should specify as the "alias" in your code.


          ------------------
          Mike Stefanik
          www.catalyst.com
          Catalyst Development Corporation

          [This message has been edited by Mike Stefanik (edited February 22, 2007).]
          Mike Stefanik
          sockettools.com

          Comment


          • #6
            >one option would be to use a tool like pexports

            or, if you are a powerbasic licensee, you could just compile show exports and imports for pb/win 6x, 7x (original by torsten reinow)


            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Thanks all.

              I did take your advice and used a utility to dump the table of
              exported functions in the DLL. I found the following:

              void Upload( void *loadDat, unsigned int ULSize )

              void *DownLoad( unsigned int request_size)

              are really:

              Upload is
              [email protected]

              Download is
              [email protected]


              At least I can run it without getting a "DLL entry point " error

              I now get GPF's so something is not being passed correctly
              I'd guess

              Again here is the 'C++' I have:

              Declare's

              void Upload( void *loadDat, unsigned int ULSize )

              void *DownLoad( unsigned int request_size)

              Call's

              char request[] = “\5\0\2\0\0\16\0\0”;

              Upload( request, 8 );

              char *response = DownLoad( 4096 );

              Here is my PB/WIN 8 code:

              DECLARE SUB upload LIB "pigusb.DLL" ALIAS "[email protected]" (BYVAL loadDat AS DWORD, ULSize AS DWORD)
              DECLARE FUNCTION downLoad LIB "pigusb.DLL" ALIAS "[email protected]"(BYVAL request_size AS DWORD) AS DWORD
              DECLARE SUB getusb()

              SUB getusb
              LOCAL ret AS DWORD
              LOCAL request AS STRING
              request = CHR$(5,0,2,0,0,16,0,0)
              upload (BYVAL STRPTR(request), 8)

              LOCAL response AS ASCIIZ PTR
              response = DownLoad(4096)
              CONTROL SET TEXT hDlg, %IDC_TEXTBOX1, STR$(response ) 'see if I get the ptr
              END SUB

              Thank you for any help. You guy's are GREAT


              ------------------
              Doug McDonald
              KD5NWK
              www.redforksoftware.com

              Comment


              • #8
                Add BYVAL to the ULSize parameter:

                DECLARE SUB upload LIB "pigusb.DLL" ALIAS "[email protected]" (BYVAL loadDat AS DWORD, BYVAL ULSize AS DWORD)

                ------------------
                Website: http://com.it-berater.org
                SED Editor, TypeLib Browser, COM Wrappers.
                Forum: http://www.forum.it-berater.org
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment


                • #9
                  Thanks Jose,

                  Tried that, no go. I'm tring to get the C / C++ dll source code.
                  I have a feeling their calls they sent me are incorrect.

                  For all I know its a 16bit dll but I doubt it. all I have to work with is what
                  I posted above. They did say something about Thunking

                  As a little background this .dll is the interface to a NETCHIP usb chip via netchip drivers


                  Thanks again, sorry to bother you all

                  Doug

                  ------------------
                  Doug McDonald
                  KD5NWK
                  www.redforksoftware.com

                  Comment


                  • #10

                    Doug,

                    The "@12" (decoration) in the call (usually) means that the parameters passed are 12-bytes long. Strange. Have you tried using STDCALL? The DLL is not 16-bit or it would not even load, I believe. Could be 64-bit, though. There is not enough information provided (there are many flavours of C\C++), this code is straight C. The compilation type is usually provided in the C project file.

                    Also, I use http://www.dependencywalker.com/ to check/analyze DLL exports/imports.

                    ------------------
                    kgpsoftware.com - Downloads
                    kgpsoftware.com - Development and Consulting
                    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                    Comment


                    • #11
                      Tanks Kev,

                      I did use Dependency walker, thats how I got the real sub/function names
                      I totally agree that the @12 would seem to indicate its looking for 12 bytes.
                      Too bad Dependency Walker doesn't show what params are passed, if it
                      does I don't know how.

                      I tried Stdcall, Cdecl ect....nothing worked

                      Your correct, I don't have enough info. I do believe they use Java

                      Here is all I got:

                      "My previous E-mail contained the two method signatures:

                      void Upload( void *loadDat, unsigned int ULSize )



                      void *DownLoad( unsigned int request_size)



                      I believe you may be able to load the dll and call these two without thinking about any USB protocol.



                      To send the request bytes to the pig might look something like this in C…



                      char request[] = “\5\0\2\0\0\16\0\0”;

                      Upload( request, 8 );

                      Followed by

                      char *response = DownLoad( 4096 );

                      to return a pointer to the actual data.

                      I don’t know the details of thunking and calling a dll in VB.net, but the procedure is probably quite similar. We do all our calls through two nearly identical methods in java."

                      BTW I'm not using VB.Net

                      Thanks again


                      ------------------
                      Doug McDonald
                      KD5NWK
                      www.redforksoftware.com

                      Comment

                      Working...
                      X