char *buf
你定义是char型吗!
肯定不可以吗!
换换类型定义就可以了!

解决方案 »

  1.   

    字副串在内存中也是二进制表示的,只不过>30H, 可以显示而以!
      

  2.   

    我的在WIN2000下没有问题,但在WIN98下就是不行.
    部分代码如下:
    DLL文件中:
    extern "C"_declspec(dllexport) void YPL_SendString(char strSend[DEFAULT_BUFFER],int iIndex)
    { memcpy(g_package[iIndex].WBuf ,strSend,DEFAULT_BUFFER);
               //sreSend在内存中不对但地址和EXE中pbuf一样(pbuf)见下面
    SetEvent(g_package[iIndex].hWEvent); 
    }
    EXE文件中:
    extern "C"_declspec(dllimport) void  YPL_SendString(char strSend[DEFAULT_BUFFER],int iIndex);HRESULT CYPL_FTPServerDlg::OnReaded (WPARAM wParam,LPARAM lParam)
    { char * pbuf; pbuf=(char *)malloc(DEFAULT_BUFFER); CopyFromFile(pbuf);//在这里将二进制拷到pbuf,在内存中可以看到是对的
    YPL_SendString(pbuf,(int)wParam); free(pbuf); return 0;}
    大家帮我看看
      

  3.   

    试一下memmove吧The memcpy function copies count bytes of src to dest. If the source and destination overlap, this function does not ensure that the original source bytes in the overlapping region are copied before being overwritten. Use memmove to handle overlapping regions.The memmove function copies count bytes of characters from src to dest. If some regions of the source area and the destination overlap, memmove ensures that the original source bytes in the overlapping region are copied before being overwritten
      

  4.   

    可能我没说清楚,
    我的意思是:
    首先程序在win2000下运行正常,在win98下出现问题.
    在EXE中YPL_SendString(pbuf,i);此时pbuf在内存中看到的是正确的内容.
    这样在DLL中YPL_SendString传进来的pbuf在内存中看到的内容就不正确了,请问是谁该了内存??
    而且有时我在dll的YPL_SendString函数中设置断点,
    如果CYPL_FTPServerDlg::OnReaded 函数如下的话
    HRESULT CYPL_FTPServerDlg::OnReaded (WPARAM wParam,LPARAM lParam)
    {char * pbuf;pbuf=(char *)malloc(DEFAULT_BUFFER);CopyFromFile(pbuf);//在这里将二进制拷到pbuf,在内存中可以看到是对的
    YPL_SendString(pbuf,(int)wParam);free(pbuf);return 0;}
    但程序可以运行到断点处,
    但如果改成
    HRESULT CYPL_FTPServerDlg::OnReaded (WPARAM wParam,LPARAM lParam)
    {char * pbuf;char * ptemp;
    pbuf=(char *)malloc(DEFAULT_BUFFER);
    ptemp(char *)malloc(DEFAULT_BUFFER);
    CopyFromFile(pbuf);//在这里将二进制拷到pbuf,在内存中可以看到是对的
    int len;
    //len 通过其他方式得到,其值<=DEFAULT_BUFFER
    memcpy(ptemp,pbuf,len);
    YPL_SendString(ptemp,(int)wParam);free(pbuf);return 0;}
    就运行不到断点处了,为什么???
      

  5.   

    to Julienjut(秋水) :
      我在SOCKET接收端收到的就是在dll中看到的那一块内存,但它的内容不正确,不是我在exe中调用YPL_SendString(pbuf)传给函数参数的内容,也就是说在exe中调用YPL_SendString时pbuf是一个内容,到dll中就变了,但我是要把exe中pbuf的内容传到dll中呀,所以才有YPL_SendString这个函数.然后dll再把这个内容通过发出去.
      

  6.   

    DLL文件中:
    extern "C"_declspec(dllexport) void YPL_SendString(char* strSend,int iIndex)
    {memcpy(g_package[iIndex].WBuf ,strSend,DEFAULT_BUFFER);
              //sreSend在内存中不对但地址和EXE中pbuf一样(pbuf)见下面
    SetEvent(g_package[iIndex].hWEvent); 
    }
    EXE文件中:
    extern "C"_declspec(dllimport) void  YPL_SendString(char *strSend,int iIndex);HRESULT CYPL_FTPServerDlg::OnReaded (WPARAM wParam,LPARAM lParam)
    {char * pbuf;
    try the following code
    pbuf=new char[DEFAULT_BUFFER];CopyFromFile(pbuf);//在这里将二进制拷到pbuf,在内存中可以看到是对的
    YPL_SendString(pbuf,(int)wParam);delete []pbuf
    ;return 0;}