用_outp函数只能发送int型.
谢谢.

解决方案 »

  1.   

    将CString转为char*,每个char就是一个byte,实际就是unsigned short int
      

  2.   

    _outp函数能发送byte型
    将CString转成byte型一个一个发
      

  3.   

    void send(CString str)
    {
    int *p;
    int nBytes, nInts, nBytesRemain;;
    nBytes = str.GetLength();
    p = (int*)str.GetBuffer(-1);
    nInts = nBytes / sizeof(int);
    nBytesRemain = nBytes % sizeof(int);
    for(int i = 0; i < nInts; i++)
        _outb(p[i]);//send remainder
    if(nBytesRemain != 0){ 
        int last = *p;
        unsigned char mask[sizeof(int)] = {0}; 
        for(int i = 0; i < nBytesRemain; i++)
            mask[i] = 0xff; 
        p = (int*)mask;
        last &= *p;
        _outp(last);
    }
    }