Announcement

Collapse
No announcement yet.

using a DLL in PBCC

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

  • using a DLL in PBCC

    I thought this would be simple, but I'm having no luck finding information. I have a DLL that I created in PB/Win 8 (actually, it shouldn't really matter where it came from). Can I use it in PBCC as a function?

    More generally, I'm trying to include an already-compiled (or DLL-compiled) function into my PBCC source code for the purposes of obscuring what's in the function. I want to write PBCC source code and make it available to others without them being able to see inside a particular function. I thought a DLL would be the perfect way. I've used DLLs with other apps, so I know how to set them up. But now, how to let PBCC accept them?

    Any other methods anyone can think of? The #INCLUDE directive looked promising, but alas, cannot do this.

    Thanks,
    Christopher
    Christopher P. Becker
    signal engineer in the defense industry
    Abu Dhabi, United Arab Emirates

  • #2
    A simple DECLARE FUNCTION ExternalFunctionName LIB "library.dll" will enable you to call external functions as if they are part of your code. See the help file under DECLARE and the "win32api.inc" file for plenty of examples. Remember to use the "ALIAS" keyword if the function exported by the DLL is not in upper-case (PB defaults to upper-case).

    #INCLUDE only needs to be used when you have the DECLARE statements for the DLL in another source code file (a good idea if you will be distributing the DLL to others, so you can distribute the DLL and this source file).
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #3
      Kevin touched on this but perhaps it should be emphasized. The function in your dll must have EXPORT before the AS clause in order to be used by another program.

      FUNCTION MYFUNCT(parameter1,parameter2...) EXPORT AS LONG/STRING,etc
      Client Writeup for the CPA

      buffs.proboards2.com

      Links Page

      Comment


      • #4
        Simple example ...

        DLL:
        Code:
        #COMPILE DLL "MYDLL.DLL"
        #INCLUDE "Win32API.inc"
        
        SUB ShowMsg ALIAS "ShowMsg" (sMsg AS STRING) EXPORT
          MSGBOX sMsg
        END SUB
        
        FUNCTION LIBMAIN (BYVAL hInstance   AS LONG, _
                          BYVAL fwdReason   AS LONG, _
                          BYVAL lpvReserved AS LONG) AS LONG
        FUNCTION = 1
        END FUNCTION
        EXE:
        Code:
        #COMPILE EXE
        
        DECLARE SUB ShowMsg LIB "mydll.dll" ALIAS "ShowMsg" (sMsg AS STRING)
        
        FUNCTION PBMAIN() AS LONG
         ShowMsg "Display this"
         $IF %DEF(%PB_CC32)
           STDOUT "Press a key to continue...";: WAITKEY$
         $ENDIF
        END FUNCTION
        The EXPORT statement must be used to make a sub or function available, and the ALIAS statement must be used to ensure case sensitivity - if it's not specified the function name (ShowMsg in this case) will be stored in uppercase as SHOWMSG.
        Last edited by Wayne Diamond; 25 Jul 2008, 04:01 AM.
        -

        Comment


        • #5
          It works

          Sorry, I should have replied sooner. I got it to work with the first suggestion. I figured it was something fairly simple.
          Christopher P. Becker
          signal engineer in the defense industry
          Abu Dhabi, United Arab Emirates

          Comment

          Working...
          X