writing functions in dll (newbie)

G

Guest

I have a task to write winform application while writing the functions that
return information, in a dll - for example opening a file. can someone please
give me an example for function that opens a file (openFileDialog) that will
be written in a dll file?

Thanks a lot
 
H

Herfried K. Wagner [MVP]

orit said:
I have a task to write winform application while writing the functions that
return information, in a dll - for example opening a file. can someone
please
give me an example for function that opens a file (openFileDialog) that
will
be written in a dll file?

Add a reference to "System.Windows.Forms.dll". Very basic sample code:

\\\
Imports System.Windows.Forms
..
..
..
Public Function OpenFile() As String
Dim o As New OpenFileDialog()
If o.ShowDialog = DialogResult.OK Then
OpenFile = o.FileName
End If
o.Dispose()
Return OpenFile
End Function
///
 
G

Guest

Thanks
I still do not completely understand the concept of how to write a general
function in a dll.
the truth is that I write on c# (sorry for not noticing before). can you
please give me the example in c# (with hope that it will be more clear for
me...)

Thanks a lot
 
H

Herfried K. Wagner [MVP]

orit said:
I still do not completely understand the concept of how to write a general
function in a dll.
the truth is that I write on c# (sorry for not noticing before). can you
please give me the example in c# (with hope that it will be more clear for
me...)

\\\
public string OpenFile()
{
string retval = null;
using (OpenFileDialog o = new OpenFileDialog())
{
if (o.ShowDialog() == DialogResult.OK)
retval = o.FileName;
}
return retval;
}
///

You can add the code above to a class file, then compile the class library
project and use the resulting DLL in other projects.
 
G

Guest

Thanks a lot.

The OpenFileDialog class requires the namespace System.Windows.Forms . The
dll class that I created doesn't know this namespace. how does it suppose to
be?

Thanks again
 
H

Herfried K. Wagner [MVP]

orit said:
The OpenFileDialog class requires the namespace System.Windows.Forms . The
dll class that I created doesn't know this namespace. how does it suppose
to
be?

Add a reference to "System.Windows.Forms.dll" to your class library project
and import the 'System.Windows.Forms' namespace.
 
G

Guest

Perfect, didn't know that technique.

Thanks

Herfried K. Wagner said:
Add a reference to "System.Windows.Forms.dll" to your class library project
and import the 'System.Windows.Forms' namespace.
 

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

Top