Home All Groups Group Topic Archive Search About

Programmatically Crawl a DLL's Namespacec

Author
17 Aug 2006 4:34 PM
jwgoerlich
Hello,

In Visual Studio, one can add in a DLL as a reference. Then, using
Object Browser, one can open and browse thru the DLL's namespace and
look at its objects and functions.

Is there a way to do this programmatically? That is, to point to a
specific DLL and return its namespace as a string?

Thanks in advance,

J Wolfgang Goerlich

Author
17 Aug 2006 7:05 PM
Chris Dunaway
jwgoerl***@gmail.com wrote:
> In Visual Studio, one can add in a DLL as a reference. Then, using
> Object Browser, one can open and browse thru the DLL's namespace and
> look at its objects and functions.
>
> Is there a way to do this programmatically? That is, to point to a
> specific DLL and return its namespace as a string?
>

Imports System.Reflection

Dim asm As [Assembly] = [Assembly].LoadFile("filename.dll")

For Each t As System.Type In asm.GetTypes()
    MsgBox(t.Name)
Next

This should give you a push in the right direction.
Author
17 Aug 2006 7:31 PM
jwgoerlich
Excellent! Much obliged.


Chris Dunaway wrote:

Show quoteHide quote
> Imports System.Reflection
>
> Dim asm As [Assembly] = [Assembly].LoadFile("filename.dll")
>
> For Each t As System.Type In asm.GetTypes()
>     MsgBox(t.Name)
> Next
Author
18 Aug 2006 12:57 AM
GhostInAK
Hello Chris,

In addition to Chris's comments... DLLs do not have a namespace.  An assembly
can participate in one or more namespaces.  However a single namespace is
not constrained to a single assembly.

Also, I would suggest loading the assembly into it's own AppDomain.. AppDomains
can be unloaded.  Individual assembies can not.

-Boo

Show quoteHide quote
> jwgoerl***@gmail.com wrote:
>
>> In Visual Studio, one can add in a DLL as a reference. Then, using
>> Object Browser, one can open and browse thru the DLL's namespace and
>> look at its objects and functions.
>>
>> Is there a way to do this programmatically? That is, to point to a
>> specific DLL and return its namespace as a string?
>>
> Imports System.Reflection
>
> Dim asm As [Assembly] = [Assembly].LoadFile("filename.dll")
>
> For Each t As System.Type In asm.GetTypes()
> MsgBox(t.Name)
> Next
> This should give you a push in the right direction.
>
Author
18 Aug 2006 3:15 PM
jwgoerlich
Alright, I have [Assembly].LoadFile("filename.dll") working. Have not
yet figured out how to do the same in AppDomain, that will come.

Now, Assembly.LoadFile works for .Net Framework DLLs. But, this does
not work for other Win32 DLLs. Netapi32, for instance, which I know
contains the DsGetDcName command. When I try to load it as an Assembly,
I get:

System.BadImageFormatException: An attempt was made to load a program
with an incorrect format.

Any suggestions?

J Wolfgang Goerlich
Author
19 Aug 2006 2:26 AM
Mudhead
If maMatch.Groups("BigGroup1").Success Then
            value1 = maMatch.Groups("value1").ToString
            value2 = maMatch.Groups("value2").ToString
            Debug.WriteLine(value1)
            Debug.WriteLine(value2)
ElseIf maMatch.Groups("BigGroup2").Success Then
            value1 = maMatch.Groups("value1").ToString
            Debug.WriteLine(value1)
End If
Author
21 Aug 2006 3:39 PM
Chris Dunaway
Mudhead wrote:
> If maMatch.Groups("BigGroup1").Success Then
>             value1 = maMatch.Groups("value1").ToString
>             value2 = maMatch.Groups("value2").ToString
>             Debug.WriteLine(value1)
>             Debug.WriteLine(value2)
> ElseIf maMatch.Groups("BigGroup2").Success Then
>             value1 = maMatch.Groups("value1").ToString
>             Debug.WriteLine(value1)
> End If

Please don't hijack the thread to ask your own question.  This question
should be posted in its own thread.
Author
19 Aug 2006 2:40 AM
GhostInAK
Hello jwgoerl***@gmail.com,

Native Win32 dlls will not ever contain .Net namespaces.  In fact, there
is no concept of a namespace at all in native dlls. 

If you want to interrogate native dlls look at the Win32 functions: LoadLibrary,
FreeLibrary, and their cohorts.

-Boo

Show quoteHide quote
> Alright, I have [Assembly].LoadFile("filename.dll") working. Have not
> yet figured out how to do the same in AppDomain, that will come.
>
> Now, Assembly.LoadFile works for .Net Framework DLLs. But, this does
> not work for other Win32 DLLs. Netapi32, for instance, which I know
> contains the DsGetDcName command. When I try to load it as an
> Assembly, I get:
>
> System.BadImageFormatException: An attempt was made to load a program
> with an incorrect format.
>
> Any suggestions?
>
> J Wolfgang Goerlich
>