Link to home
Start Free TrialLog in
Avatar of jmartins71
jmartins71

asked on

Get CLSID from ocx filename

How can I get the CLSID of one control
when I just have the name/path of the ocx file?
Avatar of mikeblas
mikeblas

You can't.  The OCX file might implement more than one control.

..B ekiM
you can always search the registry - to see if it matches in there - not sensible to do in a program but you can use regedit
or if it has a typelibrary you could load that and parse it - I think there are tools available to do that - that could be a programmatical way
> not sensible to do in a program but you can use regedit

Why not?

 > or if it has a typelibrary you could load that and parse it

Again, there may be more than one typelib in the control.

There's no identity between an OCX file and a given CLSID. You can enumerate a list of CLSIDs that are in a given OCX. But that's not the question that's been asked here.

I think you'll find that most efficient way to build that list really is to enumerate entries in the registry.

..B ekiM
> Why not?

I was thinking of time to complete - if it isn't a problem then go for it - but if it is only for 1 (one) .ocx then use regedit and the find option.
If you want to get to know this CLSID by your hands, you can use oleview to load this ocx file as a typelib file. But if you want to do this in your program, you should write a lot of codes to parse a typelib.

What do your actually want to do?
> What do your actually want to do?

that is a point - maybe if we knew what you wnated to do with it we could help :)
Avatar of jmartins71

ASKER

First of all thanks everybody!

In my application I need to switch between activex plugins.
Before I do this I need to get the CLSID from each ocx file the user wants to use. EACH OCX HAS ONLY ONE CONTROL.

Then I register this CLSID in my application registry entries.

The problem is of course how can I know the CLSID (or progID) just by knowing the ocx file that the user wants two use! Just one thing. I first register the control so the entries are in registry. but I am seing the filename like dos!!!

Mikeblas says I can not! That surprise me because if it is so how can Visual C++ wizard knows it when is creating one class for it (by doing add to project - activex)!!!!!

I have found on MSDN the following function:
"
GetClassFile
Supplies the CLSID associated with the given filename.

WINOLEAPI GetClassFile(
  LPCWSTR szFileName,
                  //Pointer to filename for which you are requesting
                  // a CLSID
  CLSID * pclsid  //Pointer to location for returning the CLSID
);

"

But I can not make it work! I am always getting the error code: MK_E_INVALIDEXTENSION

Maybe I am not using a good parameter for szFilename!?
What I am using is :
CString FileName; // with the filename and path of ocx file
BSTR temp = FileName.AllocSysString();

then use temp in szFileName.
> Mikeblas says I can not! That surprise me because if it is so how can Visual C++ wizard knows it when is creating one class for it (by doing add to project - activex)!!!!!

Visual Studio uses the typelibrary

>GetClassFile
>Supplies the CLSID associated with the given filename.

I thought that was for file extensions (read the remarks)

GetClassFile() used only for storage type files - like word's doc, excel's xls etc.

YOu can not use this function for exes.
BUt you always can search registry
HK_CLASSES_ROOT\CLSID\Inprocserver32 for file name of your OCX.
Be careful - path/filename may be converted to short.
Thanks,

I have found my file entry in win32 reg key!? Is this the same or was it generated by VStudio!?

Can I use this?

the path was HKEY_CLASSES_ROOT\typelib\(clsid)\1.0\0\win32


I have found as I say one file entry but has the ~chars (dos name files)

Two questions:
1) I do not know how to convert from my CString file to one dos filename.
2) How to begin one registry search?
Can you give me one api function for me to start.




all functions working with registry starts with Reg...
RegOpenKey
RegCreateKey
RegQueryValue
etc

or you can examine ATL's CRegKey class
it simplifies work with registry


http://www.codeguru.com/system/CRegKey.shtml
Ok,
I know CRegKey. But here is what I have found for my control:

HKEY_CLASSES_ROOT\CLSID\Inprocserver32
with "E:\TEMP\DUMMYP~1\DEBUG\DUMMYP~1.OCX"

Now I have "E:\TEMP\DUMMYPlatform\DEBUG\DUMMYplatform.OCX"

How to :
1)convert to string woth the dos limitations.
2) Query this key when I do not know the clsid to open it!?

Sorry but I am not understanding how to make registry queries on subkeys when I do not know the keys!?

ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you mikeblas
If these are in-house objects and you still have the source you could always add a new exported function called something like GetOCXCLSID(CLSID * pCLSID) or something like that and make your task easier

 > If these are in-house objects and you still have the
 > source you could always add a new exported function
 > called something like GetOCXCLSID(CLSID * pCLSID) or
 > something like that and make your task easier

I guess that might make the task a little easier, but it makes it very inefficient. Pawing through the whole HKCR\CLSID hive of the registry is going to be faster than loading a DLL, initializing it, and calling an entry point on it.

..B ekiM
> Pawing through the whole HKCR\CLSID hive of the registry is going to be faster than loading a DLL, initializing it, and calling an entry point on it

Really - I'd have thought it would be the other way round. I may do some tests if I ever need to do such a thing
I just want to make the following comment about How I have done it.

I have followed ShaunWilde comment because:

Since I have to register the control
I need to Load the DLL. The only thing I must do is to invoke another export function!
So, at least in my case is really better then parsing the registry.
> Since I have to register the control

Oh. If you've got to load and install the control anyway, then it probably is better just to go poking for that extra export.

..B ekiM