2011-09-05 87 views
0

我正在使用高級安裝程序8.3並試圖暗示我的應用程序的試用許可,目標操作系統是Windows 7 x32 & x64。C#內存訪問衝突Windows 7

以下代碼取自高級安裝程序提供的示例。

[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)] 
private 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()); 
    } 
} 

高級安裝程序中設置的類型簽名是32位unicode DEP Aware。

問題是每當我選擇註冊我得到一個訪問衝突。看來我無法使用我的應用程序中的開關來關閉DEP,因爲它是我的應用程序所需的。

有沒有人有任何想法如何繞過這一點,因爲我已經檢查了高級安裝論壇,並沒有太多類似的問題。

非常感謝

OK快速更新。

我試過所有的sig類型的組合,這是我發現的。

將類型設置爲32位Ansi(支持Win9x或更高版本)並將CharSet設置爲Ansi/Unicode或Auto result = CRASH。

將類型設置爲32位Unicode(DEP Aware),並將CharSet設置爲Unicode或Auto結果=訪問衝突。

將類型設置爲32位Unicode(DEP Aware)並將CharSet設置爲Ansi result = success。

所以,雖然它工作,但高級安裝程序顯然存在一個錯誤。

+2

你爲什麼要打開DEP? –

+0

@David Heffernan:顯然這是x86(ANSI)二進制文件的高級安裝程序的[要求](http://www.advancedinstaller.com/user-guide/tutorial-licensing.html)「...支持Win9x或更高版本OS並且不能用於支持DEP的應用程序「。 –

+0

我不完全理解,但它似乎支持兩種與DEP兼容的庫類型。 –

回答

2

根據您最後的評論(使用CharSet.None解決問題),我會如下:

指定CharSet.None,這是CharSet.Ansi過時的代名詞,真正使P/Invoke來marshal the strings as ANSI,不是Unicode (這將與Windows NT平臺上的CharSet.Auto一起使用)。

看着"6. Integrate the Licensing Library within application"它看起來像VB.NET(也許還有C#)應該使用Trial.dll(API)的「ANSI」版本。

或者也許有不同版本的Trial.dll支持unicode,但不是在你的PATH中(因此不能被P/Invoke找到)。

我不知道這個產品,所以很難說。

+0

有一個Unicode Trial.dll可用。所以也許許可功能配置不正確。 –

+0

感謝基督徒,我已經更新了我的問題。 – Kevin