Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2005
This is the forum to discuss the Wrox book Beginning Visual C# 2005 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White; ISBN: 9780764578472
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2008, 04:31 PM
Friend of Wrox
Points: 660, Level: 9
Points: 660, Level: 9 Points: 660, Level: 9 Points: 660, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2005
Location: St. Louis, , .
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Default C# DLL

After someone creates a DLL in C# using the Microsoft Visual development environment, how would another programmer take that code, make a new project that includes the DLL's source and make a GUI that uses the DLL'S API?

 
Old November 30th, 2008, 10:26 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

To be clear the second developers project would not contain the source of the DLL, only the DLL itself. To utilize this DLL in the project the developer would right click on the project and select Add Reference and then navigate to the location to the DLL.

Once the reference is added they could do something like
Code:
using SuperCoolDLL;
namespace Foo
{
   public class Boo
   {
     private void SomeMethod()
     {
       SuperCoolDLLNamespace.SuperCoolDLLClass b = new SuperCoolDLLNamespace.SuperCoolDLLClass();
       b.DoSomething();
     }
   }
}
I should point out, unless there is a naming conflict between this third party assembly and the .NET Framework, you will not need to reference the class by Namespace.Class as I did above, you can simply reference the class. (If you do have a naming conflict you will need to fully qualify the class otherwise you will get a '<className> is ambiguous...' error)

Lastly, the using statement should contain the name of the namespace(s) within the DLL that you wish to use and not the name of the physical DLL.


hth.
-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old December 1st, 2008, 07:39 PM
Friend of Wrox
Points: 660, Level: 9
Points: 660, Level: 9 Points: 660, Level: 9 Points: 660, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2005
Location: St. Louis, , .
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well, I have access to the source for the DLL code as well as the project file.

I have done a few things. I have created a console app to use as the front-end to the project. Then I have added the DLL as a reference like this:

1) In the Solution Explorer right-click "References" and select "Add Reference ...".

2) Select the "Browse" tab.

3) Navigate to the DLL and select it.

4) Add the appropriate using directive to the code file(s) where you want to use the DLL.


I have also found that I can add the Project that the DLL was made in into my new Solution file.

I have included the namespace of the DLL in the "using" section of my code.

And the intelligent type I am using recognizes this class when I declare it in my code.

But it does not seem to recognize all the methods (api's) of the class.

What am I doing wrong?

http://i67.photobucket.com/albums/h2...st_problem.jpg

Strangely, "Equals", "GetHashCode", "GetType" and "ToString" are not seen in the DLL's source code for available methods for this class.

Also, I know that if you double click on the added reference, an Object Explorer should come up showing the available methods. This is not what happens:

http://i67.photobucket.com/albums/h2...no/objects.jpg

 
Old December 1st, 2008, 08:13 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

How are the methods defined? Like this:

public static void MethodName() {}

or this:

public void MethodName() {}

Only methods declared with the static keyword can be called like this:

Code:
TheClass.SomeMethod();
Otherwise you need to do something like this (these are known as instance methods):

Code:
TheClass class = new TheClass();
class.SomeMethod();
Methods declared with private or intern won't be accessible. In the case of the latter, this will only be true if the class within the DLL is in a different namespace then the calling class.

hth.
-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========




Similar Threads
Thread Thread Starter Forum Replies Last Post
convert unmanaged dll to managed dll nitesh kumar Visual C++ 2005 0 August 4th, 2008 04:53 AM
Install problems - VS 6.0 on XP SCRRUN.DLL PDM.DLL jeff4444 Visual C++ 0 December 6th, 2006 08:48 PM
How to convert .NET dll to COM dll used by VB 6.0 gvprashanth .NET Framework 1.x 0 December 4th, 2006 05:05 AM
The database dll crdb_oracle.dll could not be load Yeliz Crystal Reports 0 October 18th, 2006 08:12 AM
DLL & Excel - keep having to reset DLL reference! James Diamond Pro VB 6 2 May 25th, 2004 03:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.