• 0

C# DLL


Question

6 answers to this question

Recommended Posts

  • 0
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?

normally we just add a reference to the dll so we can start using the codes from it.. u can do that from solution explorer right click the project > add reference

Link to comment
https://www.neowin.net/forum/topic/704468-c-dll/#findComment-590208254
Share on other sites

  • 0
normally we just add a reference to the dll so we can start using the codes from it.. u can do that from solution explorer right click the project > add reference

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?

first_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:

objects.jpg

So now to look closer at the DLL source code.Could there be a problem in the fact that the constructor ( private NookieBookieDoopieDoo() ) is

defined as a privvate? Could there be a problem that the methods are static?

It looks something like this:

namespace BladaFlabaDab
{

	public class NookieBookieDoopieDoo
	{

		private static readonly string SomethingYouDoNotNeedToKnow = @"SLAMADAMNADDORK";

		private NookieBookieDoopieDoo()
		{
		}



		public static void Send(string to, string subject, string body)
		{
			.
			.
			.
		}

		public static void Send(string to, string replyTo, string subject, string body)
		{
			.
			.
			.
		}

		private static void InitializeClient()
		{
			.
			.
			.
		}
	}
}

Could there be a problem in the fact that the constructor ( private NookieBookieDoopieDoo() ) is

defined as a privvate? Could there be a problem that the methods are static?

Link to comment
https://www.neowin.net/forum/topic/704468-c-dll/#findComment-590211424
Share on other sites

  • 0

The static keyword is used to mark a method/property/type as usuable without instantiation. So basically, I can make operations of a type available without having to declare and create a type:

public class MyTestClass
{
	public static void MyStaticOperation()
	{

	}

	public void MyInstanceOperation()
	{

	}
}

MyTestClass.MyStaticOperation(); // <- works, calling the operation without declaring an instance of MyTestClass.
MyTestClass.MyInstanceOperation(); // <- won't work, because we need to call MyInstanceOperation from an instance of MyTestClass.
MyTestClass instance = new MyTestClass();
instance.MyInstanceOperation(); // <- works, calling the operation from the instance.

The class you are using as a private constructor, so its likely that it will always be used in a static fashion, so really the entire class should be labelled as static.

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

All objects within the .NET Framework inherit from System.Object. This is an implicit inheritance because you have not expressed an explicit inheritance, e.g.:

public class MyTestClass : MyBaseClass
{
	// This class is explicitly inheriting from MyBaseClass
}

public class MyTestClass
{
	// This class is implicitly inheriting from System.Object
}

Those operations you see "Equals", "GetHashCode", "GetType" and "ToString" are implemented by the System.Object type, and become available to any subclass (which would be every object in the .NET Framework).

Hope that clears some stuff up for you.

Link to comment
https://www.neowin.net/forum/topic/704468-c-dll/#findComment-590212716
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • The auto industry really needs to update it's terminology so a software update isn't called a recall.
    • Anybody that thinks flying cars were possible are idiots. Everyone would basically need a pilot licence, can you imagine how insane and dangerous that would be, people can barely handle driving on land safely right now.
    • Microsoft Edge 149.0.4022.80 by Razvan Serea Microsoft Edge is a super fast and secure web browser from Microsoft. It works on almost any device, including PCs, iPhones and Androids. It keeps you safe online, protects your privacy, and lets you browse the web quickly. You can even use it on all your devices and keep your browsing history and favorites synced up. Built on the same technology as Chrome, Microsoft Edge has additional built-in features like Startup boost and Sleeping tabs, which boost your browsing experience with world class performance and speed that are optimized to work best with Windows. Microsoft Edge security and privacy features such as Microsoft Defender SmartScreen, Password Monitor, InPrivate search, and Kids Mode help keep you and your loved ones protected and secure online. Microsoft Edge has features to keep both you and your family protected. Enable content filters and access activity reports with your Microsoft Family Safety account and experience a kid-friendly web with Kids Mode. The new Microsoft Edge is now compatible with your favorite extensions, so it’s easy to personalize your browsing experience. Microsoft Edge 149.0.4022.80 changelog: Fixes Fixed an issue that prevented QR code generation from working. Feature updates Intune MAM Protected Downloads. The protected downloads feature for Intune MAM will now save downloaded files to the Documents > Microsoft Edge > Downloads folder in OneDrive. Extensions monitoring in the Edge management service. The Microsoft Edge management service now allows admins to gain visibility into extensions installed across their managed users. From the extensions monitoring page, admins can see which extensions have been installed as well as manage user requests for blocked extensions. For more information, see Microsoft Edge Extensions Monitoring. Validate Edge builds early with enterprise preview. Enterprise preview provides a simpler way for admins to flight pre-release Edge builds to their users. To reduce friction and bolster usage, users will receive pre-release builds directly inside of their Stable Edge application. Admins can allow users to easily opt-out of the preview experience, using built-in rollback to switch between their pre-release and stable channels with ease. Microsoft 365 admin center users can configure the feature, view their flighting population, and receive personalized recommendations all in one place. For more information, see Get started with Enterprise Preview in Microsoft Edge. Download: Microsoft Edge (64-bit) | 193.0 MB (Freeware) Download: Microsoft Edge (32-bit) | 170.0 MB Download: Microsoft Edge (ARM64) | 188.0 MB View: Microsoft Edge Website | Release History Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • The machines are starting to fight back any way they can.
    • No news articles about the Arch Linux repo being majorly infected with malware?!?
  • Recent Achievements

    • Week One Done
      Eurosoft10 earned a badge
      Week One Done
    • One Month Later
      Eurosoft10 earned a badge
      One Month Later
    • One Year In
      Skeet Campbell earned a badge
      One Year In
    • One Month Later
      Sharbel earned a badge
      One Month Later
    • First Post
      BizSAR earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      599
    2. 2
      +Edouard
      190
    3. 3
      PsYcHoKiLLa
      79
    4. 4
      Michael Scrip
      77
    5. 5
      Steven P.
      69
  • Tell a friend

    Love Neowin? Tell a friend!