由于没有使用ShareMem,所以只能用Pchar,
但是对于指针的使用并不太了解,所以导致
一个取子字符串的函数不能保证一定成功,
但是如果这个函数是在一个Project而不是DLL
中,就已经测试一定可以成功。还有就是想请问有没有相关的在DLL中如何使用Pchar
这些指针的资料!!!!!救命阿,自己控制内存的分配和管理,真的很容易出事
阿。由于自己的DLL中还使用了一些自定义的全局record
变量来返回数据。结果由于使用不当,返回的记录内容
经常不准(肯定是指针到处乱指了,呜呜~~~)。而且
使用了这个DLL的PRoject在关闭的时候肯定出错。而在
Windows2000中,在运行到使用DLL的函数时就已经出错了。
看DEBUG的CPU信息显示程序停在了ntdll.ntcreatefile的
mov指令当中。搞到死翘翘。救命阿!!!!我写的这个dll其实只是通过传进来的一个数据库连接参数
record变量连接到一个数据库表中取出其他一些参数。只有
三个很简单的函数,不过由于刚学,什么都不懂,所以没有
办法解决。如果那位观音菩萨能够留个E_mail帮小弟解决了这个简单的问题。
1000分立刻送上!!!!!!!!

解决方案 »

  1.   

    程序文件只有几K,请大虾们留下E_mail吧
      

  2.   

    你给我发邮件吧,我给你一个DLL的代码,这个DLL是一个数据库访问函数库,用于数据库记录的传递,在我做的那个项目里供VC那些程序调用的,测试没有发现问题,具体实现思想是:
    在应用程序中开辟内存,然后将缓冲区地址传递到DLL内部,在DLL内部则向这个地址写入数据,然后返回有效数据长度。应该可以满足你的要求。
    分不是问题
      

  3.   

    这是其中三个函数之一,取子字符串://通过AParamNames(aaa,bbb,...)列表获取以ASeparator(,)作为分隔符的第Anumber个字符串。
    function GetParamName(AParamNames:PChar;ASeparator:PChar;ANumber:Integer): PChar;stdcall;
    var
      i,Count: Integer;
      tempstr : PChar;
    begin
      Count := 0;
      tempstr := AParamNames;
      i := Pos(ASeparator,tempstr);
      while i > 0 do
      begin
        Count := Count+1;
        if Count = Anumber then
        begin
          result := PChar(Copy(tempstr,1,i-1));
          exit;
        end
        else
        begin
          tempstr := PChar(Copy(tempstr,i+1,length(tempstr)-i));
          i := Pos(ASeparator,tempstr);
        end;
      end;
      if Count < (Anumber-1) then
        result := PChar('')
      else
        result := tempstr;
    end;
      

  4.   

    不好意思,忘了写地址[email protected]
      

  5.   

    算了,就在这里说吧
    constructor TBvodDB.Create(dwPDBInfo:Dword);  //dwPDBInfo需要程序提供的数据库访问参数结构地址
    var
      DBInfo:TDBinfo;
    begin
      CoInitialize(nil);  copyMemory(@DBInfo,pointer(dwPDBInfo),sizeof(DBInfo));
      
      FAdoconn:=TADoConnection.Create(nil);
      FAdoconn.LoginPrompt:=false;
      //FAdoconn.CommandTimeout:=10;
      FAdoconn.ConnectionString:='Provider=SQLOLEDB.1;Password=' + DBInfo.DBPWD +
        ';Persist Security Info=True;User ID=' +
        DBInfo.DBUser + ';Initial Catalog=' + DBInfo.DBName + ';Data Source=' +
        DBInfo.DBAddr;
      try
        FAdoconn.Open;
        FConnFlag:=true;
      except
        FConnFlag:=false;
      end;
      FADoquery:=TADoquery.Create(nil);
      FADoquery.Connection:=FAdoconn;
    end;
      

  6.   

    在主程序中给指针分配内存空间,用var修饰参数,也就是传递到DLL中的只是变量的地址,然后在DLL中直接改变变量的值,不用返回
      

  7.   

    //返回有效数据结构长度(数组个数)
    function TBVodDB.BColQuery(dwbuf:Dword):integer;//dwbuf外部提供的缓冲区地址,用于DLL写入数据
    var
      i:integer;
      ColRec:TColRec;
    begin
      if not FConnFlag then
      begin
        result:=-1;
        exit;
      end;
      with FAdoquery do
      begin
        Close;
        SQL.Text:='select * from BvodColumn';
        try
          Open;
          i:=0;
          while not eof do
          begin
            strpcopy(@(ColRec.ColName),FieldByName('ColumnName').asstring);
            strpcopy(@(ColRec.ColID),FieldByName('ColumnID').asstring);
            copyMemory(pointer(dwbuf+i*sizeof(ColRec)),@ColRec,sizeof(colRec));
            Next;
            inc(i);
          end;
          result:=RecordCount;
        except
          result:=-1;
        end;
      end;
    end;
      

  8.   

    调用说明procedure TForm1.Button2Click(Sender: TObject);
    var
      aRec:TBvodConRec;
      aBuf:pchar;
      iResult:integer;
      bResult:boolean;
    begin
      aBuf:=AllocMem(10240);
      iResult:=BConQuery(11,14,dword(aBuf));
      caption:=inttostr(iResult);  copyMemory(@aRec,aBuf,sizeof(aRec));  label1.Caption:=aRec.MovieName;  strpcopy(@(aRec.MovieName),'武士1');  bResult:=BConModi(dword(@aRec));  if bResult then
        caption:='修改成功'
      else
        caption:='修改失败';  Dispose(aBuf);
    end;
      

  9.   

    TO(xdf_hubei(向太傅)):
    我已经给你发了E_mail,请你帮我看看我这样写究竟错在哪里了?
    无限感激!!!
      

  10.   

    使用Pchar类型的问题
    pchar类型变量之间怎么赋值阿?
    也即是说使用了strpos(str1,str2)函数之后,会返回一个指针。Returns a pointer to the first occurrence of STR2 in STR1.然后我想要从返回的这个指针的位置开始再向后面搜索同样的str2。那么我应该怎么做阿?
      

  11.   

    spoky(夜游魂) 我没有收到邮件,看到请重发
      

  12.   

    TO(xdf_hubei(向太傅)):
    我已经重发了,如果收不到的话请看你的留言本
      

  13.   

    刚才发送的邮件被退回This is the Postfix program at host sm206.163.com.I'm sorry to have to inform you that the message returned
    below could not be delivered to one or more destinations.For further assistance, please contact <[email protected]>If you do so, please include this problem report. You can
    delete your own text from the message returned below. The Postfix program亲爱的网易邮箱用户:
        抱歉的通知您,您的邮件无法投递到目的地址.
        下面是系统返回的错误原因(例如:收件人地址不正确,信箱满或此信被对方拒收).
        必要时您可跟对方或对方管理员联系.
    网易邮件事业部<[email protected]>: host mta.21cn.com[202.104.32.232] refused to talk to me:
        501 total command number or failed command number from ip <202.108.44.206>
        reaches maximum limit.
    ------------------------------------------------------------
    From: "向太傅" <[email protected]>
    To:  <[email protected]>
    Subject: Re: Fw: 求:用于数据库记录的传递DLL的源程序!!
    Date: Mon24 Mar 2003 22:3:53 +0800请检查邮箱容量,下面是我的一些话,代码是没法贴在这里了。我初步看了一下你的程序 ,说点我自己的想法。首先,如果你的这个DLL,给DELPHI程序调用,问题不大,如果给VC调用,应该会出问题,得到的数据有错。一点意见:你把返回值作为一个数据结构传递的想法是没错的,但是一定要注意,如果和VC调用,则注意结构的长度,一定要搞成4BYTE的整数倍,否则出错。不要在结构字段里面直接使用STRING,要用定长字符数组 ARRAY[0..N]OF CHAR;。另外,在这种设计思维下,最好的办法是在调用程序外部开辟内存空间,然后将空间地址作为参数传递给DLL,DLL内部将数据写向这个地址,返回数据长度。其他我就不说了,代码我可以给你,尽管我刚辞职,但是这个代码仍然是以前公司的产品中一部分,希望你不要传播,谢谢了!
      

  14.   

    spoky兄弟:
         小弟和你遇到同样的问题,如何解决的,能否Share?
         My E-Mail:[email protected]
      

  15.   

    begin
      Count := 0;
      tempstr := AParamNames;//这里应该有问题;是不是要用STRCOPY什么的;
      

  16.   

    请各位到以下这些帖子接分:
    http://expert.csdn.net/Expert/topic/1589/1589683.xml?temp=.7735865
    http://expert.csdn.net/Expert/topic/1589/1589705.xml?temp=.7271997
    http://expert.csdn.net/Expert/topic/1589/1589734.xml?temp=.3298609
    http://expert.csdn.net/Expert/topic/1589/1589630.xml?temp=.7795069
    http://expert.csdn.net/Expert/topic/1589/1589750.xml?temp=.8279688
    http://expert.csdn.net/Expert/topic/1589/1589785.xml?temp=.6881372
    http://expert.csdn.net/Expert/topic/1589/1589676.xml?temp=.7352564
    http://expert.csdn.net/Expert/topic/1589/1589659.xml?temp=.1869165
    http://expert.csdn.net/Expert/topic/1589/1589641.xml?temp=.3777124
    http://expert.csdn.net/Expert/topic/1589/1589617.xml?temp=.5143091