ProgramId through API? 
Author Message
 ProgramId through API?

Hi , i need some help on the following problem.

I need to get the ProgramID of a given/current com object (Dll, OCX
etc), that is the LibName.ObjName (without going throught the registry)
I know that this info is somehow saved in the compiled version of any
DLL,OCX etc.(regsrv32 reads it and saves it in the registry)

Here is some "symbolic" code of  what i want to do:

addinRegistration.bas:
proId=getMyProgID()
saveSomewereinRegistry(proId)
....
.....
_____________________________

appLoadAddin.bas:
addinProgId=readFromRegistryAddinProgId()
createObject(SomeAddinId)

I know know that this info can be hardcoded during the writing of the
COM object
(ProjectName.ModuleName) but i want to get it dynamically.

So the question is: were is it saved in the compiled module ?,
and is it possible to access it from an API?
eg: getProgId(myProcHandle)

Thanks in advance,
Apostolos Benisis.




Mon, 21 Jan 2002 03:00:00 GMT  
 ProgramId through API?

Copy the following code and paste it in a .bas module:

Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any,
Src As Any, ByVal L As Long)
Declare Function lstrlenA Lib "kernel32" (ByVal PtrToStr As Any) As Long
Declare Function lstrcpyA Lib "kernel32" (ByVal Dest As Any, ByVal Src As
Any) As Long

Type ClassInfoStruct
    Unknown_1(1 To 9) As Long
    ControlNamePrefix As Long    ' LPSTR
    lpszProgID As Long               ' LPSTR ProgID (VB controls does not
have a ProgID)
    Unknown_2 As Long
    lpszClassName As Long        ' LPSTR Class name
    lpszFullClassName As Long   ' LPSTR the full class name including the
library Name
End Type

Function ProgIDFromObject(ByVal Obj As Object) As String
Dim ClassInfoPtr As Long, Info As ClassInfoStruct

    MoveMemory ClassInfoPtr, ByVal ObjPtr(Obj) + 36, 4
    MoveMemory Info, ByVal ClassInfoPtr, Len(Info)

    ProgIDFromObject = String$(lstrlenA(Info.lpszProgID), 0)
    lstrcpyA ProgIDFromObject, Info.lpszProgID

End Function

--
Eduardo A. Morcillo
New: Read Office document properties with VB code.
Free ActiveX controls, TypeLibs & Code:
http://www.geocities.com/SiliconValley/Foothills/9940

Quote:

> Hi , i need some help on the following problem.

> I need to get the ProgramID of a given/current com object (Dll, OCX
> etc), that is the LibName.ObjName (without going throught the registry)
> I know that this info is somehow saved in the compiled version of any
> DLL,OCX etc.(regsrv32 reads it and saves it in the registry)

> Here is some "symbolic" code of  what i want to do:

> addinRegistration.bas:
> proId=getMyProgID()
> saveSomewereinRegistry(proId)
> ....
> .....
> _____________________________

> appLoadAddin.bas:
> addinProgId=readFromRegistryAddinProgId()
> createObject(SomeAddinId)

> I know know that this info can be hardcoded during the writing of the
> COM object
> (ProjectName.ModuleName) but i want to get it dynamically.

> So the question is: were is it saved in the compiled module ?,
> and is it possible to access it from an API?
> eg: getProgId(myProcHandle)

> Thanks in advance,
> Apostolos Benisis.





Mon, 21 Jan 2002 03:00:00 GMT  
 ProgramId through API?
Thanks Eduardo Morcillo that was great help.


Tue, 22 Jan 2002 03:00:00 GMT  
 ProgramId through API?
Thanks for the help but , it seems that your code does not work.
In fact if you try to run it vb crashes :)
So i changed
    MoveMemory Info, ByVal ClassInfoPtr, Len(Info)
to  :
    MoveMemory Info,  ClassInfoPtr, Len(Info)

and if fixed the crash
but still after  this change  the string pointers  of the Info variable point
to zero length strings!
Do you have any suggestions?

