SMEIDLL.dll中的函数原型为:
int WINAPI SubmitAExEx(unsigned char OrgTON, unsigned char OrgNPI, LPCSTR OrgAddr,
   unsigned char DestTON, unsigned char DestNPI, LPCSTR DestAddr, 
   unsigned char PRI, unsigned char RD, unsigned char RP, 
   unsigned char SRR, unsigned char MR, unsigned char DCS, 
   unsigned char PID, LPCSTR Schedule, LPCSTR Expire, 
   unsigned long Default_ID, unsigned char UDHI, unsigned long UDLen,
   LPCSTR UserData, LPCSTR ServiceSubType, 
   unsigned char* byMsgID, unsigned char byPKTotal, 
   unsigned char byPKNumber, unsigned char byMsglevel, 
        unsigned char byFeeUserType,  LPCSTR sSPID, LPCSTR sFeeType, 
        LPCSTR sFeeAddr, LPCSTR sFeeCode,unsigned char byUserNum, 
               LPCSTR sDestAddrs,  unsigned long* SM_ID, unsigned char* FCS)
注:SubmitAExEx适用于CMPP协议(移动)。
我的申明:
function SubmitAExEx(OrgTON, OrgNPI: Byte; OrgAddr:  LPCSTR; DestTON, DestNPI: Byte; DestAddr: LPCSTR;
               PRI, RD, RP, SRR, MR, DCS, PID: Byte; Schedule, Expire: LPCSTR;
               Default_ID: longword; UDHI: Byte; UDLen: longword; UserData, ServiceSubType: LPCSTR;
               byMsgID: PByte; byPKTotal, byPKNumber, byMsglevel, byFeeUserType: Byte;
                sSPID, sFeeType, sFeeAddr, sFeeCode: LPCSTR; byUserNum: Byte;
                sDestAddrs: LPCSTR; SM_ID: Plongword; FCS: PByte): integer; external 'smeidll.dll';
调用:
procedure TForm1.Button5Click(Sender: TObject);
var
  ret: integer;
  byMsgID : Byte;
  SM_ID : Longword;
  FCS : Byte;
  d: TSubmitAExEx;
  Schedule,Expire: string;
begin
  Schedule:=FormatDateTime('yyyy/MM/dd hh:mm:ss',Now);
  Expire:=FormatDateTime('yyyy/MM/dd hh:mm:ss',Now+0.5);
  ret:=d(2,1,'040222',1,1,'8613760818278',0,0,0,0,0,8,0,PAnsiChar(Schedule),
              PAnsiChar(Expire),0,0,4,'test','icp',@byMsgID,       //MAX_MSG_ID,CMPP的字段,消息ID
              1,1,0,1,'spid','01','','11',1,'040222',@SM_ID,@FCS);
  showmessage(inttostr(ret));
end;每次ret返回都是4,而且还会出现这样的错误提示:
   Access violation at address 3134319 in modual "smeidll.dll".read of address 3134319.
 请问是什么原因,请用过的高手急救呀!  

