zoukankan      html  css  js  c++  java
  • 我是菜鸟,stdcall的偏差

    用了N年的DELPHI的我遇到这个后发现,自己真是菜鸟
    我把问题提到CSDN后:

    DLL里面有一个函数,我是这样引用的:
    function  LIB_OPEN(ComName:PAnsiChar; EventID:longint;hWnd:Thandle):longint;stdcall; external 'DRIVER.dll';
    这个是函数说明是这样的:
    int __cdecl LIB_OPEN(LPCSTR ComName, int nEvtID,HWND hOwner)

    然后我在程序里面这样调用的:
    var temp:array[1..5] of char;
        res:longint;
    begin
      TEMPADD :=0;
      temp[1]:='C';
      temp[2]:='O';
      temp[3]:='M';
      temp[4]:='2';
      temp[5]:=char(0);
      res := cct_lib_open(@temp,cct32_msg,frmmain.Handle);
    end;
    结果报出内存读取违例:access violation at address 007F063E.Read of address 007F07063E'
    更奇怪的是:
    我在后面加了输出就不报错了:修改调用如下:
      TEMPADD :=0;
      temp[1]:='C';
      temp[2]:='O';
      temp[3]:='M';
      temp[4]:='2';
      temp[5]:=char(0);
      res := cct_lib_open(@temp,cct32_msg,frmmain.Handle);
      if res  <0 then
      showmessage(inttostr(res));

    请高手看看,我调用是不是有什么问题?我不输出的话为啥报错?

    发表于:2008-04-15 16:26:401楼 得分:0
    声明是cdecl,引用也应该是cdecl而不是stdcall吧


    其实就这么简单,唉。。。。。还要努力啊!
  • 相关阅读:
    把swf反编译成fla的几种方法
    隐藏tomcat页面异常显示的版本信息
    配置Tomcat-8.5 JVM内存参数
    Nim Game
    Longest Increasing Path in a Matrix
    信息熵和信息增益
    故乡的云
    urllib编码
    odd_even_list
    Different Ways to Add Parentheses
  • 原文地址:https://www.cnblogs.com/enli/p/1154620.html
Copyright © 2011-2022 走看看