Using an ActiveX Control (OCX) Without a Form and Without Registering It

S

Stewart Berman

We need to use an ActiveX control housed in an OCX file within a VBA module.
We are currently doing that by using late binding and
CreateObject("ControlName.ObjectName"). Unfortunately, we now need to be
able to be sure that we are using a specific file from within our
application folder without relying on the registry to find it.

It has been suggested that we could use LoadLibrary to bring in the OCX. If
anyone can point to any sample VBA code that does this it would be greatly
appreciated -- especially if we did not have to define each entry point and
property in our code. The ideal solution would be if we could load the OCX
into memory, create the object we need using it and then use the rest of our
existing code.
 
S

Stewart Berman

Is this what you are looking for? :)


It appears to have the features I want to implement but it is, or was, a
third party product that was oriented to scripting languages. The functions
are not available in Microsoft's products or rather the overrides shown are
not.

In addition, the site appears to be dead. That is all of the current
references are to the end of 2006 and the forums are full of garbage
messages. Actually, some of them are not garbage -- there are ads for CCV,
Bank Logins, pin numbers, etc.
 
T

Tony Toews [MVP]

Stewart Berman said:
We need to use an ActiveX control housed in an OCX file within a VBA module.

What functionality do you require? Maybe there are DLLs or other
alternatives that work instead. For example we have alternatives for
most of the MS OCXs that folks like to use in Access.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/
 
C

Colbert Zhou [MSFT]

Hi Saberman,

Yes, that link is some third party products implements the pattern you
want. I am sorry for not mentioning that.

I haven't find any samples for this pattern, but I found a helpful MSDN
blog article,
http://blogs.msdn.com/mikhailarkhipov/archive/2005/04/01/404433.aspx

"1. Locate COM component DLL.

2. Load it into memory using LoadLibrary.

3. Locate DllGetClassObject function exported from the DLL using
GetProcAddress Win32 API.

4. Call DllGetClassObject and obtain IClassFactory interface of your
component class factory. ATL automatically implements and exports this
function for you.

5. Invoke IClassFactory::CreateInstance.
"

If we do not register the COM dll, the only way to initialize a COM object
is calling DllGetClassObject to get the IClassFactory. Then we can call its
CreateInstance method to create the COM object.


Best regards,
Ji Zhou
Microsoft Online Community Support
 
S

Stewart Berman

Thanks but we need to use this specific OCX. It is part of a complex
security package.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top