解决方案 »

  1.   

    看了一眼,认为你的声明后面应该加stdcall,如:
    ...FCS: PByte):integer; stdcall; external 'smeidll.dll';继续看看:)
      

  2.   

    看了第三眼,函数调用部分相当完美,不会有问题。不用看了,加上stdcall就应该ok了:)
      

  3.   

    to clasj:
      我也采用过stdcall的方法
    申明为:
      type TSubmitAExEx=Function(OrgTON, OrgNPI: Byte; OrgAddr:  LPCSTR; DestTON, DestNPI: Byte; DestAddr: LPCSTR;
                 PRI, RD, RP, SRR, MR, DCS, PID: Byte; Schedule, Expire: LPCSTR;
                Default_ID: longword; UDHI: Byte; UDLen: longword; UserData, ServiceSubType: LPCSTR;
                 byMsgID: PByte; byPKTotal, byPKNumber, byMsglevel, byFeeUserType: Byte;
                    sSPID, sFeeType, sFeeAddr, sFeeCode: LPCSTR; byUserNum: Byte;
                    sDestAddrs: LPCSTR; SM_ID: Plongword; FCS: PByte): integer; stdcall;调用:
    procedure TForm1.Button5Click(Sender: TObject);
    var
      ret: integer;
      byMsgID : Byte;
      SM_ID : Longword;
      FCS : Byte;
      h:thandle;
      d: TSubmitAExEx;
      Schedule,Expire: string;
    begin
      h:=safeloadlibrary('SMEIDll.dll');
      if h>0 then
        @d:=getprocaddress(h,'SubmitAExEx')
      else
        begin
          showmessage('找不到SMEIDLL.dll文件!');
          exit;
        end;
      Schedule:=FormatDateTime('yyyy/MM/dd hh:mm:ss',Now);
      Expire:=FormatDateTime('yyyy/MM/dd hh:mm:ss',Now+0.5);
      ret:=d(2,1,'040222',1,1,'8613760818278',0,0,0,0,0,8,0,PAnsiChar(Schedule),
                  PAnsiChar(Expire),0,0,4,'test','icp',@byMsgID,       //MAX_MSG_ID,CMPP的字段,消息ID
                  1,1,0,1,'spid','01','','11',1,'040222',@SM_ID,@FCS);
      showmessage(inttostr(ret));
    end;结果运行时,返回结果还是一样,错误也会出现!》》更正,问题贴中ret:=d(....)
        应为:        ret:=SubmitAExEx(......)
      

  4.   

    刚才我又测了下,用stdcall还是不成!
    我再试下cdecl
      

  5.   

    使用cdecl后,调用此函数时程序自动关闭,
      

  6.   

    调用此函数时程序自动关闭
    -------------------------
    程序异常退出了,用stdcall是正确的,看来是其它原因。
      

  7.   

    那台机上现在还运行着另外一套华为提供的接口程序,不过功能太简单了,所以想升级改造一下。他也是调用SMEIDLL.dll文件,要连接移动的接口也用相同的用户名和密码,连相同的端口号。
    不知道与它会不会冲突呀,不过那套软件我们不能关闭,不然现有的平台就全瘫痪了!
      

  8.   

    我的意见是再好好看看这个函数的说明文档,重点是byMsgID、SM_ID、FCS这几个参数,如果函数返回的数据多于你分配的空间(比如说返回一个unsigned char[10],而你确只分配了一个byte)就会有问题。
      

  9.   

    存在冲突的可能性,不过我想应该不会导致
    Access violation at address 3134319 in modual "smeidll.dll".read of address 3134319.
      

  10.   

    我想是那个打开的接口程序的问题。你这个程序调用发送函数之前要先登陆,你登陆成功?否则发送怎么会成功?如果那个程序不能关,你可以找一个模拟网关,cmpp2.0和3.0的网上都有,可以看到你函数调用的是否成功,网关接到的数据是什么内容。
      

  11.   

    这个是我声名的,测试发送成功。
    function  SubmitAExEx(OrgTON : ShortInt; OrgNPI :ShortInt; OrgAddr :PChar; DestTON :ShortInt; DestNPI :ShortInt; DestAddr :PChar; PRI :ShortInt; RD :ShortInt; RP :ShortInt; SRR :ShortInt; MR :ShortInt; DCS :ShortInt; PID :ShortInt; Schedule :PChar; Expire :PChar; Default_ID :LongWord; UDHI :ShortInt; UDLen :LongWord; UserData :PChar;ServiceSubType:Pchar;  byMsgID:pchar; byPKTotal:ShortInt; byPKNumber:ShortInt; byMsglevel:ShortInt; byFeeUserType:ShortInt; sSPID:Pchar; sFeeType:Pchar; sFeeAddr:Pchar; sFeeCode:Pchar; byUserNum:ShortInt; sDestAddrs:Pchar; var SM_ID:longword; var FCS:ShortInt):integer;stdCall external 'SMEIDLL.DLL';
      

  12.   

    看来楼上是有经验的同志了,弱弱的问一下这个DLL是用来干什么的啊,需要硬件的支持吗?
      

  13.   

    to cjf1009(农民程序员):
       我初始化接口、登录都是成功的,只是在发送这儿出了问题。大富翁有人提到:unsigned char* byMsgID ——》byMsgID: Pchar
    我原来声明的是:unsigned char* byMsgID ——》byMsgID: Byte   然后调用@byMsgID
    这个我要试一下!至于模拟网关,我找了一个《中国移动通信CMPP2.0服务端模拟器 v1.0 》,不知道可不可以用。
    今晚我测试一下,明天我会来说明测试情况的。
      

  14.   

    将byMsgID的数组声明长一点。有时,C语言虽然是unsigned char * param,其实它表示一个指针,需要一定内存,而你只是一个byte,肯定会错。procedure TForm1.Button5Click(Sender: TObject);
    var
      ret: integer;
      byMsgID : array [0..31] of Byte;
      SM_ID : Longword;
      FCS : Byte;
      h:thandle;
      d: TSubmitAExEx;
    begin
      h:= safeloadlibrary('SMEIDll.dll');
      if h>0 then
        @d:=getprocaddress(h,'SubmitAExEx')
      else
        begin
          showmessage('找不到SMEIDLL.dll文件!');
          exit;
        end;  ret:= d(2, 1,'040222',1,1,'8613760818278',0,0,0,0,0,8,0,nil,
                  nil,0,0,4,'test','icp',@byMsgID, 1,1,0,1,'spid','01','','11',1,'040222',@SM_ID,@FCS);
      showmessage(inttostr(ret));
    end;
      

  15.   

    抱歉,昨天我有事没来得及上网。
    说一下我测的情况,现在没有了 Access  violation  at  address  3134319  in  modual    "smeidll.dll  ".read  of  address  3134319这样的错误,不过返回还是4。我想应该是我对某些参数的赋值不对,所以这些在程序上应该是都没有问题了。对于参数我会再仔细的核对一下。
    等我问题完全解决后,我会再开贴赠送你们100分的,多谢支持了!
      

  16.   

    是lptcstr的都先分配足够大的空间才行,dll中可能要用读写这些变量,若空间不足就会出现access的错误