Announcement

Collapse
No announcement yet.

How to import PB-dll in C++

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

  • How to import PB-dll in C++

    This is actually a C++ question, so this is maybe not the right forum. I would like to import a PB-dll in C++. Has anyone tried that? I am using VC++ version 6.

    Regards
    Peter

  • #2
    Since PB/DLL does not create import libs, you will have to use explicit linking. This is done by using LoadLibrary(), GetProcAddress(), FreeLibrary(). You will still have to create a header file for all of the functions, but will now have to use function pointers that are returned by GetProcAddress().
    In VB & PB, the compiler does all this for you when you use the LIB setting on a function DECLARE.


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

    Comment


    • #3
      Two more things, PB thinks of everything in uppercase by default. You will have to use function aliases in your PB code OR reference them in all caps.
      Also, PB follows standard calling conventions by default, but you can specify CDECL. It's your call on how you use either.
      Example: load foo.dll, get SayHello function, call it.
      Code:
      PB Code:
      FUNCTION SayHello(BYREF pszText AS ASCIIZ) EXPORT AS LONG
        pszText = "Hello!"
      END FUNCTION
      
      C Code:
      #include <windows.h>
      typedef int __stdcall SAYHELLO(CHAR* pszTest);
      int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {
       UCHAR szText[120];
       HMODULE hMyDll;
       SAYHELLO* pSayHello;
       long r;
      
       hMyDll = LoadLibrary("foo.dll");
       if (hMyDll == NULL) MessageBox(0, "Failed to load dll", NULL, 0);
       else {
         pSayHello = (SAYHELLO*)GetProcAddress(hMyDll,"SAYHELLO");
         if (pSayHello == NULL) MessageBox(0, "Failed to find func", NULL, 0);
         else {
           r = pSayHello(szText);
           MessageBox(0, szText, NULL, 0);
         }
       }
       FreeLibrary(hMyDll);
       MessageBox(0,"Done!",NULL,0);
      }

      [This message has been edited by Enoch S Ceshkovsky (edited June 12, 2000).]

      Comment


      • #4
        Two more things, PB thinks of everything in uppercase by default. You will have to use function aliases in your PB code OR reference them in all caps.

        FUNCTION SayHello Alias SayHello(BYREF pszText AS ASCIIZ) EXPORT AS LONG

        Like this?

        Jim had shown me how to do this, not sure if i still have that exampe or not though...


        That's a lot of functions for me to update, I've got 4 common DLL's now LOL


        Scott

        ------------------
        Scott
        mailto:[email protected][email protected]</A>
        MCSE, MCP+Internet
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment


        • #5
          Thanks!

          Regards
          Peter

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

          Comment

          Working...
          X