Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ library issue
    primarykey
    data
    text
    <p>I'm trying to make a call to a C++ library from my C# code. I also have a sample application written in C++ that invokes the same library, and works fine. However, the call from C# throws an error: </p> <blockquote> <p>Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</p> </blockquote> <p>The c# code is:</p> <pre><code>#region DllImports [DllImport("kernel32.dll", EntryPoint = "LoadLibrary")] static extern int LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpLibFileName); [DllImport("kernel32.dll", EntryPoint = "GetProcAddress")] static extern IntPtr GetProcAddress(int hModule, [MarshalAs(UnmanagedType.LPStr)] string lpProcName); [DllImport("kernel32.dll", EntryPoint = "FreeLibrary")] static extern bool FreeLibrary(int hModule); [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] delegate string bondProbeCalc(string licenseFolder, string requestString); #endregion /// &lt;summary&gt; /// Calls Bondprobe to calculate a formula /// &lt;/summary&gt; internal static string DoBondProbeOperation(string requestString) { if (string.IsNullOrEmpty(requestString)) throw new ArgumentNullException(); //Reference library int hModule = LoadLibrary(ConfigurationManager.Instance.BondProbeSettings.AssemblyFilePath); if (hModule != 0) { IntPtr intPtr = GetProcAddress(hModule, "bpStringCalc"); bondProbeCalc funcDelegate = (bondProbeCalc)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(bondProbeCalc)); requestString = requestString.EndsWith("=") ? requestString.Substring(0, requestString.Length - 1) : requestString; string returnValue = funcDelegate(ConfigurationManager.Instance.BondProbeSettings.LicenseFilePath, requestString); FreeLibrary(hModule); return returnValue; } return string.Empty; } </code></pre> <p>This exact same code works on some computers, and it throws the error on others. However, the sample C++ app seems to work everywhere.</p> <p>Any ideas?</p> <p>Thanks, Gonzalo</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload