Windows Vista Forums

Calling functions from a plain old DLL?

  1. #1


    Duncan Smith Guest

    Calling functions from a plain old DLL?

    I need to interface with a bit of hardware whose API functions are
    exported from a plain old DLL (i.e. no COM, no NET)

    This must be akin to calling the Win32 API. Is Posh able to call a
    function from a DLL?

    Many thanks,

    Duncan


      My System SpecsSystem Spec

  2. #2


    Matthias Tacke Guest

    Re: Calling functions from a plain old DLL?

    Duncan Smith wrote:
    > I need to interface with a bit of hardware whose API functions are
    > exported from a plain old DLL (i.e. no COM, no NET)
    >
    > This must be akin to calling the Win32 API. Is Posh able to call a
    > function from a DLL?
    >


    See the posting from Bruce Payette
    in the thread "Invisible windows" stared by Jon on August 12.
    <http://groups.google.com/group/microsoft.public.windows.powershell/tree/browse_frm/thread/c37385b45cd188af/3a036972ba2eb089?rnum=1&hl=de&_done=%2Fgroup%2Fmicrosoft.public.windows.powershell%2Fbrowse_frm%2Fthread%2Fc37385b45cd188af%3Fhl%3Dde%26#doc_ded6fc99549c22de>


    He uses inline csharp code to access the winapi.

    HTH

    --
    Greetings
    Matthias

      My System SpecsSystem Spec

  3. #3


    Duncan Smith Guest

    Re: Calling functions from a plain old DLL?

    On Aug 16, 10:20 am, Matthias Tacke <Matth...@Tacke.de> wrote:
    > Duncan Smith wrote:
    > > I need to interface with a bit of hardware whose API functions are
    > > exported from a plain old DLL (i.e. no COM, no NET)

    >
    > > This must be akin to calling the Win32 API. Is Posh able to call a
    > > function from a DLL?

    >
    > See the posting from Bruce Payette
    > in the thread "Invisible windows" stared by Jon on August 12.
    > <http://groups.google.com/group/microsoft.public.windows.powershell/tr...>
    >
    > He uses inline csharp code to access the winapi.
    >
    > HTH
    >
    > --
    > Greetings
    > Matthias


    Good tip, thanks!


      My System SpecsSystem Spec

  4. #4


    Oisin Grehan Guest

    Re: Calling functions from a plain old DLL?

    On Aug 16, 4:18 am, Duncan Smith <DSmith1...@googlemail.com> wrote:
    > I need to interface with a bit of hardware whose API functions are
    > exported from a plain old DLL (i.e. no COM, no NET)
    >
    > This must be akin to calling the Win32 API. Is Posh able to call a
    > function from a DLL?
    >
    > Many thanks,
    >
    > Duncan


    An alternate way [to Mr Payette's method] is to use the Invoke-Win32
    function that Lee Holmes posted on his blog:

    http://www.leeholmes.com/blog/GetThe...arameters.aspx

    It's more "powershelly" than inline C#, but no less abstruse due to
    its heavy dependence on the BCL.

    - Oisin


      My System SpecsSystem Spec

  5. #5


    Hal Rottenberg Guest

    Re: Calling functions from a plain old DLL?

    On Aug 16, 4:18 am, Duncan Smith <DSmith1...@googlemail.com> wrote:
    > I need to interface with a bit of hardware whose API functions are
    > exported from a plain oldDLL(i.e. no COM, no NET)


    Just ran into a similar situation today where a dev here had made a
    DLL and said "here, you should be able to just use this in Powershell,
    right?" He's a .NET guy, but he didn't see an additional requirement
    which I just now pieced together. Here it is below for your benefit:

    1. The dev must create a strong name for his assembly so that it can
    be loaded into the Global Assembly Cache. See "How to install an
    assembly in the Global Assembly Cache in Visual Basic .NET or in
    Visual Basic 2005" <http://support.microsoft.com/kb/315682>. I don't
    know how far back this step goes, perhaps one of the devs on the list
    can answer that. In other words, I don't know if the "plain old DLL"
    you have would work in this case.

    2. Now you can use the steps that others have documented on how to get
    at the stuff in the assembly. See Richard Siddway's post:
    http://richardsiddaway.spaces.live.c...3E96!291.entry
    for one example.

    Question to the group: Does the term "assembly" indicate that
    something is using .NET?


      My System SpecsSystem Spec

  6. #6


    Keith Hill [MVP] Guest

    Re: Calling functions from a plain old DLL?

    "Hal Rottenberg" <halr9000@gmail.com> wrote in message
    news:1187964425.556042.89890@q5g2000prf.googlegroups.com...
    > On Aug 16, 4:18 am, Duncan Smith <DSmith1...@googlemail.com> wrote:
    >> I need to interface with a bit of hardware whose API functions are
    >> exported from a plain oldDLL(i.e. no COM, no NET)

    >
    > Just ran into a similar situation today where a dev here had made a
    > DLL and said "here, you should be able to just use this in Powershell,
    > right?" He's a .NET guy, but he didn't see an additional requirement
    > which I just now pieced together. Here it is below for your benefit:
    >
    > 1. The dev must create a strong name for his assembly so that it can
    > be loaded into the Global Assembly Cache. See "How to install an
    > assembly in the Global Assembly Cache in Visual Basic .NET or in
    > Visual Basic 2005" <http://support.microsoft.com/kb/315682>. I don't
    > know how far back this step goes, perhaps one of the devs on the list
    > can answer that. In other words, I don't know if the "plain old DLL"
    > you have would work in this case.


    I'm pretty sure that you can use non-strong named assemblies in PowerShell.
    To install into the GAC does indeed require a strong named assembly.
    However you should be able to do an [reflection.assembly]::loadFrom(<path to
    assembly>) to load an assembly that isn't in the GAC and that isn't strong
    named. Now you need to make sure that all the other assemblies this
    assembly depends on are in the same dir (or a probing path) or the GAC.
    However you can't put a "plain old DLL" in the GAC aka Global Assembly
    Cache - that place is reserved for the .NET assemblies only (well, and also
    ngned versions of assemblies).

    >
    > Question to the group: Does the term "assembly" indicate that
    > something is using .NET?


    Yep. I'm not sure if this link was already mentioned but it covers this
    scenario also:

    http://blogs.msdn.com/powershell/arc...25/583236.aspx

    --
    Keith



      My System SpecsSystem Spec


Calling functions from a plain old DLL?
Similar Threads
Thread Forum
Calling external Subs and Functions VB Script
Limitations when calling recursive functions PowerShell
calling functions from other scripts PowerShell
Log Parser - Plain, COM, .NET PowerShell
Calling functions confusion PowerShell