小编Ste*_*n M的帖子

调用C++ DLL时出现System.AccessViolationException

我试图让Java Access Bridge(2.02)与C#(.NET 3.5)一起使用.我确实有一些功能,但是当我调用一个引用结构的函数(getAccessibleContextInfo)时,我收到此错误消息: System.AccessViolationException:尝试读取或写入受保护的内存.这通常表明其他内存已损坏.

这是我的代码:

[DllImport("Windowsaccessbridge.dll", CallingConvention = CallingConvention.Cdecl)]
internal extern static void Windows_run();

[DllImport("Windowsaccessbridge.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static void releaseJavaObject(long vmID, IntPtr javaObject);

[DllImport("Windowsaccessbridge.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static bool isJavaWindow(IntPtr window);

[DllImport("Windowsaccessbridge.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static bool getAccessibleContextInfo(long vmID, IntPtr ac, out AccessibleContextInfo textInfo);

[DllImport("Windowsaccessbridge.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern bool getAccessibleContextFromHWND(IntPtr hwnd, out long vmID, out IntPtr ac);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct AccessibleContextInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] …
Run Code Online (Sandbox Code Playgroud)

c# exception dllimport

6
推荐指数
1
解决办法
7146
查看次数

标签 统计

c# ×1

dllimport ×1

exception ×1