Microsoft appears to be moving a lot of configuration and query capabilities to PowerShell (accessible from C# or managed C++), while deprecating and even removing older APIs (accessible for C or unmanaged C++). Those of us who have extensive unmanaged C++ programs that can't switch to managed C++ may have a need to call PowerShell cmdlets (at least, I have one now) -- how can we do so?
Microsoft似乎将大量配置和查询功能转移到PowerShell(可从C#或托管C ++访问),同时弃用甚至删除旧的API(可访问C或非托管C ++)。我们这些拥有无法切换到托管C ++的大量非托管C ++程序的人可能需要调用PowerShell cmdlet(至少我现在有一个) - 我们怎么能这样做?
There are suggestions that a reverse-PInvoke (managed/unmanaged thunking) might be able to do something, but I'm hoping for a better way than either thunking or parsing text output from a PowerShell script.
有人建议反向PInvoke(托管/非托管thunking)可以做一些事情,但我希望有一种比从PowerShell脚本中解析或解析文本输出更好的方法。
[Note: This is a reworked and generalized query I made yesterday that may have been too specialized.]
[注意:这是我昨天做的一个经过重新设计和概括的查询,可能过于专业化了。
1 个解决方案
#1
The MS suggestion would probably be to compile specific classes/modules in your generally unmanaged C++ app as managed code (compiling individual files with /clr), and letting the IJW transition code manage the calls to/from it (and calling PowerShell API's from the managed bits). I've been told (from MS VC++ people) that's the expected methodology for adding bits of managed calls to large unmanaged applications.
MS的建议可能是在你的普通非托管C ++应用程序中编译特定的类/模块作为托管代码(使用/ clr编译单个文件),并让IJW转换代码管理对它的调用(并从中调用PowerShell API)管理位)。我被告知(来自MS VC ++人员),这是向大型非托管应用程序添加托管调用的预期方法。
Hope that helps.
希望有所帮助。
#1
The MS suggestion would probably be to compile specific classes/modules in your generally unmanaged C++ app as managed code (compiling individual files with /clr), and letting the IJW transition code manage the calls to/from it (and calling PowerShell API's from the managed bits). I've been told (from MS VC++ people) that's the expected methodology for adding bits of managed calls to large unmanaged applications.
MS的建议可能是在你的普通非托管C ++应用程序中编译特定的类/模块作为托管代码(使用/ clr编译单个文件),并让IJW转换代码管理对它的调用(并从中调用PowerShell API)管理位)。我被告知(来自MS VC ++人员),这是向大型非托管应用程序添加托管调用的预期方法。
Hope that helps.
希望有所帮助。