C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2596
Number of posts: 5564

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Integrating a DLL into C# Posted by capitolc on 10 Oct 2006 at 9:45 AM
I need a starting point when using a .dll created using C++ within a C# Windows applicatiion. I'm using Visual Studio .NET 2003 and I copied the dll inside my new project.

I am concerned on how to link the dll to my project and code. I went to 'add reference' menu and located the dll to add, but I'm not for sure if I should use the NET tab or the COM tab. Does it matter? What's the difference?

Once added, the dll does show in the solution explorer under the reference node along with the defualt system/system.data/.window/window.form. BUT, once I to use the 'using' to declare my namespace along side the defualt 'system.windows.form', I get the error namespace name can not be found. What is my problem here?

Am I missing something in my process? How do I use a created dll within a C# project? How do I reference the functions inside the dll in the C# source code? If you can help and/or point me in the right driection, it will be greatly appreciated.



-=The Best Has Yet To Come=-
Report
Re: Integrating a DLL into C# Posted by NeonTiger2007 on 12 Oct 2006 at 6:17 AM
: I need a starting point when using a .dll created using C++ within a C# Windows applicatiion. I'm using Visual Studio .NET 2003 and I copied the dll inside my new project.
:
: I am concerned on how to link the dll to my project and code. I went to 'add reference' menu and located the dll to add, but I'm not for sure if I should use the NET tab or the COM tab. Does it matter? What's the difference?
:
: Once added, the dll does show in the solution explorer under the reference node along with the defualt system/system.data/.window/window.form. BUT, once I to use the 'using' to declare my namespace along side the defualt 'system.windows.form', I get the error namespace name can not be found. What is my problem here?
:
: Am I missing something in my process? How do I use a created dll within a C# project? How do I reference the functions inside the dll in the C# source code? If you can help and/or point me in the right driection, it will be greatly appreciated.
:
:
:
: -=The Best Has Yet To Come=-
:

Hi buddy:

Well, I only once linked a 'C++ made' Dll and I did it for using ports on XP.
Whithin the code of the main program I used this:

class Port{
[DllImport("Inpout32.dll", EntryPoint="Out32")]
public static extern void Output(byte bData, word wPort);
}

Explanation:
-----------
I was importing "Inpout32.dll" in order to use the function "Out32" which is inside the dll.
"public" made this function call public.
"static" means you don't have to declare an instance of the class Port
"extern" means you are declaring an extern function (inside the DLL)
"void" you already know...

Considering that, the paradigmatic declaration should be:

class NameOfTheClass{
[DllImport("YourDLL.dll",EntryPoint="FunctionInsideDLL")]
public static extern ReturnType AliasName(Type Param[,Type Param [..]])
};

public static Main(){
AliasName(...);
}

That's all...

Good luck and have fun with C# !!!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.