0

我使用以下非托管代码在 IAccessible 树中搜索 IAccessible,但托管端的返回 IAccessible ansIacc 始终为空。

非托管代码(被调用者):

extern "C" __declspec(dllexport) HRESULT search(IAccessible * parent, BSTR bstrName, int role, int index_,
     _Out_ IAccessible* ansIacc, _Out_ int* left, _Out_ int* top, _Out_ int*width, _Out_ int* height)
{
       // the implementation of this function.
       // I have checked that the return value of left/top/width/height are right, 
       // but the ansIacc is null in the c# side
}

托管代码(调用者):

        [DllImport(@"C:\Users\jyppz\source\repos\server\x64\Debug\SearchIAcc.dll",
            CallingConvention = CallingConvention.StdCall)]
        static extern int search(IAccessible parent, [MarshalAs(UnmanagedType.BStr)] string bstrName, int role, int index, out object ansIacc, out int left, out int top, out int width, out int height);

        object ans = new object(); // I also have tried IAccessible ans = null 
                           // and Marshal's static method, but all failed.
        search((IAccessible)parent, accName_, accrole_, index_,
                        out ans, out top, out left, out width, out height);

        // the return ans is null !!!!!!!!!!!

任何人都可以提出一些建议来改进上述代码以返回正确的答案(搜索结果)?谢谢。

4

0 回答 0