DLL Problem
-
using System; namespace MyClassNameDLL { /// /// Summary description for Class1. /// public class MyClassName { public MyClassName() { // // TODO: Add constructor logic here // } public Hi() { szPassed = "Hi."; } } } MyClassName works as far as debugging, but Hi doesn't it says: Class, struc, or interface must have a return type What does that mean? -- modified at 20:06 Friday 10th February, 2006
-
using System; namespace MyClassNameDLL { /// /// Summary description for Class1. /// public class MyClassName { public MyClassName() { // // TODO: Add constructor logic here // } public Hi() { szPassed = "Hi."; } } } MyClassName works as far as debugging, but Hi doesn't it says: Class, struc, or interface must have a return type What does that mean? -- modified at 20:06 Friday 10th February, 2006
Your
public Hi()
is what it's complaining about. You haven't specified what the return type is, even if it's not supposed to have one (void
).using System;
namespace MyClassNameDLL
{
///
/// Summary description for Class1.
///
public class MyClassName
{
public MyClassName()
{
//
// TODO: Add constructor logic here
//
}
public void Hi()
{
string szPassed = "Hi.";
}
}
}RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Your
public Hi()
is what it's complaining about. You haven't specified what the return type is, even if it's not supposed to have one (void
).using System;
namespace MyClassNameDLL
{
///
/// Summary description for Class1.
///
public class MyClassName
{
public MyClassName()
{
//
// TODO: Add constructor logic here
//
}
public void Hi()
{
string szPassed = "Hi.";
}
}
}RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Ok, so I have a reference to the DLL file. How do I do the using statement? Right now it is: using MyClassNameDLL; What else do I need?
-
Ok, so I have a reference to the DLL file. How do I do the using statement? Right now it is: using MyClassNameDLL; What else do I need?
Add a Reference to the MyClassNameDLL PROJECT, not the .DLL file. Since you're still developing the .DLL, it'll make changes easier when you recompile the app that's using this DLL. Right-click the References folder, pick Add Reference. Click the Projects tab, then highlight your .DLL project (I'm assuming both projects are in the same solution!), then click OK. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Ok, so I have a reference to the DLL file. How do I do the using statement? Right now it is: using MyClassNameDLL; What else do I need?
If your using Visual Studio be sure to add a reference to it By right clicking the name of your project and selecting add reference in the solution explorer. Browse to your .dll and select it. if you have: using MYClassNameDLL; at the very top of your code You are now ready to use your .dll in your code. Hope this helps
-
If your using Visual Studio be sure to add a reference to it By right clicking the name of your project and selecting add reference in the solution explorer. Browse to your .dll and select it. if you have: using MYClassNameDLL; at the very top of your code You are now ready to use your .dll in your code. Hope this helps
When I want to use a function within the DLL how do I use it? Usually I do: Hi();
-
When I want to use a function within the DLL how do I use it? Usually I do: Hi();
It's looking like you REALLY need to pick up a book on C#. The questions you've asked in this thread are all beginning concepts in programming, let alone C#. GENERALLY, since you've imported the namespace your class sits in (the
using
statement at the top of the code), you can just create an instance of your class and call itsHi
method:MyClassName myClass = new MyClassName();
myClass.Hi();RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
It's looking like you REALLY need to pick up a book on C#. The questions you've asked in this thread are all beginning concepts in programming, let alone C#. GENERALLY, since you've imported the namespace your class sits in (the
using
statement at the top of the code), you can just create an instance of your class and call itsHi
method:MyClassName myClass = new MyClassName();
myClass.Hi();RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Two things: 1st: Although I don't take offense to you saying I don't know how to code, I have to say you are wrong. I do my time in coding with ASP.NET applications in which my employer require the code sit in a single .cs file. They don't want seperate .dlls or any other file except for files such as pictures. I am creating this program on my own to help me with a game I play. 2nd: I am having no problem getting to the functions on the DLL, I have done what you stated above, but usually when you use a DLL you don't end up having to do things like MyClass.MyFunctions. Thanks for the help.
-
Two things: 1st: Although I don't take offense to you saying I don't know how to code, I have to say you are wrong. I do my time in coding with ASP.NET applications in which my employer require the code sit in a single .cs file. They don't want seperate .dlls or any other file except for files such as pictures. I am creating this program on my own to help me with a game I play. 2nd: I am having no problem getting to the functions on the DLL, I have done what you stated above, but usually when you use a DLL you don't end up having to do things like MyClass.MyFunctions. Thanks for the help.
ExpertComing wrote:
I am having no problem getting to the functions on the DLL, I have done what you stated above, but usually when you use a DLL you don't end up having to do things like MyClass.MyFunctions.
You're thinking of the time when these were actually called "functions". In an OOP model, they're called "methods". There are different access levels for methods. The example I showed you is one where an instance of the host class must be created before you can call the method on that instance. Static methods don't require and instace, but you stil have to specify the class that is hosting them. You can either directly specify the host class, like
MyClassName.Hi();
, or, if you change theusing
statement tousing MYClassNameDLL.MyClassName;
, you can shorten the method call toHi();
. While it's easier to type, it leaves the source of the method a bit vague and makes your code harder to read.ExpertComing wrote:
Although I don't take offense to you saying I don't know how to code, I have to say you are wrong. I do my time in coding with ASP.NET applications
In what language? ASP.NET is just a web page generation technology. The concepts you're refering to are still very basic, Beginning C# - Week #1, concepts. I don't see how you could possible write an ASP.NET app in C# without knowing the things you're asking about already. I'm not here to insult you or ridicule your abilities. I'm just give you some advice based on the skill level of your question. If you are just starting out in C#, then you're best, fastest, method of learning this stuff is going to be a book. You'll get these questions answered far faster in those pages that you could in any forum. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
ExpertComing wrote:
I am having no problem getting to the functions on the DLL, I have done what you stated above, but usually when you use a DLL you don't end up having to do things like MyClass.MyFunctions.
You're thinking of the time when these were actually called "functions". In an OOP model, they're called "methods". There are different access levels for methods. The example I showed you is one where an instance of the host class must be created before you can call the method on that instance. Static methods don't require and instace, but you stil have to specify the class that is hosting them. You can either directly specify the host class, like
MyClassName.Hi();
, or, if you change theusing
statement tousing MYClassNameDLL.MyClassName;
, you can shorten the method call toHi();
. While it's easier to type, it leaves the source of the method a bit vague and makes your code harder to read.ExpertComing wrote:
Although I don't take offense to you saying I don't know how to code, I have to say you are wrong. I do my time in coding with ASP.NET applications
In what language? ASP.NET is just a web page generation technology. The concepts you're refering to are still very basic, Beginning C# - Week #1, concepts. I don't see how you could possible write an ASP.NET app in C# without knowing the things you're asking about already. I'm not here to insult you or ridicule your abilities. I'm just give you some advice based on the skill level of your question. If you are just starting out in C#, then you're best, fastest, method of learning this stuff is going to be a book. You'll get these questions answered far faster in those pages that you could in any forum. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Well, I would always have all my code in one class, it becomes a slight mess, but it was easy. I have 3 books, I'll read them, thanks for the help, and the advice. I was used to Visual Basic 5, before .NET. You are right about the functions verse methods thing, thanks.