Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi Vefiry if CLSID/CLASS ID is Valid

Posted on 2010-01-12
6
Medium Priority
?
1,564 Views
Last Modified: 2013-12-03
Hello everybody

Someone knows how to verify if a CLSID/ClassID is valid?

example

Its a valid CLSID
{B19A7CF5-7AA4-4FF9-8625-4FDE4AC47FB4}

Its invalid since i made it myself
{8AFEFA22-875F-AF2A-C00C-CAF23FB3AFCF}

look, both seems to be valid hehe

but programatically, how to check when its valid or not?

Best Regards,
Carlos
0
Comment
Question by:cebasso
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 1000 total points
ID: 26292309
you can make a GUID in Delphi by hitting Ctrl-Shift G
http://www.delphifaq.com/faq/delphi_windows_API/f533.shtml

a GUID in the CLSID is just one that exists in the registry
from a program which registered it

there are many ways to create a GUID
http://createguid.com/
http://msdn.microsoft.com/en-us/library/ms241442%28VS.80%29.aspx
0
 
LVL 4

Author Comment

by:cebasso
ID: 26292337
Hello Geert_Gruwez!
Ok, but how to check if a given GUID is valid?
In this case, i'm not talking about a GUID that Exists in the registry... its about created guids/classids
example
function ValidCLSID(const szBuff: String): Boolean;
if ValidCLSID('{B19A7CF5-7AA4-4FF9-8625-4FDE4AC47FB4}') then OK else not
Thanks!
0
 
LVL 12

Accepted Solution

by:
Hypo earned 1000 total points
ID: 26292393
Check the sample below...
uses ...,ActiveX;

function ValidClassID(ACLSID : TGUID) : Boolean;
var aRes : HRESULT;
    P : PWideChar;
begin
  Result := False;
  aRes := ProgIDFromCLSID(ACLSID, P);
  CoTaskMemFree(P);
  case aRes of
    S_OK:
      Result := True;
    REGDB_E_CLASSNOTREG:
      Result := False;
    else
      OleCheck(aRes);
  end;
end;

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 1000 total points
ID: 26292429
in essence it's just a number ...
so all GUID's are valid
it's just a hexadecimal presentation of the number with some '-' positions

you could use this class TGuidEx from about.com
http://delphi.about.com/library/weekly/aa022205a.htm

0
 
LVL 4

Author Closing Comment

by:cebasso
ID: 31676042
Thank you all for help-me
It will help anyone since learn how to create and how to check and manipulate..

Thank you very much!
Cheers!!
0
 
LVL 4

Author Comment

by:cebasso
ID: 26292755
Thank you all for help :D
based on Hypo example, i have adapted with my needs

function ValidClassID(const szCLSID: String): Boolean;
var
  hRes: HRESULT;
  g: TGUID;
begin
  Result := True;
  try
    hRes := CLSIDFromString(PWideChar(WideString(szCLSID)), g);
  except
    on E: Exception do
    Result := False;
  end;
  if Result then
  try
    OleCheck(hRes);
  except
    on E: Exception do
    Result := False;
  end;
end;
Cheers!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question