yoy.be "Why-o-Why"

Skipping the COM registry by calling DllGetClassObject yourself

2015-09-30 16:07  DllGetClassObject  delphi  [permalink]

Yey! For the first time ever I created a COM object from the DLL, skipping the COM registry. (Should have done this much, much sooner!) Why, you ask? Just to be sure you're using the correct DLL, and that the registry is not (ab)used to divert it to another DLL. And also this way in some cases you can avoid having to get administrative privileges at some point just to get that COM registration into the Windows registry...

type
T_DGCO=function(const CLSID, IID: TGUID; var Obj): HResult; stdcall;//DllGetClassObject
var
p:T_DGCO;
f:IClassFactory;
x:IMyObject;//replace by an interface of choice
begin
p:=GetProcAddress(LoadLibrary(FullPathToDLL),'DllGetClassObject');
if (p=nil) or (p(CLASS_MyObject,IClassFactory,f)<>S_OK) then
RaiseLastOSError;
if f.CreateInstance(nil,IMyObject,x)<>S_OK then
RaiseLastOSError;
x.Hello('World');//or whatever your object does
end;