HighTechTalks DotNet Forums  

Create DLL, import in main application

Dotnet FAQs microsoft.public.dotnet.faqs


Discuss Create DLL, import in main application in the Dotnet FAQs forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old   
CT
 
Posts: n/a

Default Re: Create DLL, import in main application - 09-23-2005 , 10:27 AM






Hmm, this works for me:

Dim assemblyToLoad As [Assembly]
' Load assembly from file
assemblyToLoad =
[Assembly].LoadFrom("D:\Projects\ClassLibrary\bin\ClassLibra ry.dll")

' Find the assembly module
Dim assemblyModule As [Module] =
assemblyToLoad.GetModule("ClassLibrary.dll")
' Find the Module type.
Dim moduleType As Type = _
assemblyModule.GetType("ClassLibrary.Module1")

' Get the public Company constant
Dim PublicField As FieldInfo
PublicField = moduleType.GetField("Company")
MsgBox(PublicField.Name.ToString)
MsgBox(PublicField.GetValue(PublicField).ToString)


--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"Andy" <andy.mail (AT) zwickau-net (DOT) de> wrote

Quote:
ThatŽs what iŽve tried but it ends up with an exception that the object
type cant be converted to the target type.
Displaying the name of the constant is no problem...

My code in the module:
Public Const Company As String = "TestCompany"

My code in the main application:
Dim PublicField As FieldInfo
PublicField = FormType.GetField("Company")
MsgBox(PublicField.Name.ToString) <- that works perfectly,
displaying "Company"
MsgBox(PublicField.GetValue(PublicField).ToString) <- no way :-(


Any idea?

Thanks,
Andy


CT wrote:
This is one way:

fi.GetValue(fi).ToString

Feel free to use a conversion function instead of the ToString method,
depedning on the type of constant you have, i.e. CInt for and Integer
etc:

Dim x As Integer = CInt(fi.GetValue(fi))




Reply With Quote
  #12  
Old   
Andy
 
Posts: n/a

Default Re: Create DLL, import in main application - 09-23-2005 , 10:56 AM






No way, it doesn't want to work here...
Maybe you can send a copy of the main project and the library project to
andy.mail (AT) zwickau-net (DOT) de?

Or can I call a function from the module library, which throws the
variables i would like to have?

Thank you,
Andy


CT wrote:
Quote:
Hmm, this works for me:

Dim assemblyToLoad As [Assembly]
' Load assembly from file
assemblyToLoad =
[Assembly].LoadFrom("D:\Projects\ClassLibrary\bin\ClassLibra ry.dll")

' Find the assembly module
Dim assemblyModule As [Module] =
assemblyToLoad.GetModule("ClassLibrary.dll")
' Find the Module type.
Dim moduleType As Type = _
assemblyModule.GetType("ClassLibrary.Module1")

' Get the public Company constant
Dim PublicField As FieldInfo
PublicField = moduleType.GetField("Company")
MsgBox(PublicField.Name.ToString)
MsgBox(PublicField.GetValue(PublicField).ToString)



Reply With Quote
  #13  
Old   
Andy
 
Posts: n/a

Default Re: Create DLL, import in main application - 09-23-2005 , 11:21 AM



Oh no, my fault! I handled the wrong dll file, now it works.

Thanks for all your patience, Carsten!

I hope youŽll have a very nice and relaxed weekend!

Best regards and thanks again,
Andy


Andy wrote:
Quote:
No way, it doesn't want to work here...
Maybe you can send a copy of the main project and the library project to
andy.mail (AT) zwickau-net (DOT) de?

Or can I call a function from the module library, which throws the
variables i would like to have?

Thank you,
Andy


CT wrote:
Hmm, this works for me:

Dim assemblyToLoad As [Assembly]
' Load assembly from file
assemblyToLoad =
[Assembly].LoadFrom("D:\Projects\ClassLibrary\bin\ClassLibra ry.dll")

' Find the assembly module
Dim assemblyModule As [Module] =
assemblyToLoad.GetModule("ClassLibrary.dll")
' Find the Module type.
Dim moduleType As Type = _
assemblyModule.GetType("ClassLibrary.Module1")

' Get the public Company constant
Dim PublicField As FieldInfo
PublicField = moduleType.GetField("Company")
MsgBox(PublicField.Name.ToString)
MsgBox(PublicField.GetValue(PublicField).ToString)



Reply With Quote
  #14  
Old   
CT
 
Posts: n/a

Default Re: Create DLL, import in main application - 09-23-2005 , 11:28 AM



Quote:
Oh no, my fault! I handled the wrong dll file, now it works.
One of those days, eh? ;-)

Enjoy the weekend.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"Andy" <andy.mail (AT) zwickau-net (DOT) de> wrote

Quote:
Oh no, my fault! I handled the wrong dll file, now it works.

Thanks for all your patience, Carsten!

I hope youŽll have a very nice and relaxed weekend!

Best regards and thanks again,
Andy


Andy wrote:
No way, it doesn't want to work here...
Maybe you can send a copy of the main project and the library project to
andy.mail (AT) zwickau-net (DOT) de?

Or can I call a function from the module library, which throws the
variables i would like to have?

Thank you,
Andy


CT wrote:
Hmm, this works for me:

Dim assemblyToLoad As [Assembly]
' Load assembly from file
assemblyToLoad =
[Assembly].LoadFrom("D:\Projects\ClassLibrary\bin\ClassLibra ry.dll")

' Find the assembly module
Dim assemblyModule As [Module] =
assemblyToLoad.GetModule("ClassLibrary.dll")
' Find the Module type.
Dim moduleType As Type = _
assemblyModule.GetType("ClassLibrary.Module1")

' Get the public Company constant
Dim PublicField As FieldInfo
PublicField = moduleType.GetField("Company")
MsgBox(PublicField.Name.ToString)
MsgBox(PublicField.GetValue(PublicField).ToString)





Reply With Quote
  #15  
Old   
Richard Grimes [MVP]
 
Posts: n/a

Default Re: Create DLL, import in main application - 10-15-2005 , 11:09 AM



Andy wrote:
Quote:
CT,

thanks for your very quick answer.
Is it possible to include forms in assemblies so the assembly can be a
complete program which is called from the main application?

Can you recommend an assembly tutorial to me?
You'll find one here :-)

http://www.grimes.demon.co.uk/workshops/fusionWS.htm

Richard
--
www.grimes.demon.co.uk




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.