unsigned char buf[1024];memset( buf, 0, sizeof(buf) );
buf[0]=0xef;
buf[1]=0x14;
memcpy( buf+2, "something here", 14 );

解决方案 »

  1.   

    unsigned char buf[1024];
    dim buf as stringmemset( buf, 0, sizeof(buf) );
    string=""buf[0]=0xef;
    string = &Hefbuf[1]=0x14;
    string =string + (&H14)memcpy( buf+2, "something here", 14 );
    string =string + "something here"
      

  2.   

    To :ydzqw(===七条狗===)
     thank you.
     还有一个问题,如果用socket将这一串string发给unix的机器,unix同样是用socket接收,收下来的首位&Hef会不会不一致?因为现在实际情况首位收到的不是&Hef,第二个字节是正常的是&H14。
      

  3.   

    有两种方式可以实现
    方式一
    unsigned char buf[1024];
    ----Dim strBuf as stringmemset( buf, 0, sizeof(buf) );
    buf[0]=0xef;
    ----strBuf=chrw(&Hef)            ''注意 是chrw函数,不是chr函数
    buf[1]=0x14;
    ----strBuf=strBuf & chrw(&H14)
    memcpy( buf+2, "something here", 14 );
    ----strBuf=strBuf & "Something here"
      

  4.   

    方法二,采用二进制方式,虽然烦琐,但可靠
    unsigned char buf[1024];
    ----Dim abtBuf(1024) as byte
    ----Dim i as Integer
    ----Dim strTmp as stringmemset( buf, 0, sizeof(buf) );
    buf[0]=0xef;
    ----abtBuf(0)=&HEFbuf[1]=0x14;
    ----abtBuf(1)=&H14memcpy( buf+2, "something here", 14 );
    ----strTmp="Something Here"
    ----For i=2 to len(strTmp)
            abtBuf(i)=cByte(Asc(Mid(strTmp,i-1,1)))
        Next