calling a function in a DLL from an EXE

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I create a WinApp (EXE) and a ClassLibrary (DLL), how do I call a class
'say' that displays a WinForm in the ClassLibrary from the WinApp?
TIA
 
If you are looking for a higher-level answer than I have given you, please let me know.

1. Create a WinForms app (EXE) and add a reference to the class library (DLL) if your using VS.NET.
If your not using VS.NET, just build your EXE with a compiler switch that references your DLL

2. To invoke a method in the DLL you have a few options:

A. Create a class in the DLL that has a static method
B. Create a class in the DLL that has an instance method, and create an instance of the class from your EXE code

Here's an example in C# of using a static method:

/// WinForms code:

using DLLNamespace;

public namespace EXENamespace
{
public class EXEClass
{
static void Main() // app entry point
{
DLLClass.ShowWindow();
}
}
}

// Class Library Code:

using System.Windows.Forms; // this is a reference to a namespace found in a class library of the same name

public namespace DLLNamespace
{
public class DLLClass
{
public static void ShowWindow() // marked as 'static' so that you don't have to create a 'DLLClass' instance
{
MessageBox.Show("Here's a window, popped-up using code written in a class library");
}
}
}
 
Thank you - that is exactly what I was asking - It was the adding a reference
that I missed
Thanks
Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top