Calling functions from a plain old DLL?


  1.    16 Aug 2007 #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.    16 Aug 2007 #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.    16 Aug 2007 #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.    16 Aug 2007 #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.    24 Aug 2007 #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.    24 Aug 2007 #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
Just plain slow...
Anyway to speed things up? The File database does not seem as fast as the Express db file format. Anyway to improve it? Do I need Raid with...
Live Mail
Switching to plain text...
How the heck do we switch to plain text when composing in Windows Live Mail (ie Hotmail)?
Live Mail
Calling external Subs and Functions
It says here that Public Sub "indicates that the Sub procedure is accessible to all other procedures in all scripts". That sounds to me like I can...
VB Script
Limitations when calling recursive functions
I have this function to calculate a factorial value function fact( $x ) { ( ?: { $x -lt 2 } { return 1} { $x * ( fact ($x -1) ) }) } Which...
PowerShell
calling functions from other scripts
Hi, I undestand it's possible to call functions from other script, for instance, if I had a script called Foo.ps1 in c:\temp\, which contains...
PowerShell
Log Parser - Plain, COM, .NET
First the plain Log Parser version. Windows PowerShell Copyright (C) 2006 Microsoft Corporation. All rights reserved. PS> LogParser "SELECT...
PowerShell
Calling functions confusion
I have a simple funciton: function foo($dir, $pathspec) { "`$dir is $dir/$($dir.GetType().Name), `$pathspec is...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • Old server
    About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 19:30.
    .