Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Powershell code failed to run
#4
thank you for your reply,

In order to get faster, I am trying to achieve the same functionality using C# code.

I encountered two problems when running the code

1. Unable to register component

2. How to get the return value

The following are the code of the powershell and C#, the powershell code can run successfully, But the above problems exist in the C# code.
Any suggestions are welcome, thanks in advance

Can you combine powershell code and C# code and QM code into one file, and test the execution speed of each piece of code?
This is a good example of The QM calling a third-party C# component.   Smile


Macro QM Run PS Code
Code:
Copy      Help
;Requires 32-bit components Link: http://www.chilkatsoft.com/downloads_DotNet.asp
;Put the dll file in the location C:\Chilkat\ChilkatDotNet47.dll
str code=
;[Reflection.Assembly]::LoadFile("C:\Chilkat\ChilkatDotNet47.dll")
;
;$json = New-Object Chilkat.JsonObject
;
;#  The only reason for failure in the following lines of code would be an out-of-memory condition..
;
;#  An index value of -1 is used to append at the end.
;$index = -1
;
;$success = $json.AddStringAt(-1, "Title", "Pan's Labyrinth")
;$success = $json.AddStringAt(-1, "Director", "Guillermo del Toro")
;$success = $json.AddStringAt(-1, "Original_Title", "El laberinto del fauno")
;$success = $json.AddIntAt(-1, "Year_Released", 2006)
;
;$json.EmitCompact = $false
;$($json.Emit())

PsCmd3 code "" _s
out _s  ;;Can get the return result


Macro QM Run C# Code
Code:
Copy      Help
;Requires 32-bit components Link: http://www.chilkatsoft.com/downloads_DotNet.asp
;Put the dll file in the location C:\Chilkat\ChilkatDotNet47.dll
RegisterNetComComponent "C:\Chilkat\ChilkatDotNet47.dll" 2|4

CsExec("") ;;How to get the running result


#ret
//C# code
using System;
using Chilkat;

public class Test
{
public string Main()
{

Chilkat.JsonObject json = new Chilkat.JsonObject();

bool success;

//  The only reason for failure in the following lines of code would be an out-of-memory condition..

//  An index value of -1 is used to append at the end.
int index = -1;

success = json.AddStringAt(-1,"Title","Pan's Labyrinth");
success = json.AddStringAt(-1,"Director","Guillermo del Toro");
success = json.AddStringAt(-1,"Original_Title","El laberinto del fauno");
success = json.AddIntAt(-1,"Year_Released",2006);

json.EmitCompact = false;
//Console.WriteLine(json.Emit());
return json.Emit()
}
}


Messages In This Thread
Powershell code failed to run - by win - 06-15-2019, 12:03 AM
RE: Powershell code failed to run - by win - 06-17-2019, 02:26 PM
RE: Powershell code failed to run - by Gintaras - 06-17-2019, 03:31 PM
RE: Powershell code failed to run - by win - 06-17-2019, 10:51 PM
RE: Powershell code failed to run - by Gintaras - 06-18-2019, 04:45 AM
RE: Powershell code failed to run - by win - 06-18-2019, 07:05 AM
RE: Powershell code failed to run - by Gintaras - 06-18-2019, 07:11 AM
RE: Powershell code failed to run - by win - 06-18-2019, 08:17 AM
RE: Powershell code failed to run - by Kevin - 06-20-2019, 04:44 AM
RE: Powershell code failed to run - by win - 06-20-2019, 05:30 AM
RE: Powershell code failed to run - by Kevin - 06-20-2019, 11:54 AM
RE: Powershell code failed to run - by win - 06-20-2019, 12:50 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)