Quote:

> Copy the following code and paste it in a .bas module:

> Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any,
> Src As Any, ByVal L As Long)
> Declare Function lstrlenA Lib "kernel32" (ByVal PtrToStr As Any) As Long
> Declare Function lstrcpyA Lib "kernel32" (ByVal Dest As Any, ByVal Src As
> Any) As Long

> Type ClassInfoStruct
>     Unknown_1(1 To 9) As Long
>     ControlNamePrefix As Long    ' LPSTR
>     lpszProgID As Long               ' LPSTR ProgID (VB controls does not
> have a ProgID)
>     Unknown_2 As Long
>     lpszClassName As Long        ' LPSTR Class name
>     lpszFullClassName As Long   ' LPSTR the full class name including the
> library Name
> End Type

> Function ProgIDFromObject(ByVal Obj As Object) As String
> Dim ClassInfoPtr As Long, Info As ClassInfoStruct

>     MoveMemory ClassInfoPtr, ByVal ObjPtr(Obj) + 36, 4
>     MoveMemory Info, ByVal ClassInfoPtr, Len(Info)

>     ProgIDFromObject = String$(lstrlenA(Info.lpszProgID), 0)
>     lstrcpyA ProgIDFromObject, Info.lpszProgID

> End Function

> --
> Eduardo A. Morcillo
> New: Read Office document properties with VB code.
> Free ActiveX controls, TypeLibs & Code:
> http://www.geocities.com/SiliconValley/Foothills/9940


> > Hi , i need some help on the following problem.

> > I need to get the ProgramID of a given/current com object (Dll, OCX
> > etc), that is the LibName.ObjName (without going throught the registry)
> > I know that this info is somehow saved in the compiled version of any
> > DLL,OCX etc.(regsrv32 reads it and saves it in the registry)

> > Here is some "symbolic" code of  what i want to do:

> > addinRegistration.bas:
> > proId=getMyProgID()
> > saveSomewereinRegistry(proId)
> > ....
> > .....
> > _____________________________

> > appLoadAddin.bas:
> > addinProgId=readFromRegistryAddinProgId()
> > createObject(SomeAddinId)

> > I know know that this info can be hardcoded during the writing of the
> > COM object
> > (ProjectName.ModuleName) but i want to get it dynamically.

> > So the question is: were is it saved in the compiled module ?,
> > and is it possible to access it from an API?
> > eg: getProgId(myProcHandle)

> > Thanks in advance,
> > Apostolos Benisis.





Tue, 22 Jan 2002 03:00:00 GMT  
 ProgramId through API?
1) The MoveMemory line is:

        MoveMemory Info, ByVal ClassInfoPtr, Len(Info)

    Don't change it.

2) Are you using VB6? The code was only tested in VB5.

3) VB controls and forms don't have ProgIds.

--
Eduardo A. Morcillo
New: Read Office document properties with VB code.
Free ActiveX controls, TypeLibs & Code:
http://www.geocities.com/SiliconValley/Foothills/9940

Quote:
> Thanks for the help but , it seems that your code does not work.
> In fact if you try to run it vb crashes :)
> So i changed
>     MoveMemory Info, ByVal ClassInfoPtr, Len(Info)
> to  :
>     MoveMemory Info,  ClassInfoPtr, Len(Info)

> and if fixed the crash
> but still after  this change  the string pointers  of the Info variable
point
> to zero length strings!
> Do you have any suggestions?


> > Copy the following code and paste it in a .bas module:

> > Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As
Any,
> > Src As Any, ByVal L As Long)
> > Declare Function lstrlenA Lib "kernel32" (ByVal PtrToStr As Any) As Long
> > Declare Function lstrcpyA Lib "kernel32" (ByVal Dest As Any, ByVal Src
As
> > Any) As Long

