Mr Deed
Mr Deed

Reputation: 1

identify which application is calling a DLL

I have a DLL (vb.net) which is used by several applications.

I have referenced the DLL in several .net applications (using visual studio 2015).

I need to identify which application is invoking functions.

ex:

Public Sub xpto ()

if (application A) then

end if

If (application B) then

end if


End Sub

How can I do this in a dll?

Upvotes: 0

Views: 941

Answers (2)

Kzryzstof
Kzryzstof

Reputation: 8402

I would use Assembly.GetEntryAssembly() instead of GetCallingAssembly() as suggested.

This call will help identify you the actual process running calling your library instead of the library immediately calling your assembly.

Gets the process executable in the default application domain. In other application domains, this is the first executable that was executed by ExecuteAssembly(String).

Applied to your scenario, you would have something like this:

Public Sub xpto ()

' Grabs the entry assembly.
Dim entryAssembly as Assembly = Assembly.GetEntryAssembly()

' Grabs its name
Dim entryAssemblyName as AssemblyName = entryAssembly.GetName()

    If (entryAssemblyName.Name == ApplicationA) Then

    End If

    If (entryAssemblyName.Name == ApplicationB) Then

    End If

End Sub

Upvotes: 0

Blindy
Blindy

Reputation: 67524

You can use Assembly.GetCallingAssembly() to get the first other assembly calling your function.

Upvotes: 1

Related Questions