问题:
App1.exe调用xxx.Dll,并传递一些参数给xxx.Dll,
使xxx.Dll中的一些变量获得数值!
然后让App1.exe启动App2.exe,而App2.exe要使用xxx.Dll中已经存在数值的变量!难、难、难!!!难死我了!唉~~~~~~
怎么办?
App1.exe调用xxx.Dll,并传递一些参数给xxx.Dll,
使xxx.Dll中的一些变量获得数值!
然后让App1.exe启动App2.exe,而App2.exe要使用xxx.Dll中已经存在数值的变量!难、难、难!!!难死我了!唉~~~~~~
怎么办?
image1 : timage;例如参数Pic1显示图像1,参数Pic2显示图像2:procedure TForm1.FormActivate(Sender: TObject);
begin
if (paramcount{ 参数个数 }<1) or
(paramstr(1)='Pic1') then
image1.Picture.LoadFromFile('c:\pic1.BMP')
else
if (paramstr(1)='Pic2') then
image1.Picture.LoadFromFile('c:\pic2.BMP');
end;paramstr(n) n=1 --- paramcount 为第n个参数,
用映射文件或WM_COPYDATA等等.
你说的是不同的App之间,通过命令行方式传递参数的方法
和我的问题不一样!我要的是xxx.Dll驻留,多个应用程序公用其中方法,
而且xxx.Dll中的参数、状态要有App1.exe(主程序)改变,
其他程序(子程序)只是引用bpint(流离) :
你说的方法我没用过,能不能说得再详细点?或者哪里有资料可供参考?谢谢 !
你有相关例子吗?如何直接访问呢?
library Project1;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,Windows,
Classes;
const
cMMFileName: PChar = 'SharedMapData';{$R *.res}
var
MyString : PChar;
MapHandle : THandle;
procedure GetDLLData(test:PChar); StdCall;
begin
{ Point AGlobalData to the same memory address referred to by GlobalData. }
strcopy(test,mystring);
end;
procedure SetDLLData(test:PChar);StdCall;
begin
strcopy(mystring,test);
end;
procedure OpenSharedData;
var
Size: Integer;
begin
{ Get the size of the data to be mapped. }
getmem(mystring,1024);
Size :=SizeOf(MyString);
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 }
MyString:=MapViewOfFile(MapHandle, FILE_MAP_ALL_ACCESS, 0, 0, Size);
{ Initialize this data } if MyString = 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(MyString);
CloseHandle(MapHandle);
end;procedure DLLEntryPoint(dwReason: DWord);
begin
case dwReason of
DLL_PROCESS_ATTACH: OpenSharedData;
DLL_PROCESS_DETACH: CloseSharedData;
end;
end;exports
GetDLLData,
SetDLLData;
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.
outer2000(天外流星) 小弟愚笨!烦请mail实例!我的最简单的要求是:
App1.exe启动xxx.dll传入参数,
xxx.dll通过这些参数连接数据库
App2.exe使用xxx.dll中的方法访问数据库!麻烦各位了!~
时把ini文件中的参数取出连接数据库。
你的方法缺乏安全性!
QQ联系!谢谢~~