how to use bind.exe (windows)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • allynm
    New Member
    • Apr 2010
    • 20

    #1

    how to use bind.exe (windows)

    Hello everyone,

    I am unsure how to invoke bind.exe from windows platform sdk. Looking for an example. The context here is how to bind a particular DLL to a calling program. Suppose that the caller is caller.exe and the dll is ydll.dll. How would I invoke bind.exe ?

    Thanks,
    Mark Allyn
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I believe you are talking about using the #import preprocessor directive at compile time.

    I think #import is Microsoft-specific and so I would research this in MSDN.

    #import assumes the dll is on project folder and it it's not you need to prvode a path to it by using your tools/options of VC++.

    Comment

    • allynm
      New Member
      • Apr 2010
      • 20

      #3
      Further on Bind.exe

      Hi Weaknessforcats ,

      Thanks for thinking over my query. I really appreciate your time and effort.

      I don't think bind.exe is related to preprocessing. Of course, I could be wrong. I have become extremely wary and insecure in matters of this sort.

      Bind.exe is a program available exclusively in Microsoft Platform SDK. My understanding is that it binds specific DLL exports to the IAT of a process. Thus, it alleviates the look-up problem the loader has at run-time. In one sense, it sort of defeats the purpose of having a DLL but the benefit seems to be faster program linking. Or, so it appears....to the unwashed (me).

      I have done some exploration in MSDN documentation. The results have been quite disappointing. It appears to be sort of a forgotten program. And yet, one of the MSFT linker options specifically prohibits binding if invoked which suggests that at least at some point MSFT cared about binding. One can indeed read about binding on Wikipedia in their entry on DLLs.

      The program is "for real". Or so it seems..

      Regards,
      Mark Allyn

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Usuallly you LoadLibrary at run time. Then using the returned HMODULE you call GetProcAddress using your function name ands then you typecast the returned FARPROC to a function pointer of the correct arguments and return type.

        If your DLL suppports __declspec(dlle xport) for the functions you want to call, then when the DLL is built a .lib file is created along with the .dll.

        This .lib can be used as a static library but when you call a functon in this lib you actaully call a wrapper that itself does the LoadLibrary, GetProcAddess and
        typecast for you.

        It appears the DLL is statically linked you to your code.

        Would this get you what you want? If so, check this out in MSDN.

        Comment

        • allynm
          New Member
          • Apr 2010
          • 20

          #5
          Further on the subject of dynamic/static loading

          Hi Weaknessforcats ,

          Thanks for your very compact and comprehensive reply. Your description of loadlibrary/getprocaddress is spot-on. I have written exactly this kind of code for explicit linking. (for some reason, I always have to go back and teach myself about function pointers every time I do this...)

          What had prompted my interest in BIND.exe goes back to my investigation of how the PE header works, and indeed, therefore, how the loader does its thing when it loads DLL's. In going through this maze I ran across references to BIND.exe and I was trying to discover how to use it and watch it at work with OLLY. There are very few fleeting references to BIND.

          In short, this is hardly a mission critical issue for me. But, I am the sort of nit-wit who wants to know how EVERYTHING works....

          Regards as always,
          Mark

          Comment

          Working...