开发者

C# Memory Access Violation Windows 7

开发者 https://www.devze.com 2023-04-02 06:23 出处:网络
I\'m using advanced installer 8.3 and trying to impliment trial licensing for my application, the target OS is Windows 7 x32 & x64.

I'm using advanced installer 8.3 and trying to impliment trial licensing for my application, the target OS is Windows 7 x32 & x64.

The following code is taken from an example supplied by advanced installer.

 [DllImport("Trial.dll", EntryPoint = "ReadSettingsStr", CharSet = CharSet.Auto)]
private static extern uint InitTrial(String aKeyCode, IntPtr aHWnd);

[DllImport("Trial.dll", EntryPoint = "ReadSettingsRetStr", CharSet = CharSet.Auto)]
priv开发者_JAVA百科ate static extern uint InitTrialReturn(String aKeyCode, IntPtr aHWnd);

[DllImport("Trial.dll", EntryPoint = "DisplayRegistrationStr", CharSet = CharSet.Auto)]
private static extern uint DisplayRegistration(String aKeyCode);

[DllImport("Trial.dll", EntryPoint = "GetPropertyValue", CharSet = CharSet.Auto)]
private static extern uint GetPropertyValue(String aPropName, StringBuilder aResult, ref UInt32 aResultLen);

 private void registerToolStripMenuItem_Click(object sender, EventArgs e)
{
  try
  {
    Process process = Process.GetCurrentProcess();
    DisplayRegistration(kLibraryKey, process.MainWindowHandle);
  }

  catch(Exception ex1) 
  {
    MessageBox.Show(ex1.ToString());
  }
}

The type signature set in advanced installer is 32bit unicode DEP Aware.

The problem is everytime i select register i get an Access Violation. It appears i cannot use the switch on my app to turn off DEP as it is required for my application.

Does anyone have any ideas how to get round this, as i have checked on the advanced installer forum and theres not much other than similar issues.

Many Thanks

OK quick update.

I tried all the combinations of the sig type this is what i found.

Setting the type to 32bit Ansi (Supports Win9x or higher) and set the CharSet to Ansi/Unicode or Auto result = CRASH.

Setting the type to 32bit Unicode (DEP Aware) and set the CharSet to Unicode or Auto result = Access Violation.

Setting the type to 32bit Unicode (DEP Aware) and set the CharSet to Ansi result = success.

So although it is working there's obviously a bug in Advanced Installer.


Based on your last comment (using CharSet.None fixes the problem), I would guess the following:

Specifying CharSet.None, which is the deprecated synonym for CharSet.Ansi, really causes P/Invoke to marshal the strings as ANSI, not Unicode (which would be used with CharSet.Auto on Windows NT platforms).

Looking at "6. Integrate the Licensing Library within application" it looks like VB.NET (so maybe also C#) should use the "ANSI" version of the Trial.dll (APIs).

Or maybe there is a different version of Trial.dll that supports unicode, but is not the one that is in your PATH (and thus is not found by P/Invoke).

I don't know the product, so it's hard to tell.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号