DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: Register a DLL in code and Call a function by address?

  1. #1
    Sean Woods Guest

    Register a DLL in code and Call a function by address?

    I have a couple of questions.

    The first is how does one register COM dll's via VB code? I know I could
    just shell to regsvr32 and use the silent mode but I was hoping for an API
    approach.

    The second is it possible to call a function by way of its address from
    inside of VB?

    As an example of the later, lets say I call LoadLibrary to load a specific
    DLL. Then I call GetProcAddress to get the address of a function inside the
    DLL. Now that I have this address how do I call the function from inside of
    VB?

    Thanks
    Sean Woods



  2. #2
    Rob Teixeira Guest

    Re: Register a DLL in code and Call a function by address?


    "Sean Woods" <swoods@eclickmd.com> wrote:
    >I have a couple of questions.
    >
    >The first is how does one register COM dll's via VB code? I know I could
    >just shell to regsvr32 and use the silent mode but I was hoping for an API
    >approach.


    Every COM dll exposes a DLLRegisterServer function (that you can then declare
    and call just like any API).

    >The second is it possible to call a function by way of its address from
    >inside of VB?


    a) there's no native VB(1-6) mechanism for it
    b) there are some ActiveX components out there that help you do this
    c) you can manually adjust the calling stackframe for the parameters and
    hack to the function call. This is particularly tricky. If i'm not mistaken,
    Matt Curland touches on the issue either in an article or in his book (been
    a while since i read it).
    Resist the urge to use CallWindowProc by itself to call the function, even
    if you see samples that do this. It's not entirely safe.
    d) VB.NET (or any .NET language for that matter) allows you to declare a
    function delegate and Invoke it

    -Rob

    >As an example of the later, lets say I call LoadLibrary to load a specific
    >DLL. Then I call GetProcAddress to get the address of a function inside

    the
    >DLL. Now that I have this address how do I call the function from inside

    of
    >VB?
    >
    >Thanks
    >Sean Woods
    >
    >



  3. #3
    Rob Teixeira Guest

    Re: Register a DLL in code and Call a function by address?


    "Sean Woods" <swoods@eclickmd.com> wrote:
    >I have a couple of questions.
    >
    >The first is how does one register COM dll's via VB code? I know I could
    >just shell to regsvr32 and use the silent mode but I was hoping for an API
    >approach.


    Every COM dll exposes a DLLRegisterServer function (that you can then declare
    and call just like any API).

    >The second is it possible to call a function by way of its address from
    >inside of VB?


    a) there's no native VB(1-6) mechanism for it
    b) there are some ActiveX components out there that help you do this
    c) you can manually adjust the calling stackframe for the parameters and
    hack to the function call. This is particularly tricky. If i'm not mistaken,
    Matt Curland touches on the issue either in an article or in his book (been
    a while since i read it).
    Resist the urge to use CallWindowProc by itself to call the function, even
    if you see samples that do this. It's not entirely safe.
    d) VB.NET (or any .NET language for that matter) allows you to declare a
    function delegate and Invoke it

    -Rob

    >As an example of the later, lets say I call LoadLibrary to load a specific
    >DLL. Then I call GetProcAddress to get the address of a function inside

    the
    >DLL. Now that I have this address how do I call the function from inside

    of
    >VB?
    >
    >Thanks
    >Sean Woods
    >
    >



  4. #4
    Peter Young Guest

    Re: Register a DLL in code and Call a function by address?

    > Matt Curland touches on the issue either in an article or in his book
    (been
    > a while since i read it).


    He shows how in his book:
    www.powervb.com

    and in the Feb. 2000 issue of VBPJ:
    http://www.devx.com/premier/mgznarch...200/mc0200.asp

    The technique works very well.



  5. #5
    Peter Young Guest

    Re: Register a DLL in code and Call a function by address?

    > Matt Curland touches on the issue either in an article or in his book
    (been
    > a while since i read it).


    He shows how in his book:
    www.powervb.com

    and in the Feb. 2000 issue of VBPJ:
    http://www.devx.com/premier/mgznarch...200/mc0200.asp

    The technique works very well.



  6. #6
    Matthew Curland Guest

    Re: Register a DLL in code and Call a function by address?

    It's not tricky if you're comfortable providing a typelib definition for the
    function you're calling. The VB6 mechanism (following Peter Young's jump)
    looks like:
    Dim FD As FunctionDelegator
    Dim pCall As ICallFoo
    Set pCall = InitDelegator(FD, FunctionAddress)
    pCall.Call p1, p2, p3 ...

    This is trivial if you have the FunctionDelegator structure.

    Also, you can't call a native function pointer in VB.NET (or C#) any easier
    than you can in VB6. You can easily get and call a function pointer (renamed
    to Delegate) to another .NET function, but not anything retrieved with
    LoadLibrary/GetProcAddress. -Matt

    "Rob Teixeira" <RobTeixeira@@msn.com> wrote in message
    news:3c3f558d$1@147.208.176.211...
    >
    > "Sean Woods" <swoods@eclickmd.com> wrote:
    > >I have a couple of questions.
    > >
    > >The first is how does one register COM dll's via VB code? I know I could
    > >just shell to regsvr32 and use the silent mode but I was hoping for an

    API
    > >approach.

    >
    > Every COM dll exposes a DLLRegisterServer function (that you can then

    declare
    > and call just like any API).
    >
    > >The second is it possible to call a function by way of its address from
    > >inside of VB?

    >
    > a) there's no native VB(1-6) mechanism for it
    > b) there are some ActiveX components out there that help you do this
    > c) you can manually adjust the calling stackframe for the parameters and
    > hack to the function call. This is particularly tricky. If i'm not

    mistaken,
    > Matt Curland touches on the issue either in an article or in his book

    (been
    > a while since i read it).
    > Resist the urge to use CallWindowProc by itself to call the function, even
    > if you see samples that do this. It's not entirely safe.
    > d) VB.NET (or any .NET language for that matter) allows you to declare a
    > function delegate and Invoke it
    >
    > -Rob
    >
    > >As an example of the later, lets say I call LoadLibrary to load a

    specific
    > >DLL. Then I call GetProcAddress to get the address of a function inside

    > the
    > >DLL. Now that I have this address how do I call the function from inside

    > of
    > >VB?
    > >
    > >Thanks
    > >Sean Woods
    > >
    > >

    >




  7. #7
    Matthew Curland Guest

    Re: Register a DLL in code and Call a function by address?

    It's not tricky if you're comfortable providing a typelib definition for the
    function you're calling. The VB6 mechanism (following Peter Young's jump)
    looks like:
    Dim FD As FunctionDelegator
    Dim pCall As ICallFoo
    Set pCall = InitDelegator(FD, FunctionAddress)
    pCall.Call p1, p2, p3 ...

    This is trivial if you have the FunctionDelegator structure.

    Also, you can't call a native function pointer in VB.NET (or C#) any easier
    than you can in VB6. You can easily get and call a function pointer (renamed
    to Delegate) to another .NET function, but not anything retrieved with
    LoadLibrary/GetProcAddress. -Matt

    "Rob Teixeira" <RobTeixeira@@msn.com> wrote in message
    news:3c3f558d$1@147.208.176.211...
    >
    > "Sean Woods" <swoods@eclickmd.com> wrote:
    > >I have a couple of questions.
    > >
    > >The first is how does one register COM dll's via VB code? I know I could
    > >just shell to regsvr32 and use the silent mode but I was hoping for an

    API
    > >approach.

    >
    > Every COM dll exposes a DLLRegisterServer function (that you can then

    declare
    > and call just like any API).
    >
    > >The second is it possible to call a function by way of its address from
    > >inside of VB?

    >
    > a) there's no native VB(1-6) mechanism for it
    > b) there are some ActiveX components out there that help you do this
    > c) you can manually adjust the calling stackframe for the parameters and
    > hack to the function call. This is particularly tricky. If i'm not

    mistaken,
    > Matt Curland touches on the issue either in an article or in his book

    (been
    > a while since i read it).
    > Resist the urge to use CallWindowProc by itself to call the function, even
    > if you see samples that do this. It's not entirely safe.
    > d) VB.NET (or any .NET language for that matter) allows you to declare a
    > function delegate and Invoke it
    >
    > -Rob
    >
    > >As an example of the later, lets say I call LoadLibrary to load a

    specific
    > >DLL. Then I call GetProcAddress to get the address of a function inside

    > the
    > >DLL. Now that I have this address how do I call the function from inside

    > of
    > >VB?
    > >
    > >Thanks
    > >Sean Woods
    > >
    > >

    >




  8. #8
    Sean Woods Guest

    Re: Register a DLL in code and Call a function by address?

    Peter's link and your code did the trick. I can now register and unregister
    the com dlls I wanted to from code and can check a "getVersion" function I
    place in all my none com dlls.

    Thanks a bunch.

    Sean

    "Matthew Curland" <mattcur@microsoft.com> wrote in message
    news:3c3f91fa$1@147.208.176.211...
    > It's not tricky if you're comfortable providing a typelib definition for

    the
    > function you're calling. The VB6 mechanism (following Peter Young's jump)
    > looks like:
    > Dim FD As FunctionDelegator
    > Dim pCall As ICallFoo
    > Set pCall = InitDelegator(FD, FunctionAddress)
    > pCall.Call p1, p2, p3 ...
    >
    > This is trivial if you have the FunctionDelegator structure.
    >
    > Also, you can't call a native function pointer in VB.NET (or C#) any

    easier
    > than you can in VB6. You can easily get and call a function pointer

    (renamed
    > to Delegate) to another .NET function, but not anything retrieved with
    > LoadLibrary/GetProcAddress. -Matt
    >
    > "Rob Teixeira" <RobTeixeira@@msn.com> wrote in message
    > news:3c3f558d$1@147.208.176.211...
    > >
    > > "Sean Woods" <swoods@eclickmd.com> wrote:
    > > >I have a couple of questions.
    > > >
    > > >The first is how does one register COM dll's via VB code? I know I

    could
    > > >just shell to regsvr32 and use the silent mode but I was hoping for an

    > API
    > > >approach.

    > >
    > > Every COM dll exposes a DLLRegisterServer function (that you can then

    > declare
    > > and call just like any API).
    > >
    > > >The second is it possible to call a function by way of its address from
    > > >inside of VB?

    > >
    > > a) there's no native VB(1-6) mechanism for it
    > > b) there are some ActiveX components out there that help you do this
    > > c) you can manually adjust the calling stackframe for the parameters and
    > > hack to the function call. This is particularly tricky. If i'm not

    > mistaken,
    > > Matt Curland touches on the issue either in an article or in his book

    > (been
    > > a while since i read it).
    > > Resist the urge to use CallWindowProc by itself to call the function,

    even
    > > if you see samples that do this. It's not entirely safe.
    > > d) VB.NET (or any .NET language for that matter) allows you to declare a
    > > function delegate and Invoke it
    > >
    > > -Rob
    > >
    > > >As an example of the later, lets say I call LoadLibrary to load a

    > specific
    > > >DLL. Then I call GetProcAddress to get the address of a function

    inside
    > > the
    > > >DLL. Now that I have this address how do I call the function from

    inside
    > > of
    > > >VB?
    > > >
    > > >Thanks
    > > >Sean Woods
    > > >
    > > >

    > >

    >
    >




  9. #9
    Sean Woods Guest

    Re: Register a DLL in code and Call a function by address?

    Peter's link and your code did the trick. I can now register and unregister
    the com dlls I wanted to from code and can check a "getVersion" function I
    place in all my none com dlls.

    Thanks a bunch.

    Sean

    "Matthew Curland" <mattcur@microsoft.com> wrote in message
    news:3c3f91fa$1@147.208.176.211...
    > It's not tricky if you're comfortable providing a typelib definition for

    the
    > function you're calling. The VB6 mechanism (following Peter Young's jump)
    > looks like:
    > Dim FD As FunctionDelegator
    > Dim pCall As ICallFoo
    > Set pCall = InitDelegator(FD, FunctionAddress)
    > pCall.Call p1, p2, p3 ...
    >
    > This is trivial if you have the FunctionDelegator structure.
    >
    > Also, you can't call a native function pointer in VB.NET (or C#) any

    easier
    > than you can in VB6. You can easily get and call a function pointer

    (renamed
    > to Delegate) to another .NET function, but not anything retrieved with
    > LoadLibrary/GetProcAddress. -Matt
    >
    > "Rob Teixeira" <RobTeixeira@@msn.com> wrote in message
    > news:3c3f558d$1@147.208.176.211...
    > >
    > > "Sean Woods" <swoods@eclickmd.com> wrote:
    > > >I have a couple of questions.
    > > >
    > > >The first is how does one register COM dll's via VB code? I know I

    could
    > > >just shell to regsvr32 and use the silent mode but I was hoping for an

    > API
    > > >approach.

    > >
    > > Every COM dll exposes a DLLRegisterServer function (that you can then

    > declare
    > > and call just like any API).
    > >
    > > >The second is it possible to call a function by way of its address from
    > > >inside of VB?

    > >
    > > a) there's no native VB(1-6) mechanism for it
    > > b) there are some ActiveX components out there that help you do this
    > > c) you can manually adjust the calling stackframe for the parameters and
    > > hack to the function call. This is particularly tricky. If i'm not

    > mistaken,
    > > Matt Curland touches on the issue either in an article or in his book

    > (been
    > > a while since i read it).
    > > Resist the urge to use CallWindowProc by itself to call the function,

    even
    > > if you see samples that do this. It's not entirely safe.
    > > d) VB.NET (or any .NET language for that matter) allows you to declare a
    > > function delegate and Invoke it
    > >
    > > -Rob
    > >
    > > >As an example of the later, lets say I call LoadLibrary to load a

    > specific
    > > >DLL. Then I call GetProcAddress to get the address of a function

    inside
    > > the
    > > >DLL. Now that I have this address how do I call the function from

    inside
    > > of
    > > >VB?
    > > >
    > > >Thanks
    > > >Sean Woods
    > > >
    > > >

    > >

    >
    >




  10. #10
    Michael Culley Guest

    Re: Register a DLL in code and Call a function by address?

    Sean,

    There is also an example of how to register/unregister a com dll and call
    non-com dll functions on my site. It uses all VB code. Download the call ptr
    example.

    --
    Michael Culley
    www.vbdotcom.com


    "Sean Woods" <swoods@eclickmd.com> wrote in message
    news:3c407e28$1@147.208.176.211...
    > Peter's link and your code did the trick. I can now register and

    unregister
    > the com dlls I wanted to from code and can check a "getVersion" function I
    > place in all my none com dlls.
    >
    > Thanks a bunch.
    >
    > Sean
    >
    > "Matthew Curland" <mattcur@microsoft.com> wrote in message
    > news:3c3f91fa$1@147.208.176.211...
    > > It's not tricky if you're comfortable providing a typelib definition for

    > the
    > > function you're calling. The VB6 mechanism (following Peter Young's

    jump)
    > > looks like:
    > > Dim FD As FunctionDelegator
    > > Dim pCall As ICallFoo
    > > Set pCall = InitDelegator(FD, FunctionAddress)
    > > pCall.Call p1, p2, p3 ...
    > >
    > > This is trivial if you have the FunctionDelegator structure.
    > >
    > > Also, you can't call a native function pointer in VB.NET (or C#) any

    > easier
    > > than you can in VB6. You can easily get and call a function pointer

    > (renamed
    > > to Delegate) to another .NET function, but not anything retrieved with
    > > LoadLibrary/GetProcAddress. -Matt
    > >
    > > "Rob Teixeira" <RobTeixeira@@msn.com> wrote in message
    > > news:3c3f558d$1@147.208.176.211...
    > > >
    > > > "Sean Woods" <swoods@eclickmd.com> wrote:
    > > > >I have a couple of questions.
    > > > >
    > > > >The first is how does one register COM dll's via VB code? I know I

    > could
    > > > >just shell to regsvr32 and use the silent mode but I was hoping for

    an
    > > API
    > > > >approach.
    > > >
    > > > Every COM dll exposes a DLLRegisterServer function (that you can then

    > > declare
    > > > and call just like any API).
    > > >
    > > > >The second is it possible to call a function by way of its address

    from
    > > > >inside of VB?
    > > >
    > > > a) there's no native VB(1-6) mechanism for it
    > > > b) there are some ActiveX components out there that help you do this
    > > > c) you can manually adjust the calling stackframe for the parameters

    and
    > > > hack to the function call. This is particularly tricky. If i'm not

    > > mistaken,
    > > > Matt Curland touches on the issue either in an article or in his book

    > > (been
    > > > a while since i read it).
    > > > Resist the urge to use CallWindowProc by itself to call the function,

    > even
    > > > if you see samples that do this. It's not entirely safe.
    > > > d) VB.NET (or any .NET language for that matter) allows you to declare

    a
    > > > function delegate and Invoke it
    > > >
    > > > -Rob
    > > >
    > > > >As an example of the later, lets say I call LoadLibrary to load a

    > > specific
    > > > >DLL. Then I call GetProcAddress to get the address of a function

    > inside
    > > > the
    > > > >DLL. Now that I have this address how do I call the function from

    > inside
    > > > of
    > > > >VB?
    > > > >
    > > > >Thanks
    > > > >Sean Woods
    > > > >
    > > > >
    > > >

    > >
    > >

    >
    >




  11. #11
    Michael Culley Guest

    Re: Register a DLL in code and Call a function by address?

    Sean,

    There is also an example of how to register/unregister a com dll and call
    non-com dll functions on my site. It uses all VB code. Download the call ptr
    example.

    --
    Michael Culley
    www.vbdotcom.com


    "Sean Woods" <swoods@eclickmd.com> wrote in message
    news:3c407e28$1@147.208.176.211...
    > Peter's link and your code did the trick. I can now register and

    unregister
    > the com dlls I wanted to from code and can check a "getVersion" function I
    > place in all my none com dlls.
    >
    > Thanks a bunch.
    >
    > Sean
    >
    > "Matthew Curland" <mattcur@microsoft.com> wrote in message
    > news:3c3f91fa$1@147.208.176.211...
    > > It's not tricky if you're comfortable providing a typelib definition for

    > the
    > > function you're calling. The VB6 mechanism (following Peter Young's

    jump)
    > > looks like:
    > > Dim FD As FunctionDelegator
    > > Dim pCall As ICallFoo
    > > Set pCall = InitDelegator(FD, FunctionAddress)
    > > pCall.Call p1, p2, p3 ...
    > >
    > > This is trivial if you have the FunctionDelegator structure.
    > >
    > > Also, you can't call a native function pointer in VB.NET (or C#) any

    > easier
    > > than you can in VB6. You can easily get and call a function pointer

    > (renamed
    > > to Delegate) to another .NET function, but not anything retrieved with
    > > LoadLibrary/GetProcAddress. -Matt
    > >
    > > "Rob Teixeira" <RobTeixeira@@msn.com> wrote in message
    > > news:3c3f558d$1@147.208.176.211...
    > > >
    > > > "Sean Woods" <swoods@eclickmd.com> wrote:
    > > > >I have a couple of questions.
    > > > >
    > > > >The first is how does one register COM dll's via VB code? I know I

    > could
    > > > >just shell to regsvr32 and use the silent mode but I was hoping for

    an
    > > API
    > > > >approach.
    > > >
    > > > Every COM dll exposes a DLLRegisterServer function (that you can then

    > > declare
    > > > and call just like any API).
    > > >
    > > > >The second is it possible to call a function by way of its address

    from
    > > > >inside of VB?
    > > >
    > > > a) there's no native VB(1-6) mechanism for it
    > > > b) there are some ActiveX components out there that help you do this
    > > > c) you can manually adjust the calling stackframe for the parameters

    and
    > > > hack to the function call. This is particularly tricky. If i'm not

    > > mistaken,
    > > > Matt Curland touches on the issue either in an article or in his book

    > > (been
    > > > a while since i read it).
    > > > Resist the urge to use CallWindowProc by itself to call the function,

    > even
    > > > if you see samples that do this. It's not entirely safe.
    > > > d) VB.NET (or any .NET language for that matter) allows you to declare

    a
    > > > function delegate and Invoke it
    > > >
    > > > -Rob
    > > >
    > > > >As an example of the later, lets say I call LoadLibrary to load a

    > > specific
    > > > >DLL. Then I call GetProcAddress to get the address of a function

    > inside
    > > > the
    > > > >DLL. Now that I have this address how do I call the function from

    > inside
    > > > of
    > > > >VB?
    > > > >
    > > > >Thanks
    > > > >Sean Woods
    > > > >
    > > > >
    > > >

    > >
    > >

    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center