我依照书编写了一个dll文件,结果编译能够通过,但是用外部程序调用这个dll中的
 GetDllData过程时提示'无法找到入口',是错在哪里呢?请接触过这类问题的高手帮忙找出原因好吗?源程序如下:
library ShareLib;uses
  SysUtils,
  windows,
  Classes;
type
  Pglobaldlldata=^TGlobaldlldata;
  TGlobaldlldata=record
  s:String[50];
  I:Integer;
end;
const
   cMMFileName:PChar='SharedMapData';{$r *.res}
var
  GlobalData: PGlobalDlldata;
  MapHandle:Thandle;procedure GetDllData(var Aglobaldata:PGlobalDllData);stdcall;
begin
  AGlobalData:=GlobalData;
end;
procedure OpenSharedData;
var
 size:integer;
begin
  Size:=SizeOf(TGlobalDLLData);  MapHandle:=CreateFileMapping(DWord(-1),nil,PAGE_READWRITE,0,size,cMMFileName);  if MapHandle=0 then
     RaiselastWin32Error;  GlobalData:=MapViewofFile(MapHandle,FILE_MAP_ALL_ACCESS,0,0,size);  GlobalData^.s:='ShareLib';
  GlobalData^.I :=1;  if GlobalData=nil then
  begin
    CloseHandle(MapHandle);
    RaiselastWin32Error;
  end;
end;procedure CloseSharedData;
begin
  UnMapViewOffile(GlobalData);
  Closehandle(Maphandle);
end;procedure DLLEntryPoint(dwReason:DWord);
begin
  case dwReason of
    DLL_PROCESS_ATTACH: OpenSharedData;
    DLL_PROCESS_DETACH:CloseSharedData;
  end;
end;
exports
   GetDllData;
begin
  DllProc:=@dllEntryPoint;
  DLLEntryPoint(DLL_PROCESS_ATTACH);
end.

