Ngen on setup, VB to C# translation
-
Yes, it looks like a P/Invoke signature. Did you try converting it to c# yourself?
#region signature my articles #endregion
Ok, I actually got it to compile using:
[DllImport("mscoree.dll")] static extern int GetCORSystemDirectory( [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] StringBuilder buffer, Int32 buffer_length, out Int32 length );
And then calling the function like this:System.Text.StringBuilder Path = new System.Text.StringBuilder(1024); int Size; GetCORSystemDirectory(Path, Path.Capacity, out Size);
Still doesn't seem to be working though, can you tell me if the signature is right?Standards are great! Everybody should have one!
-
In the original there is System.Text.StringBuilder, why did you change it with just String? If you've never worked with P/Invoke, I suggest you have a look at this: P/Invoke[^]
#region signature my articles #endregion
-
In the original there is System.Text.StringBuilder, why did you change it with just String? If you've never worked with P/Invoke, I suggest you have a look at this: P/Invoke[^]
#region signature my articles #endregion
-
Ok, I actually got it to compile using:
[DllImport("mscoree.dll")] static extern int GetCORSystemDirectory( [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] StringBuilder buffer, Int32 buffer_length, out Int32 length );
And then calling the function like this:System.Text.StringBuilder Path = new System.Text.StringBuilder(1024); int Size; GetCORSystemDirectory(Path, Path.Capacity, out Size);
Still doesn't seem to be working though, can you tell me if the signature is right?Standards are great! Everybody should have one!
You should also have notices that original code uses System.Runtime.InteropServices.UnmanagedType.LPWStr and not System.Runtime.InteropServices.UnmanagedType.LPStr Also, third parameter of GetCORSystemDirectory Function is DWORD* so you should pass a reference to int.
#region signature my articles #endregion
-
You should also have notices that original code uses System.Runtime.InteropServices.UnmanagedType.LPWStr and not System.Runtime.InteropServices.UnmanagedType.LPStr Also, third parameter of GetCORSystemDirectory Function is DWORD* so you should pass a reference to int.
#region signature my articles #endregion
Ok, thanks for the advice I've updated the code to:
[DllImport("mscoree.dll")]
static extern int GetCORSystemDirectory(
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] StringBuilder buffer,
Int32 buffer_length,
ref Int32 length
);And the call is now like this:
// Gets the path to the Framework directory.
System.Text.StringBuilder Path = new System.Text.StringBuilder(1024);
int Size = 0;
GetCORSystemDirectory(Path, Path.Capacity, ref Size);Still it's not working :(. If I could only set a breakpoint to find out why, but this doesn't seem to be supported for installer projects...
Standards are great! Everybody should have one!
-
Ok, thanks for the advice I've updated the code to:
[DllImport("mscoree.dll")]
static extern int GetCORSystemDirectory(
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] StringBuilder buffer,
Int32 buffer_length,
ref Int32 length
);And the call is now like this:
// Gets the path to the Framework directory.
System.Text.StringBuilder Path = new System.Text.StringBuilder(1024);
int Size = 0;
GetCORSystemDirectory(Path, Path.Capacity, ref Size);Still it's not working :(. If I could only set a breakpoint to find out why, but this doesn't seem to be supported for installer projects...
Standards are great! Everybody should have one!
Are you getting an error/exception or is it returning wrong data? Did you turn the stringbuilder into string?
#region signature my articles #endregion
-
Are you getting an error/exception or is it returning wrong data? Did you turn the stringbuilder into string?
#region signature my articles #endregion
I'm on Vista and getting code 2869, no further explanation. I've googled it for a bit and now suspect it's a security problem. This would mean the p/invoke call is actually good now. This is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Runtime.InteropServices;
using System.Text;
using System.Diagnostics;namespace InstallationHelper
{
[RunInstaller(true)]
public partial class InstallationHelper : Installer
{
[DllImport("mscoree.dll")]
static extern int GetCORSystemDirectory(
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] StringBuilder buffer,
Int32 buffer_length,
ref Int32 length
);public InstallationHelper() { InitializeComponent(); } \[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)\] public override void Install(System.Collections.IDictionary savedState) { base.Install(savedState); string Args = this.Context.Parameters\["Args"\]; if (Args == "") { throw new InstallException("No arguments specified"); } // Gets the path to the Framework directory. System.Text.StringBuilder Path = new System.Text.StringBuilder(1024); int Size = 0; GetCORSystemDirectory(Path, Path.Capacity, ref Size); Process P; // Quotes the arguments, in case they have a space in them. ProcessStartInfo Si = new ProcessStartInfo(Path.ToString() + "ngen.exe", "\\"" + Args + "\\""); Si.WindowStyle = ProcessWindowStyle.Maximized; try { P = Process.Start(Si); P.WaitForExit(); } catch (Exception e) { throw new InstallException(e.Message); } } }
}
Standards are great! Everybody should have one!
-
I'm on Vista and getting code 2869, no further explanation. I've googled it for a bit and now suspect it's a security problem. This would mean the p/invoke call is actually good now. This is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Runtime.InteropServices;
using System.Text;
using System.Diagnostics;namespace InstallationHelper
{
[RunInstaller(true)]
public partial class InstallationHelper : Installer
{
[DllImport("mscoree.dll")]
static extern int GetCORSystemDirectory(
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] StringBuilder buffer,
Int32 buffer_length,
ref Int32 length
);public InstallationHelper() { InitializeComponent(); } \[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)\] public override void Install(System.Collections.IDictionary savedState) { base.Install(savedState); string Args = this.Context.Parameters\["Args"\]; if (Args == "") { throw new InstallException("No arguments specified"); } // Gets the path to the Framework directory. System.Text.StringBuilder Path = new System.Text.StringBuilder(1024); int Size = 0; GetCORSystemDirectory(Path, Path.Capacity, ref Size); Process P; // Quotes the arguments, in case they have a space in them. ProcessStartInfo Si = new ProcessStartInfo(Path.ToString() + "ngen.exe", "\\"" + Args + "\\""); Si.WindowStyle = ProcessWindowStyle.Maximized; try { P = Process.Start(Si); P.WaitForExit(); } catch (Exception e) { throw new InstallException(e.Message); } } }
}
Standards are great! Everybody should have one!
Yes, according to google it looks like a problem with permissions and vista. You could try running it on XP or calling unmanaged function from a normal windows application so that you can set breakpoint.
#region signature my articles #endregion
-
Yes, according to google it looks like a problem with permissions and vista. You could try running it on XP or calling unmanaged function from a normal windows application so that you can set breakpoint.
#region signature my articles #endregion
-
Ok, problem solved! Cleaning up seems to be the right thing to do here: Just removing the constructor was enough to get the thing going for some reason :). Thanks a bunch Giorgi, you've been a real help!
Standards are great! Everybody should have one!
Glad to help you :)
#region signature my articles #endregion