> > Type ClassInfoStruct
> >     Unknown_1(1 To 9) As Long
> >     ControlNamePrefix As Long    ' LPSTR
> >     lpszProgID As Long               ' LPSTR ProgID (VB controls does
not
> > have a ProgID)
> >     Unknown_2 As Long
> >     lpszClassName As Long        ' LPSTR Class name
> >     lpszFullClassName As Long   ' LPSTR the full class name including
the
> > library Name
> > End Type

> > Function ProgIDFromObject(ByVal Obj As Object) As String
> > Dim ClassInfoPtr As Long, Info As ClassInfoStruct

> >     MoveMemory ClassInfoPtr, ByVal ObjPtr(Obj) + 36, 4
> >     MoveMemory Info, ByVal ClassInfoPtr, Len(Info)

> >     ProgIDFromObject = String$(lstrlenA(Info.lpszProgID), 0)
> >     lstrcpyA ProgIDFromObject, Info.lpszProgID

> > End Function

> > --
> > Eduardo A. Morcillo
> > New: Read Office document properties with VB code.
> > Free ActiveX controls, TypeLibs & Code:
> > http://www.geocities.com/SiliconValley/Foothills/9940


> > > Hi , i need some help on the following problem.

> > > I need to get the ProgramID of a given/current com object (Dll, OCX
> > > etc), that is the LibName.ObjName (without going throught the
registry)
> > > I know that this info is somehow saved in the compiled version of any
> > > DLL,OCX etc.(regsrv32 reads it and saves it in the registry)

> > > Here is some "symbolic" code of  what i want to do:

> > > addinRegistration.bas:
> > > proId=getMyProgID()
> > > saveSomewereinRegistry(proId)
> > > ....
> > > .....
> > > _____________________________

> > > appLoadAddin.bas:
> > > addinProgId=readFromRegistryAddinProgId()
> > > createObject(SomeAddinId)

> > > I know know that this info can be hardcoded during the writing of the
> > > COM object
> > > (ProjectName.ModuleName) but i want to get it dynamically.

> > > So the question is: were is it saved in the compiled module ?,
> > > and is it possible to access it from an API?
> > > eg: getProgId(myProcHandle)

> > > Thanks in advance,
> > > Apostolos Benisis.





Wed, 23 Jan 2002 03:00:00 GMT  
 ProgramId through API?
So :

2) Are you using VB6? The code was only tested in VB5.

Yes i am using VB6. Can this code be converted to vb6?
or should i make a dll in vb5 and use it from vb6 projects?Will it then
work?

Quote:

>1) The MoveMemory line is:

>        MoveMemory Info, ByVal ClassInfoPtr, Len(Info)

>    Don't change it.

>2) Are you using VB6? The code was only tested in VB5.

>3) VB controls and forms don't have ProgIds.



Wed, 23 Jan 2002 03:00:00 GMT  
 ProgramId through API?

Quote:

>So :

>2) Are you using VB6? The code was only tested in VB5.

>Yes i am using VB6. Can this code be converted to vb6?
>or should i make a dll in vb5 and use it from vb6 projects?Will it then
>work?

Well i installed vb5.0 but the problems still persists!!!
Were can i get some relevant documentation ?


Wed, 23 Jan 2002 03:00:00 GMT  
 ProgramId through API?
Apostolos,

Quote:
>I need to get the ProgramID of a given/current com object (Dll, OCX
>etc), that is the LibName.ObjName (without going throught the registry)

I'm not exactly sure what Eduardo's up to, but you
can use the " TypeLib Information" type library ("TLI"
in the references dialog) that comes with VB to
assist in concocting a progid...

Public Function ProgID(obj As Object) As String
  Dim tlia As New TLIApplication
  ' the object may have no Parent, in which case we won't get a ProgID
  On Error Resume Next
  ProgID = tlia.InterfaceInfoFromObject(obj).Parent & "." & TypeName(obj)
End Function

There's a rather nice html help file for it at:
http://msdn.microsoft.com/vbasic/downloads/addon.asp
"Visual Studio 6.0 TypeLib Information Object Library
HTML Help file"

And after poking around a little, it appears that the

  tlia.InterfaceInfoFromObject(obj).Parent[.Name]

