Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Registering OCX 3

Status
Not open for further replies.

SGLong

Programmer
Joined
Jun 6, 2000
Messages
405
Location
US
I've got a network application on our server which needs access to the MS DatePicker control. I've got the following code at the top of my main program:

LOCAL lcCommand
lcCommand = "RUN RegSvr32.exe C:\windows\system\MsComct2.ocx /s"
&lcCommand
RELEASE lcCommand

First, it's not "silent".

Second, it's running every time the program starts. How can I detect if the control is already registered and only run this registration when the application is run for the first time on a different workstation?

 
Normally you'd install/register this and any other control in the SETUP.EXE for your application, then you wouldn't have to worry about it in the application itself.

You'll need to read the registry to see if it's registered. Minimally you'll need to check for this key: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\mscomct2.ocx".

Rick
 
Rick,

Doesn't the OCX need to be on the local workstation machine? If so, then an installation (SETUP.EXE) file won't help. It'll be registered on the server and not where it needs to be.

Steve
 
Steve,
Absolutely, while I didn't make it clear, I meant an application Workstation install. Since the example he gave was on "C:", I assumed that was what he was talking about.

Rick
 
Hi Steve,

The OCX can remain in your server directory, as long as it's properly register. However, it really should be placed in the user's local windows\system directory.

Now, to address your two questions. Define exactly what you mean by it's not "silent". The /s switch passed to regsvr32 will prevent the confirmation messagebox from appearing, which is where I presume you derived the term silent. If you're referring to the flash of the DOS console include the nowait switch with a minimize attribute for the RUN command:
RUN /N7 regsvr32 c:\windows\system\mscomct2.ocx /s

AFA determining if the control is already registered, attempt to create an instance:
ON ERROR llNotInstalled = .T.
oDatePick = CreateObject("MSComCt2.DTPicker.2")
IF llNotInstalled
*copy the ocx from network path to local windows\sys dir
*register ocx
ENDIF

FWIW, if the OS is NT-based, the local path will be WinNT\System32. Jon Hawkins
 
Sorry, but the oleclass for the datetime picker is MSComCtl2.DTPicker.2 - I should've consulted the docs prior to posting. So the line that reads:

oDatePick = CreateObject("MSComCt2.DTPicker.2")

should read:

oDatePick = CreateObject("MSComCtl2.DTPicker.2")

And for clarification, Rick's suggestion of using a SETUP application is the proper way for distributing/registering ActiveX controls.
Jon Hawkins
 
Jon,
I do like your CreateObject() / error handling much better than mucking around in the registry. The strange thing is that I'd used that technique before, but forgot about it - probably because it works so good!

Rick
 
Rick & John:

I've consolidated all of the above into a class that will check the registration status. If not registered, it will copy it local and then register it. Once I get the code "cleaned up" I'll post the class in the FAQ section.

Thanks for the guidance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top