解决方案 »

  1.   

    你是不是还没引出过程呀.用export
      

  2.   

    有啊!
    exports        //-------exports--------//
       GetDllData;
    begin
      DllProc:=@dllEntryPoint;
      DLLEntryPoint(DLL_PROCESS_ATTACH);
    end.
      

  3.   

    是delphi5开发人员指南上的吧。我看了半天没看出有什么区别:(
    前面少了sharemem。但加上了还是报错
      

  4.   

    是delphi6高级编程上的一道例题,我也正在郁闷,程序我读得没问题,哎,自己=大大菜鸟!
      

  5.   

    晕~。例子也有抄袭的??,我把原文贴上来你看看
    {
    Copyright © 1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
    }library ShareLib;uses
      ShareMem,
      Windows,
      SysUtils,
      Classes;
    const  cMMFileName: PChar = 'SharedMapData';{$I DLLDATA.INC}   //这个地方就是定义了一些pglobaldlldata等变量var
      GlobalData : PGlobalDLLData;
      MapHandle  : THandle;{ GetDLLData will be the exported DLL function }
    procedure GetDLLData(var AGlobalData: PGlobalDLLData); StdCall;
    begin
      { Point AGlobalData to the same memory address referred to by GlobalData. }
      AGlobalData := GlobalData;
    end;procedure OpenSharedData;
    var
       Size: Integer;
    begin
      { Get the size of the data to be mapped. }
      Size := SizeOf(TGlobalDLLData);  { Now get a memory-mapped file object. Note the first parameter passes
        the value $FFFFFFFF or DWord(-1) so that space is allocated from the system's
        paging file. This requires that a name for the memory-mapped
        object get passed as the last parameter. }  MapHandle := CreateFileMapping(DWord(-1), nil, PAGE_READWRITE, 0, Size, cMMFileName);  if MapHandle = 0 then
        RaiseLastWin32Error;
      { Now map the data to the calling process's address space and get a
        pointer to the beginning of this address }
      GlobalData := MapViewOfFile(MapHandle, FILE_MAP_ALL_ACCESS, 0, 0, Size);
      { Initialize this data }
      GlobalData^.S := 'ShareLib';
      GlobalData^.I := 1;
      if GlobalData = nil then
      begin
        CloseHandle(MapHandle);
        RaiseLastWin32Error;
      end;
    end;procedure CloseSharedData;
    { This procedure un-maps the memory-mapped file and releases the memory-mapped
      file handle }
    begin
      UnmapViewOfFile(GlobalData);
      CloseHandle(MapHandle);
    end;procedure DLLEntryPoint(dwReason: DWord);
    begin
      case dwReason of
        DLL_PROCESS_ATTACH: OpenSharedData;
        DLL_PROCESS_DETACH: CloseSharedData;
      end;
    end;exports
      GetDLLData;begin
      { First, assign the procedure to the DLLProc variable }
      DllProc := @DLLEntryPoint;
      { Now invoke the procedure to reflect that the DLL is attaching
        to the process }
      DLLEntryPoint(DLL_PROCESS_ATTACH);
    end.
      

  6.   

    问一下楼上, DLLDATA.INC 该怎么生成呢?
      

  7.   

    就直接在里面写了一个记录
    type  PGlobalDLLData = ^TGlobalDLLData;
      TGlobalDLLData = record
        S: String[50];
        I: Integer;
      end;在dll里用了一个编译开关链接
      

  8.   

    请问一下你有没有上面那个程序呢,有的话发给我好吗?(所有相关文件)
    我的email :[email protected]
      

  9.   

    我这样做了以后编译可以通过,但是还是没有办法调用GetDLLData啊
      

  10.   

    能够正确运行的代码:
      {
    Copyright ?1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
    }library ShareLib;uses
      ShareMem,
      Windows,
      SysUtils,
      Classes;
    const  cMMFileName: PChar = 'SharedMapData';{$I DLLDATA.INC}var
      GlobalData : PGlobalDLLData;
      MapHandle  : THandle;{ GetDLLData will be the exported DLL function }
    procedure GetDLLData(var AGlobalData: PGlobalDLLData); StdCall;
    begin
      { Point AGlobalData to the same memory address referred to by GlobalData. }
      AGlobalData := GlobalData;
    end;procedure OpenSharedData;
    var
       Size: Integer;
    begin
      { Get the size of the data to be mapped. }
      Size := SizeOf(TGlobalDLLData);  { Now get a memory-mapped file object. Note the first parameter passes
        the value $FFFFFFFF or DWord(-1) so that space is allocated from the system's
        paging file. This requires that a name for the memory-mapped
        object get passed as the last parameter. }  MapHandle := CreateFileMapping(DWord(-1), nil, PAGE_READWRITE, 0, Size, cMMFileName);  if MapHandle = 0 then
        RaiseLastWin32Error;
      { Now map the data to the calling process's address space and get a
        pointer to the beginning of this address }
      GlobalData := MapViewOfFile(MapHandle, FILE_MAP_ALL_ACCESS, 0, 0, Size);
      { Initialize this data }
      GlobalData^.S := 'ShareLib';
      GlobalData^.I := 1;
      if GlobalData = nil then
      begin
        CloseHandle(MapHandle);
        RaiseLastWin32Error;
      end;
    end;procedure CloseSharedData;
    { This procedure un-maps the memory-mapped file and releases the memory-mapped
      file handle }
    begin
      UnmapViewOfFile(GlobalData);
      CloseHandle(MapHandle);
    end;procedure DLLEntryPoint(dwReason: DWord);
    begin
      case dwReason of
        DLL_PROCESS_ATTACH: OpenSharedData;
        DLL_PROCESS_DETACH: CloseSharedData;
      end;
    end;exports
      GetDLLData;begin
      { First, assign the procedure to the DLLProc variable }
      DllProc := @DLLEntryPoint;
      { Now invoke the procedure to reflect that the DLL is attaching
        to the process }
      DLLEntryPoint(DLL_PROCESS_ATTACH);
    end.
      

  11.   

    错误的代码:
      library ShareLib;uses  ShareMem,
      SysUtils,
      windows,
      Classes;const
       cMMFileName:PChar='SharedMapData';{$I dlldata.inc}
    var
      GlobalData: PGlobalDlldata;
      MapHandle:Thandle;procedure GetDllData(var Aglobaldata:PGlobalDllData);stdcall;
    begin
      AGlobalData:=GlobalData;
    end;
    procedure OpenSharedData;
    var
     size:integer;
    begin
      Size:=SizeOf(TGlobalDLLData);  MapHandle:=CreateFileMapping(DWord(-1),nil,PAGE_READWRITE,0,size,cMMFileName);  if MapHandle=0 then
         RaiselastWin32Error;  GlobalData:=MapViewofFile(MapHandle,FILE_MAP_ALL_ACCESS,0,0,size);  GlobalData^.s:='ShareLib';
      GlobalData^.I :=1;  if GlobalData=nil then
      begin
        CloseHandle(MapHandle);
        RaiselastWin32Error;
      end;
    end;procedure CloseSharedData;
    begin
      UnMapViewOffile(GlobalData);
      Closehandle(Maphandle);
    end;procedure DLLEntryPoint(dwReason:DWord);
    begin
      case dwReason of
        DLL_PROCESS_ATTACH:OpenSharedData;
        DLL_PROCESS_DETACH:CloseSharedData;
      end;
    end;
    exports
       GetDllData;
    begin
      DllProc:=@dllEntryPoint;
      DLLEntryPoint(DLL_PROCESS_ATTACH);
    end.