call equates to:

  IDispatchObject.GetTypeInfo(..., ITypeInfo)
  ITypeInfo.GetContainingTypeLib(ITypeLib)
  ITypeLib.GetDocumentation(-1, ...)

I have absolutely no idea what VB does to fill TypeName
though (...as if it matters much anyway).

--
Brad Martinez, http://www.mvps.org
Please direct questions/replies to the newsgroup

Quote:

>Hi , i need some help on the following problem.

>I need to get the ProgramID of a given/current com object (Dll, OCX
>etc), that is the LibName.ObjName (without going throught the registry)
>I know that this info is somehow saved in the compiled version of any
>DLL,OCX etc.(regsrv32 reads it and saves it in the registry)

>Here is some "symbolic" code of  what i want to do:

>addinRegistration.bas:
>proId=getMyProgID()
>saveSomewereinRegistry(proId)
>....
>.....
>_____________________________

>appLoadAddin.bas:
>addinProgId=readFromRegistryAddinProgId()
>createObject(SomeAddinId)

>I know know that this info can be hardcoded during the writing of the
>COM object
>(ProjectName.ModuleName) but i want to get it dynamically.

>So the question is: were is it saved in the compiled module ?,
>and is it possible to access it from an API?
>eg: getProgId(myProcHandle)

>Thanks in advance,
>Apostolos Benisis.





Wed, 23 Jan 2002 03:00:00 GMT  
 ProgramId through API?
Well i have tried your code but still, it does not do what i want. (the
control does not have a parent )
Perhaps i was not clear enough with my problem, so let me rephrase it:

Let us say that i have a VB project with a control.
MyProject.vbp
MyProject\MyControl.ctl
and i want some kind of code that will resolve the "MyProject.MyControl.ocx"
ProgId at run time
given the object "Me"
i.e in Module
   MyControl.ctl:
       sub getProgIdAndDoSomething()
            .....
            progID=getProgID(Me) ' It should be "MyProject.MyControl.ocx"
            ......
        end sub
        function getProgID(obj as object) as string
            .....
            .....
        end function

Quote:

>Apostolos,

>>I need to get the ProgramID of a given/current com object (Dll, OCX
>>etc), that is the LibName.ObjName (without going throught the registry)

>I'm not exactly sure what Eduardo's up to, but you
>can use the " TypeLib Information" type library ("TLI"
>in the references dialog) that comes with VB to
>assist in concocting a progid...

>Public Function ProgID(obj As Object) As String
>  Dim tlia As New TLIApplication
>  ' the object may have no Parent, in which case we won't get a ProgID
>  On Error Resume Next
>  ProgID = tlia.InterfaceInfoFromObject(obj).Parent & "." & TypeName(obj)
>End Function

>There's a rather nice html help file for it at:
>http://msdn.microsoft.com/vbasic/downloads/addon.asp
>"Visual Studio 6.0 TypeLib Information Object Library
>HTML Help file"

>And after poking around a little, it appears that the

>  tlia.InterfaceInfoFromObject(obj).Parent[.Name]

>call equates to:

>  IDispatchObject.GetTypeInfo(..., ITypeInfo)
>  ITypeInfo.GetContainingTypeLib(ITypeLib)
>  ITypeLib.GetDocumentation(-1, ...)

>I have absolutely no idea what VB does to fill TypeName
>though (...as if it matters much anyway).

>--
>Brad Martinez, http://www.mvps.org
>Please direct questions/replies to the newsgroup



Thu, 24 Jan 2002 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. ProgramId through API?

2. ProgramId through API?

3. ProgramID through Api?

4. ProgramID through Api?

5. How do i get the Control ProgramId?.

6. API API API

7. API, API, Who's got the API

8. releaseCapture API and send message API.

9. need help with releaseCapture API and send message API

10. I need Windows 3.11 API / Necesito API de Windows 3.11

11. Win32 API / NET API security context

12. New API-Guide & API-Toolshed Released

 

 
Powered by phpBB® Forum Software