pRcvValue = RunPro(i_TempBuf, i_ComnIndex);
是否改变pRcvValue的地址了?

解决方案 »

  1.   

    应该是memcpy(pRcvValue, RunPro(i_TempBuf, i_ComnIndex), 1024)吧?
      

  2.   

    你是不是返回了一个局部变量的指针,返回给pRcvValue 了?这样肯定有问题
      

  3.   

    Runpro主要是对下位机进行操作的命令,没有什么局部变量的指针。
    typedef char* (_stdcall *TRunPro)(char*, long);       //运行程序
    char*  RunPro(char* v_pTelNum, long v_pComn)//运行程序
    {
    // CString str;
    if (!g_hMyMiscDLL) 
    return FALSE; TRunPro func = (TRunPro)GetProcAddress(g_hMyMiscDLL, "RunPro");
    if(!func)
    {
    FreeLibrary(g_hMyMiscDLL);
    return FALSE;
    } return (char*)func(v_pTelNum, v_pComn);
    }
    调用DLL的过程
      

  4.   

    DLL中是用Delphi写的
    //3、运行程序
    function RunPro(ClientID:PChar;CommPort:integer):PChar;
    begin
      CtrlOption:=TCtrlOption.create(Application);
      Ctrloption.MsCommctrl.CommPort:=CommPort;
      CtrlOption.CMDWord:='B2';
      Ctrloption.ReceiveCMD:='CA';
      CtrlOption.ReceiveL:=4;
      CtrlOption.GrpID:=shortstring(ClientID);
      Ctrloption.send(shortstring(ClientID)+'00');
      result:=PChar(string(Ctrloption.ReceiveStr));
      CtrlOption.MsCommctrl.Destroy;
      pub.Destroy;
    end;
      

  5.   

    return (char*)func(v_pTelNum, v_pComn);已经把pRcvValue的地址改了。
    楼主的debug时,记录一下new时的地址,然后再比较pRcvValue = RunPro(i_TempBuf, i_ComnIndex);之后的地址
      

  6.   

    debug后查看时,new时显示是0x00b96f08"",
    函数调用后,返回的是0x00de24a4"15",当返回值pRcvValue中,引号中包含数字时,就没问题,
    一旦引号中什么也没有,i_OneValue = (int)pRcvValue[0];就出错。
      

  7.   

    RunPro 增加一个参数,把你的pRcvValue 传进去,然后把内容拷贝到你pRcvValue  所指的空间里
    我不懂delphi的代码但是怀疑你是指向了局部变量的指针
      

  8.   

    函数中返回了指针,事先就不需要分配了。
    由于是Delphi分配的,也许用delete[]删除会有问题,改成free()试试。
      

  9.   

    char *pRcvValue = new char[1024];
        memset(pRcvValue, 0, 1024);
    pRcvValue = RunPro(i_TempBuf, i_ComnIndex);
    i_OneValue = (int)pRcvValue[0];
              delete []pRcvValue ;
    莫名其妙,既然RunPro返回一个char指针,何必自己去new呢?char *pRcvValue = RunPro(i_TempBuf, i_ComnIndex);这样不就行了
      

  10.   

    Avoid 你的方法早就采用过了,不行我才换成这样的。
      

  11.   

    你改成这样试试,估计是你的new和delete出的问题
    char *pRcvValue;
    pRcvValue = RunPro(i_TempBuf, i_ComnIndex);
    i_OneValue = (int)pRcvValue[0];
      

  12.   

    不是上面的问题,程序出错时DLL的返回值,和正长时一样。
    所以很郁闷
      

  13.   

    char   *pRcvValue   =   new   char[1024]; 
    char* pBackup = pRcvValue;
    .....
    delete [] pBackup; 这样行不行?
      

  14.   

    pRcvValue   =   RunPro(i_TempBuf,   i_ComnIndex); 这个这要赋值后, pRcvValue 的值到底有没有改?
    如果改了的话,楼主前七次没报错也是碰巧的.
    后面delete的不是前面new的那个值,而是从函数返回的值?