CHANGE an OCX CLSID

hi all
i develop my own CommonDialogControl ocx which shows more options than Microsoft common dialog control , now the problem is the CLSID , as my OCX clsid is not equal by microsoft's , i can not force windows programs to use my own ocx.
is there any way i tell VB6 that compile my OCX with certain CLSID i want ???
hamidgiviAsked:
Who is Participating?
 
danaseamanCommented:
See attached module which allows you to replace existing CLSID with another post build.
You will need to add a reference to "TypeLib Information" located at C:\Windows\System32\TLBINF32.DLL to get the original CLSID.

Calling syntax using this module:

Public Function ReplaceGUIDInFile(ByVal sFileName As String, _
   ByVal sGUIDOld As String, _
   ByVal sGUIDNew As String, _
   ByVal bReplace As Boolean) As Boolean


Option Explicit

Public Function ReplaceGUIDInFile(ByVal sFileName As String, _
   ByVal sGUIDOld As String, _
   ByVal sGUIDNew As String, _
   ByVal bReplace As Boolean) As Boolean

   Dim sText            As String 'File string
   Dim sOld             As String 'Search string
   Dim sNew             As String
   Dim pos              As Long

   sOld = strGUIDtoMemory(sGUIDOld)
   sNew = strGUIDtoMemory(sGUIDNew)
   sText = BinaryFile_Read_VB(sFileName)
   'Note: Hex(pos) returned by InstrB agrees with location when opening OCX with UltraEdit in Hex mode.
   pos = InStrB(1, sText, sOld, vbBinaryCompare)
   Do While pos > 0
      Debug.Print "Match at Hex", Hex(pos)
      If bReplace Then
         sText = Replace(sText, sOld, sNew) 'Note: This replaces both occurences in OCX/DLL
         BinaryFile_Write_VB sFileName, sText
      End If
      pos = InStrB(pos + 1, sText, sOld, vbBinaryCompare)
   Loop

End Function

'Note: Rearrange bytes for memory search/replace.
'Long/Integer byte values are reversed.
Private Function strGUIDtoMemory(ByVal sGUID As String) As String
   Dim b(15)            As Byte
   Dim i                As Long
   Dim lChar            As Long

   'Strip curly brackets and separator
   sGUID = Replace(sGUID, "{", "")
   sGUID = Replace(sGUID, "}", "")
   sGUID = Replace(sGUID, "-", "")

   'Original     File         Type     Comments
   '--------     --------     -------  --------
   '2AEF8139     3981EF2A     Long     Reversed
   'B732         32B7         Integer  Reversed
   '4B9E         9E4B         Integer  Reversed
   'AFB2         AFB2         Byte     Normal
   '7A94F1E616F5 7A94F1E616F5 Byte     Normal

   'Rearrange bytes for memory search/replace
   'From 2AEF8139B7324B9EAFB27A94F1E616F5
   'To   3981EF2A32B79E4B + AFB27A94F1E616F5
   sGUID = Mid(sGUID, 7, 2) & _
      Mid(sGUID, 5, 2) & _
      Mid(sGUID, 3, 2) & _
      Mid(sGUID, 1, 2) & _
      Mid(sGUID, 11, 2) & _
      Mid(sGUID, 9, 2) & _
      Mid(sGUID, 15, 2) & _
      Mid(sGUID, 13, 2) & _
      Mid(sGUID, 17)

   'Populate 16 byte array with sGUID values
   For i = 1 To Len(sGUID) - 1 Step 2
      lChar = "&H" & Mid(sGUID, i, 2)
      'Debug.Print i \ 2, Hex(lChar)
      b(i \ 2) = lChar
   Next

   'Convert byte array to string.
   strGUIDtoMemory = b

End Function

Public Function BinaryFile_Read_VB(ByVal sFileName As String) As String

   Dim FF               As Long
   Dim b()              As Byte

   On Error Resume Next

   FF = FreeFile
   Open sFileName For Binary Access Read As FF
   ReDim b(LOF(FF) - 1)
   Get FF, , b
   Close FF
   BinaryFile_Read_VB = b

End Function

Public Sub BinaryFile_Write_VB(ByVal sFileName As String, ByVal sText As String)

   Dim FF               As Long
   Dim b()              As Byte

   On Error Resume Next
   Kill sFileName
   On Error GoTo 0
   FF = FreeFile
   Open sFileName For Binary Access Write As #FF
   b = sText
   Put #FF, , b
   Close #FF
   
End Sub

Public Function GetLCIDFromFile(ByVal sPath As String) As String
   Dim m_cTLI           As TypeLibInfo
   Set m_cTLI = TLI.TypeLibInfoFromFile(sPath)
   GetLCIDFromFile = m_cTLI.LCID
End Function

Open in new window

0
 
Todd GerbertIT ConsultantCommented:
I don't recall how to setup such things with VB6, but I will say that this is not advisable.

If you did not exactly replicate EVERY (every interface, class, enum, field, etc) feature of Microsoft's common dialog library, this may well cause trouble for programs dependant on this library.
0
 
