C#p/调用,从所有者绘制的列表框中读取数据 [英] C# p/invoke, Reading data from an Owner Drawn List Box

查看:108
本文介绍了C#p/调用,从所有者绘制的列表框中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在外部应用程序( America Online )中有一个所有者绘制的列表框,我需要从中获取数据以构建组件来帮助人们提高其可用性. (该实用程序将使某些事物的访问更加简单,等等).

I have an Owner Drawn List Box in an external application (America Online) that I need to get data out of for building a component to assist people with its usability. (the utility will be making access of certain things more simple, etc).

我对C ++的了解非常差.我是C#程序员.

My knowledge of C++ is very poor. I am a C# programmer.

我有问题的列表框中的hWnd,但它似乎是所有者绘制的.使用LB_GETTEXT返回错误的数据,我只是变得很烂(它在调试器中呈现为一堆汉字),通过LB_GETITEMDATA返回的结果几乎相同.

I have the hWnd to the List Box in question, but it appears to be owner drawn. Using LB_GETTEXT returns bad data, I just get junk (it renders in my debugger as a bunch of chinese characters) and going through LB_GETITEMDATA returns much the same.

我相信这是因为所有者绘制的列表框上有图形.进行了大量的挖掘工作,我在过去发现了其他与此问题有关的人.我已经发掘了下面的代码,该代码应该可以解决此问题.但是事实并非如此.该代码发布在下面,以及下面的问题.

I believe this is because the owner drawn list box has graphics on it. Doing a lot of digging, I have discovered others in the past with this problem. I have unearthed the following code that is supposed to remedy this issue. However it does not. The code is posted below, and the issues beneath it.

void GetListItemData( HWND hListWnd, long index, char *outputResult )
{
    int result;
    DWORD processID;
    HANDLE hProcess;
    char *itemData;
    char sDataRead[5];
    DWORD bytes;
    DWORD lListItemHold, lListItemDataHold;
    *outputResult=0;

    if( hListWnd )
    {
        GetWindowThreadProcessId( hListWnd, &processID );

        hProcess=OpenProcess( 0x10|0xf0000|PROCESS_VM_READ, 0, processID );

        if( hProcess )
        {
            lListItemHold=(DWORD)SendMessage( hListWnd, LB_GETITEMDATA, index-1, 0 );
            lListItemHold=lListItemHold+24;

            result=ReadProcessMemory( hProcess, (void *)lListItemHold, &sDataRead, 4, &bytes );
            if( !result )
            {
                RaiseWinErr();
            }

            memcpy( &lListItemDataHold, &sDataRead, 4 );
            lListItemDataHold=lListItemDataHold+6;

            ReadProcessMemory( hProcess, (void *)lListItemDataHold, outputResult, 16, &bytes );

            CloseHandle( hProcess );
        }
    }
}

我的理解是有限的,它是lListItemHold=lListItemHold+24试图解释ListBox中的任何结构",并通过它的前24个字节,然后返回剩余的内容.但是,这似乎不适用于我.

My understanding, limited as it is, is that lListItemHold=lListItemHold+24 tries to account for whatever 'structure' is in the ListBox and pass through the first 24 bytes of it, and return what remains. However this does not seem to be working for me.

有人可以阐明我可以尝试的事情吗?我知道我正在抓住稻草.我正在用C#编写代码,因此可以使用p/invoke来使用此功能,如下所示;

Can anyone shed some light on things I could try? I know I am grasping at straws as it is. I am coding this in C#, so this function is used using p/invoke such as follows;

    [DllImport("GetListItemData.dll", CallingConvention = CallingConvention.Cdecl)]
    internal static extern void RetrieveListItem(
        System.IntPtr hWnd,
        System.Int32 index,
        [MarshalAs(UnmanagedType.LPArray)]byte[] buffer
    );

    [DllImport("GetListItemData.dll", CallingConvention = CallingConvention.Cdecl)]
    internal static extern void RetrieveListItem(
        System.IntPtr hWnd,
        System.Int32 index,
        [MarshalAs(UnmanagedType.LPTStr)]System.Text.StringBuilder buffer
    );

推荐答案

我有两个关于该主题的博客文章

I have two blog posts on the topic

http://taylorza.blogspot. com/2009/08/archive-hacking-my-way-across-process.html http://taylorza.blogspot.com/2010/06/crossing-process-boundary-with-net.html

http://taylorza.blogspot.com/2009/08/archive-hacking-my-way-across-process.html http://taylorza.blogspot.com/2010/06/crossing-process-boundary-with-net.html

这些是用于ListView控件的,但是您可能需要看一下代码.第二篇文章是使用P/Invoke在.NET中实现这一点.

These however are for a ListView control, but you might want to take a look at the code. The second post is using P/Invoke to achieve this in .NET.

1-为什么要在lListItemHold中加上24?

1- Why are you adding 24 to lListItemHold?

2-您确定lListItemhold是指向字符串的指针,它可能是应用程序的某些内部结构.

2- Are you sure lListItemhold is a pointer to a string, it might be some internal structure of the application.

这篇关于C#p/调用,从所有者绘制的列表框中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