- Aug
- 2,320
- 111
I have the following function defined in my PowerShell profile;
This allows me to call Take Command internal functions and commands from PowerShell.
Loading tcc.exe this way is fast, but I was looking for a way to make it faster.
The method I am testing now is using Platform Invoke to call the internal functions and commands from the unmanaged TakeCmd.dll file.
I am using the TakeCmd.h file from the plugin SDK as a guide.
First, I have created a TakeCmd.ps1 file containing C# code to define a command and a function that exist in the unmanaged TakeCmd.dll file;
I load this in PowerShell as;
I can see the class members;
I then change to the folder where the unmanaged TakeCmd.dll is located;
...and I can beep (honk);
When I invoke the GetExeType function;
...the return value is not correct.
Here is GetExeType from TakeCmd.h;
For the example function I am testing, GetExeType, I would appreciate input from the PowerShell folks on how to properly define the DllImport, and how to properly get the return value from this example.
Joe
Code:
function tcc
{
& "c:\program files\jpsoft\tcmd25\tcc.exe" /I /Q /C $args
}
This allows me to call Take Command internal functions and commands from PowerShell.
Loading tcc.exe this way is fast, but I was looking for a way to make it faster.
The method I am testing now is using Platform Invoke to call the internal functions and commands from the unmanaged TakeCmd.dll file.
I am using the TakeCmd.h file from the plugin SDK as a guide.
First, I have created a TakeCmd.ps1 file containing C# code to define a command and a function that exist in the unmanaged TakeCmd.dll file;
Code:
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public static class TakeCmd
{
[DllImport("takecmd.dll", CharSet = CharSet.Auto)]
public static extern void honk();
[DllImport("takecmd.dll", CharSet = CharSet.Auto)]
public static extern int GetExeType( string pszFilename );
}
'@
I load this in PowerShell as;
Code:
PS E:\Utils> .\takecmd.ps1
I can see the class members;
Code:
PS E:\Utils> [takecmd] | get-member -static
TypeName: TakeCmd
Name MemberType Definition
---- ---------- ----------
Equals Method static bool Equals(System.Object objA, System.Object objB)
GetExeType Method static int GetExeType(string pszFilename)
honk Method static void honk()
ReferenceEquals Method static bool ReferenceEquals(System.Object objA, System.Object objB)
I then change to the folder where the unmanaged TakeCmd.dll is located;
Code:
PS E:\Utils> [environment]::CurrentDirectory = 'c:\program files\jpsoft\tcmd25'
...and I can beep (honk);
Code:
PS E:\Utils> [TakeCmd]::honk()
When I invoke the GetExeType function;
Code:
PS E:\Utils> [TakeCmd]::GetExeType(".\WMIGen.exe")
-2
PS E:\Utils> [TakeCmd]::GetExeType("WMIGen.exe")
-2
...the return value is not correct.
Here is GetExeType from TakeCmd.h;
Code:
INT WINAPI GetExeType( LPCTSTR pszFilename );
/*
Returns an integer specifying the type of executable:
0 // Error, or not an EXE file
1 // Just plain old MS-DOS
2 // DOS app with a PIF file
3 // Windows 3.x
4 // Windows 3.x VxD
5 // OS/2 2.x
6 // Windows NT, 2000, XP, or 2003 GUI
7 // Windows NT, 2000, XP, or 2003 console mode
8 // Windows NT, 2000, XP, or 2003 Posix
9 // Windows x64 GUI
10 // Windows x64 console
11 // EFI
12 // EFI boot driver
13 // EFI runtime driver
14 // EFI ROM
15 // XBox
16 // Windows boot application
*/
For the example function I am testing, GetExeType, I would appreciate input from the PowerShell folks on how to properly define the DllImport, and how to properly get the return value from this example.
Joe