HooKooDooKuCommented:
Speaking from a phylisophical point of view, it would seem that what you are trying to do would be impossible.  The main reason would be that IF there was a way to assign the CLSID (and I'm sure through some HACK it could be done) it would conflict with existing CLSIDs of Microsoft compenents.

Plus I would hope Microsoft has something build in to avoid allowing this type of manipulation to the operating system.

The real main problem I see with trying to userpt the exiting control is that if you are able to replace the existing control with your own, your version could possibly return values that are unexpected by the applications that have been programmed to specifically work with the CommonDialogControl.

And on top of all that, such code could also been seen as a virus at it is attempting to esentially replace a piece of the operating system (perhaps not the actual "Windows" operating system, but at least the VB supprot files... details are different, but concept is the same).

Now obviously there isn't anything wrong to build your own version of the CommonDialogControl and writing VB programs to utilize your control.  But there is something fundimentally wrong (or at least exceedingly difficult with reliability) with attempting to userpt a part of the operating system.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
hamidgiviAuthor Commented:
thanks tgerbert & hookoodooku
1-with one of tools included in Microsoft visual studio ( Activex Control Test Container) we can find all methods and properties of any ActiveX . so easily we can create our custom activex , have the same as original methods , input and outputs but do things by way we need .

2- change the CLSID in system registery is not my subject, if i don't wrong , when an application want to call an activex , search for it in registery by the Activex CLSID provided in main application at design time,
for example , think we have a ready activex named MoneyTools.OCX , it has CLSID inside the OCX ( suddenly not viewable by text editors)
when we develop a VB program wich use that activex , in our program a refrence to that CLSID creates like "object= "1a234-kjx6494565...." .
we compile our project and move and install it to new machine.
a copy of MoneyTools.OCX will register in new pc registery by the same CLSID ,
when application want to use moneytools.ocx , looks in registery for the key "1a234-kjx6494565...." , find the address of ocx from the registery , find the OCX file , rechek the CLSID with OCX file , and then use it.
thatswhy we can move Dll And OCX files wherever we like ( even a flash memory or network place )  and register them again and programs work Ok.( i mean programs not windows core)

now , my problem is

HOW force VB to compile our custom activex With a certain CLSID we need
OR
HOW change the CLSID inside of an OCX file(compiled) ( not the registery version)

sadly for vb programmers like me , it is so easy in vc++ .
0
 
danaseamanCommented:
Working example:

Dim sFileName As String
sFileName = "C:\MyControls\Release\vbalIml6_EDA1811C.ocx"

ReplaceGUIDInFile sFileName, _
   GetLCIDFromFile(sFileName), _
   "{DFF6AA8E-1EC0-4026-B7F5-61555D9DDB8B}", _
   True)




 
0
 
nffvrxqgrcfqvvcCommented:
This is different in VB that it generates the GUID informatiom automatically for you. When you have finished your component mark it for binary compatability and recompile.

Project > Project Properties choose the Component tab under Version Compatability choose Binary Compatability.

The GUID will be the same on all systems after compiling using binary compatability. Use that GUID in your application or use CLSIDFromProgID() to obtain it automatically.
0
 
hamidgiviAuthor Commented:
Thanks again all
egl1044 ,  the way you show , works only if the refrence OCX file was written in VB.
but i want to assign the Written_by_VC++.OCX  CLSID to my new VB activex .

i think the danaseaman method is better

0
 
danaseamanCommented:
Sorry, this was part of a larger project and I forgot to include Function GetGUIDFromFile.

Dim sFileName As String
sFileName = "C:\MyControls\Release\vbalIml6_EDA1811C.ocx"

ReplaceGUIDInFile sFileName, _
  GetGUIDFromFile(sFileName), _
  "{DFF6AA8E-1EC0-4026-B7F5-61555D9DDB8B}", _
  True)

Public Function GetGUIDFromFile(ByVal sPath As String) As String
   Dim m_cTLI           As TypeLibInfo
   Set m_cTLI = TLI.TypeLibInfoFromFile(sPath)
   GetLCIDFromFile = m_cTLI.Guid
End Function
0
 
danaseamanCommented:
Public Function GetGUIDFromFile(ByVal sPath As String) As String
   Dim m_cTLI           As TypeLibInfo
   Set m_cTLI = TLI.TypeLibInfoFromFile(sPath)
   GetGUIDFromFile = m_cTLI.Guid
End Function
0
 
hamidgiviAuthor Commented:
only a little code  in this module MUST CHANGE.
at line 109 , "GetLCIDFromFile = m_cTLI.LCID"  must change to "GetLCIDFromFile = m_cTLI.GUID" to show us the CLSID ,
the LCID is for language support , that is not our subject
0
 
hamidgiviAuthor Commented:
thanks again all experts
special thanks to danaseaman , the module works fine

but i still have a problem.

i developed MY_OWN1.OCX file , use it in a VB application and compile my application to MY_APP_USE_OCX1.exe

then i create MY_OWN2.OCX file , and with the module you show , change the CLSID of this ocx to the CLSID of MY_OWN1.OCX ,

then i delete MY_OWN1.OCX and copy the MY_OWN2.OCX to the MY_OWN1.OCX folder,

it seems the MY_APP_USE_OCX1.exe should work properly , because the new ocx has same properties and methodes and CLSID and name(file name) all LIKE the original version , but saddly , the application raise an error :

    SYSTEM ERROR $H80040111(-2147221231)

do anybody know whats incorrect ???


0
 
Todd GerbertIT ConsultantCommented:
There's more in that OCX than you can see with the ActiveX test container. For example, did you define the ICommonDialogEvents interface? All of the color constants, and printer orientation constants?

You shouldn't be doing what you're trying to do.  You shouldn't be able to force an application that I wrote to use your OCX.
0
 
hamidgiviAuthor Commented:
the problem changed
the error "SYSTEM ERROR $H80040111(-2147221231) " , was happend because i was develop my OCX in VisualBasic and data types like BSTR , VAR_I4 , .... was not in vb.

again i write my OCX in VC++ 6 , ( it was so hard because i never work with C++ before ) , and many problems solved automatically , custom CLSID  configuration is very very very easy in VC++ even for me , but there is still a problem , i have two prorgams use my OCX , both of them use ALL properties and methods and events of MYOCX , one of them works fine with New_Faked_ocx and one of them raise an error " runtime error 13 , Type mismatch " !!!!!!.
why ? can anybody  tel me ??
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.