DLL中能否使用RegisterClass?
请教各位高人,能否住DLL中使用RegisterClass注册类,并住调用程序软件代码中使用GetClass将其取出?为什么俺每次都非到?谢谢!
//MYLIB.DLL:initialization
RegisterClass(TMyClass);
finalization
UnregisterClass(TMyClass);
end.//Application:
...
LoadLibrary('MYLIB.DLL');
if GetClass('TMyClass') = nil
then ShowMessage('Class not found');怎么都找不到?要怎么弄呢?
请教各位高人,能否住DLL中使用RegisterClass注册类,并住调用程序软件代码中使用GetClass将其取出?为什么俺每次都非到?谢谢!
//MYLIB.DLL:initialization
RegisterClass(TMyClass);
finalization
UnregisterClass(TMyClass);
end.//Application:
...
LoadLibrary('MYLIB.DLL');
if GetClass('TMyClass') = nil
then ShowMessage('Class not found');怎么都找不到?要怎么弄呢?
exe中的RegGroups中含有你的相关类的注册信息
------------------------------------------------
额,,我在网上查了下是这样说的,但是我现在有一套源码却是采用DLL来做的,在library界面中也没有看见有有导出方法来SHOW窗体,
其下有注册类
initialization
RegisterClassE(TCallProcTestfrm);
finalization
UnRegisterClassE(TCallProcTestfrm);
但源代码不完整,所以不怎么明白是怎么实现的
If a class is registered in a dynamic-link library (DLL) with the RegisterClass() function and an application uses this class when creating a window or a dialog box, then the CreateDialog() or CreateWindow() call in the application will fail. The debug version of Windows will produce a Fatal Exit code 0x8800 with the following message:
To register a window class in a DLL and subsequently create a window (or create a dialog box) of that class in any application that links into this DLL, the window class must be registered with the CS_GLOBALCLASS class style. This style specifies that the window class is an application global class, and will allow this class to be accessed globally by all applications. The CS_GLOBALCLASS class style is documented in the Windows version 3.1 SDK "Programmer's Reference, Volume 1: Overview," manual on page 19 under the Class Styles section.
不过暂时只能帮这么多了,dll注册类用的不多
难道二者结合后可以从BPL中获得---?
------------BPL中一窗体管理单元
interface
uses Classes,SysUtils;type
TManagerForm=class(TObject)
private
FClassList:TList;
function GetClass(Index: Integer): TPersistentClass;
function GetCount: Integer;
public
constructor Create;
destructor Destroy;override;
function FindClassE(AClass:TPersistentClass):Integer;
procedure RegisterClassE(AClass:TPersistentClass);
procedure UnRegisterClassE(AClass:TPersistentClass);
property Items[Index:Integer]:TPersistentClass read GetClass;
property Count:Integer read GetCount;
end;
procedure RegisterClassE(AClass:TPersistentClass); //注册窗体类函数
procedure UnRegisterClassE(AClass:TPersistentClass); //反注册窗体类函数
var
GoManagerForm:TManagerForm;implementationprocedure RegisterClassE(AClass:TPersistentClass);
begin
GoManagerForm.RegisterClassE(AClass);
end;procedure UnRegisterClassE(AClass:TPersistentClass);
begin
GoManagerForm.UnRegisterClassE(AClass);
end;{ TManagerForm }constructor TManagerForm.Create;
begin
FClassList:=TList.Create;
end;destructor TManagerForm.Destroy;
begin
FClassList.Free;
inherited;
end;function TManagerForm.FindClassE(AClass: TPersistentClass): Integer;
var
i:Integer;
loClass:TPersistentClass;
begin
Result:=-1;
for i:=0 to Count-1 do
begin
loClass:=TPersistentClass(FClassList[i]);
if AClass=loClass then
begin
Result:=i;
Exit;
end;
end;
end;function TManagerForm.GetClass(Index: Integer): TPersistentClass;
begin
if (Index>-1) and (Index<Count) then
Result:=TPersistentClass(FClassList[Index])
else
Result:=nil;
end;function TManagerForm.GetCount: Integer;
begin
Result:=FClassList.Count;
end;procedure TManagerForm.RegisterClassE(AClass: TPersistentClass);
var
Index:Integer;
begin
Index:=FindClassE(AClass);
if Index<0 then
begin
FClassList.Add(AClass);
try
RegisterClass(AClass);
except
end;
end;
end;procedure TManagerForm.UnRegisterClassE(AClass: TPersistentClass);
var
Index:Integer;
begin
Index:=FindClassE(AClass);
if Index>=0 then
begin
FClassList.Delete(Index);
try
UnRegisterClass(AClass);
except
end;
end;
end;initialization
GoManagerForm:=TManagerForm.Create;
finalization
GoManagerForm.Free;
end.
除非你的DLL和EXE都是带运行时包运行的.Classes才会都用运行时包中的
编译dll和exe时在options中选择build with runtime packages
两个项目都引用同一个包
把类信息写在包中
然后调用包的时候,内存中会只维护一份类实例,因为包本身是包含类信息的