I am writing an installer using NSIS which needs to parse a block of JSON.
To achieve this I was hoping to be able to call a .Net dll which would parse the JSON and then in my NSIS script I could call properties on the class to retrieve back the data I need.
However, it appears that the NSIS CLR.dll has a problem where the state of a class is not maintained between calls.
My test .Net class is as follows:
namespace NSISTestDll
{
public class TestClass
{
private bool _configured;
public void Configure()
{
_configured = true;
}
public string Name
{
get
{
if (_configured)
{
return "John Doe";
}
return "Unconfigured";
开发者_JAVA技巧 }
}
}
}
And the part of my NSIS script that calls this is:
File "NSISTestDll.dll"
CLR::Call /NOUNLOAD "NSISTestDll.dll" "NSISTestDll.TestClass" "Configure" 0
CLR::Call /NOUNLOAD "NSISTestDll.dll" "NSISTestDll.TestClass" get_Name 0
pop $0
MessageBox MB_OK $0
The MessageBox shows "Unconfigured" rather than the expected "John Doe".
Reading the forum on the CLR.dll the creater of the plugin does mention that this is a problem.
Does anyone know of a workaround for this?
One thing I was thinking of doing was writing a wrapper in C++ and using System.dll instead so that I can pass my needed values back directly to the NSIS script variables.
The other alternative is to parse the JSON for every property I need to retrieve, the JSON is small enough that this wouldn't impact performance too badly.
In a call like CLR::Call /NOUNLOAD ...
/NOUNLOAD only applies to the CLR dll (The plugin) The CLR plugin itself would have to invent/support it's own parameter if it needed to keep NSISTestDll loaded
精彩评论