我依照书编写了一个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.
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.
解决方案 »
- 请教高手们!(我是菜鸟),解决出错.谢谢!
- 怎么知道combobox选中的序号如combobox.item[i]中的i
- 想入门delphi,不知从何下手,请打虾们指点指点。。。
- 热键
- 怎么将Treeview.Items.Item[i].data的值赋给一个record类型的变量啊?
- 请问这是不是delphi6的bug
- !!!!!负载平衡问题,大师级人物请进来,入门者回避,送分!
- 告诉各位一个很有意思的事!关于delphi使用内存的!(很有用哟!)
- 问个奇怪的问题!
- 我想统计dbgrid中某一列的所有值的和该用什么函数????怎么写????高分请教
- 100分,如何给TButton加自定义消息。GZ都有分。
- 如何让Label中的文字换行
exports //-------exports--------//
GetDllData;
begin
DllProc:=@dllEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
前面少了sharemem。但加上了还是报错
{
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.
type PGlobalDLLData = ^TGlobalDLLData;
TGlobalDLLData = record
S: String[50];
I: Integer;
end;在dll里用了一个编译开关链接
我的email :[email protected]
{
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.
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.