• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Calling functions from a plain old DLL?

D

Duncan Smith

#1
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 Computer

M

Matthias Tacke

#2
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 Computer

D

Duncan Smith

#3
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 Computer

O

Oisin Grehan

#4
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/GetTheOwnerOfAProcessInPowerShellPInvokeAndRefOutParameters.aspx

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

- Oisin
 

My Computer

H

Hal Rottenberg

#5
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.com/blog/cns!43CFA46A74CF3E96!291.entry
for one example.

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

My Computer

K

Keith Hill [MVP]

#6
"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/archive/2006/04/25/583236.aspx

--
Keith
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)