- -其实我好奇为啥用指针……
MyDC = GetDC(this.Handle);能不能改成MyDC = GetDC(IntPrt.Zero);?
demo里没有m_hWnd是哪个窗口的句柄?
另外xtk_get_line(xtk_p,PixelsData);//取数据 和你做的一样么?

解决方案 »

  1.   

    改成改成MyDC = GetDC(IntPrt.Zero);也不行,我早就试了。demo里的确没有指明m_hWnd是哪个窗口的句柄,先声明HDC MyDC然后就 MyDC=::GetDC(m_hWnd); 我查找了m_hWnd,在程序中仅仅出现了上面的一行代码,其他的都是afxwin.h中的。就算xtk_get_line(xtk_p,PixelsData);和我做的取数据不一样
    ,我把数组全赋值为0,它也应该在界面上显示黑的呀。迷茫中,没用过c++,不知道其中的奥妙,请高手不吝赐教!!!拜谢。
      

  2.   


    - -没实例啊……
    建议SetLastError = true看有没有错误代码
    单步执行测试吧
    一步步看哪里错了另外“把数组全赋值为0,它也应该在界面上显示黑的呀”能成立?
    你应该是不知道他内部是怎么写的吧?
    如果赋值为0是白色或者不处理呢?你可以开两个vs,开他的demo和自己的程序, 传一样的数据进去 都单步执行,看到了哪一步变得不一样了
      

  3.   

     ASD_Start(HDC DC, signed long X, signed long Y, signed long W, signed long H); long 对应的是int 32位的把[DllImport("ACCESScrollingDisplay.dll")] 
    private static extern uint ASD_Start(IntPtr DC, int X, int Y, int W, int H); 
      

  4.   

    我都改了,不行呀。IntPtr 怎样转换成HDC,这可是个很棘手的问题呀。dll共有三个方法:demo程序中这样写的, 
    #ifdef __cplusplus 
    extern "C" { 
    #endif __declspec(dllimport) unsigned long ASD_Start(HDC DC, signed long X, signed long Y, signed long W, signed long H); 
    __declspec(dllimport) unsigned long ASD_Stop(void); 
    __declspec(dllimport) unsigned long ASD_ScanLine(unsigned long *pLineData); 
    #ifdef __cplusplus 

    #endif 
      

  5.   

    long * 是 out long么
      

  6.   

    如果是非托管的,就用DllImport,举例 
      using System; 
      using System.Runtime.InteropServices; 
      class MainApp 
          [DllImport("Kernel32")]                    //读取动态库文件 
            public static extern int GetProcAddress(int handle, String funcname);   给你讲一下我的经验: 
      首先 你在C#中调用的 是C++ 写的一个动态库。比如Kernel32.dll 中的 函数; 
      这个函数用C++写 有如下要求: 
    1、 必须为全局函数 
    2、 函数参数 必须为基本类型,也就是C++ 和C#都有的类型,否则你在public static extern int GetProcAddress(int handle, String funcname); 
        这里没有办法声明。 其余的 没什么了; 还有你可以参考这里:http://blog.csdn.net/jingshuaizh/archive/2009/02/04/3862019.aspx先前用VC写的程序生成的DLL,C#里能够调用么? 
    可以的话,在VC里传入参数为CString,而C#里是string,怎么传参数呢? 再者就是问,用VC写的DLL如果是一个导出类,而不是函数接口,C#里可以直接调用么? 
    第一个问题我遇到过, 可用如下方法解决:   VC++ 中为: int Set(char** str,int n);          //将 String 改成 char** , C# 中没有与String对应的类型 
      C#  中为: int Set(ref string str,int n); 
      
      VC++ 中的 BOOL 类型对应 C# 中的 System.Int32 类型, 建议改动一下参数类型吧.第二个问题,生成的DLL里的函数在一个类里面,这样的话在C#里需要实例化那个类么?怎么做 
    比如说,类solution里有函数int getch(int a); 
    我怎么调用这个getch函数?? 建议在C++中另外写个函数封装一下, 如: 
      int Dllgetch(int a) 

        solution st = //实例化 类solution 
        return st.getch(a); 

    这个 Dllgetch(int a) 就可以提取出来供 C# 调用.
    你的方法可以,我也解决了 
    将CString 改成了LPCTSTR 
    BOOL在C#中对应的是Boolean
      

  7.   

    访问我的博客 程序员日记 http://www.ideaext.com
      

  8.   

    能不能发一下DLL呀
    [email protected]
      

  9.   

    我想请问大侠:IntPtr和HDC如何转换啊?我觉得这个是问题的关键所在。
      

  10.   


    HDC是设备环境句柄,在绘图中用作环境句柄或者内存环境句柄m_hWnd应该是接收消息所用的句柄msdn中
    HDC GetDC(
      HWND hWnd   // handle to window
    );
    Parameters
    hWnd 
    [in] Handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire screen. 
    Windows 98/Me, Windows 2000/XP: To get the DC for a specific display monitor, use the EnumDisplayMonitors and CreateDC functions.参考http://baike.baidu.com/view/1080533.htm
    翻译为
    hWnd:设备上下文环境被检索的窗口的句柄,如果该值为NULL,GetDC则检索整个屏幕的设备上下文环境。
      Windows 98,WindowsNT 5.0或以后版本:如果该参数为Null,GetDC检索首要显示器的设备上下文环境,要得到其他显示器的设备上下文环境,可使用EnumDisplayMonitors和CreateDc函数。另外
    Return Values
    If the function succeeds, the return value is a handle to the DC for the specified window's client area. 
    If the function fails, the return value is NULL. 
    Windows NT/2000/XP: To get extended error information, call GetLastError.
    建议
    GetLastError()查看有没有出错。