|
You last visited: Today at 09:53
Advertisement
Dll Import
Discussion on Dll Import within the CO2 Programming forum part of the Conquer Online 2 category.
01/24/2014, 19:10
|
#1
|
elite*gold: 0
Join Date: Aug 2007
Posts: 1,525
Received Thanks: 230
|
Dll Import
well i've been studying C# till Now but i couldnt understand this part ... Why would i need to use External Dll Files ? and How do i know that im using the Right Dll ? i've Seen many Example of ppls using User32.Dll Or Kernel.Dll .. what are these Dlls Provide ? and i've seen Alot Or Parameters being used when these Dlls are used in the Project ..so i need Help in This
Regards
shadowman123
|
|
|
01/24/2014, 19:36
|
#2
|
elite*gold: 0
Join Date: Sep 2006
Posts: 774
Received Thanks: 8,580
|
|
|
|
01/24/2014, 19:39
|
#3
|
elite*gold: 20
Join Date: Sep 2007
Posts: 1,767
Received Thanks: 1,746
|
It's because being that C# runs on the CLR it doesn't have full access to certain areas. Even then sometimes it's just easier to use an existing method written within the operating system. The parameters are used to control how the method is loaded generally.
Here's an example (from a program I'm working atm):
Code:
#region Field Region
//Declare variables
long
_ticksPerSecond = 0,
_previousElapsedTime = 0;
#endregion
#region Properties
/// <summary>
/// Gets the Elapsed Time of the Precise Timer.
/// </summary>
public double ElapsedTime
{
get
{
long time = 0;
double elapsedTime;
QueryPerformanceCounter(ref time);
elapsedTime = (double)(time - _previousElapsedTime) / (double)_ticksPerSecond;
_previousElapsedTime = time;
return elapsedTime;
}
}
#endregion
#region Constructor
/// <summary>
/// Creates a new precise timer.
/// </summary>
public PreciseTimer()
{
QueryPerformanceFrequency(ref _ticksPerSecond);
GetElapsedTime(); // Get rid of first rubbish result
}
#endregion
#region Imported Methods
[SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency);
[SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceCounter(ref long PerformanceCount);
#endregion
In this example it uses the two methods within the kernel32.dll for windows to get an extremely accurate timer. You could try to use "DateTime" but this could return incorrect results between updates and would result in slower processing. However using this method allows for a great handle for an infinite loop like that found in games or graphics based software.
To find these kinds you could read them all found on msdn, however normally you may just come across more methods through experience and searching for solutions.
Lastly another reason could be that someone wrote the majority of code you need in c++ instead of c#. However it would be faster for you to import the methods instead of creating them in c# again.
MSDN Sources:

|
|
|
01/24/2014, 20:06
|
#4
|
elite*gold: 0
Join Date: Jan 2008
Posts: 1,444
Received Thanks: 1,176
|
Quote:
Originally Posted by shadowman123
well i've been studying C# till Now but i couldnt understand this part ... Why would i need to use External Dll Files ? and How do i know that im using the Right Dll ? i've Seen many Example of ppls using User32.Dll Or Kernel.Dll .. what are these Dlls Provide ? and i've seen Alot Or Parameters being used when these Dlls are used in the Project ..so i need Help in This
Regards
shadowman123
|
DLL files are libraries. Using them allow you to use code that somebody written (like System.IO is a DLL). You can use directly .NET DLLs as you do with standard namespaces, but for native DLLs (C/C++), you must convert the CLR data to native (with marshalling). It can be useful for using unported WinAPI functions (User32, Kernel, etc) or to use a C++ library instead of reimplementing everything in .NET.
On MSDN website, the DLL is specified for each WinAPI function. Else, you must know the exported symbols to define the import table in C#.
Note that you'll have an overhead when using native DLLs as you must marshal everything.
|
|
|
01/24/2014, 20:13
|
#5
|
elite*gold: 0
Join Date: Aug 2007
Posts: 1,525
Received Thanks: 230
|
Quote:
Originally Posted by phize
|
First of All thx for your Answer .i've Searched Alot of Internet and Found Alot of Infos about that but couldnt understand them including the Explaination in the link you mentioned Above
Quote:
Originally Posted by funhacker
It's because being that C# runs on the CLR it doesn't have full access to certain areas. Even then sometimes it's just easier to use an existing method written within the operating system. The parameters are used to control how the method is loaded generally.
Here's an example (from a program I'm working atm):
Code:
#region Field Region
//Declare variables
long
_ticksPerSecond = 0,
_previousElapsedTime = 0;
#endregion
#region Properties
/// <summary>
/// Gets the Elapsed Time of the Precise Timer.
/// </summary>
public double ElapsedTime
{
get
{
long time = 0;
double elapsedTime;
QueryPerformanceCounter(ref time);
elapsedTime = (double)(time - _previousElapsedTime) / (double)_ticksPerSecond;
_previousElapsedTime = time;
return elapsedTime;
}
}
#endregion
#region Constructor
/// <summary>
/// Creates a new precise timer.
/// </summary>
public PreciseTimer()
{
QueryPerformanceFrequency(ref _ticksPerSecond);
GetElapsedTime(); // Get rid of first rubbish result
}
#endregion
#region Imported Methods
[SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency);
[SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceCounter(ref long PerformanceCount);
#endregion
In this example it uses the two methods within the kernel32.dll for windows to get an extremely accurate timer. You could try to use "DateTime" but this could return incorrect results between updates and would result in slower processing. However using this method allows for a great handle for an infinite loop like that found in games or graphics based software.
To find these kinds you could read them all found on msdn, however normally you may just come across more methods through experience and searching for solutions.
Lastly another reason could be that someone wrote the majority of code you need in c++ instead of c#. However it would be faster for you to import the methods instead of creating them in c# again.
MSDN Sources:
 
|
i understood What you Posted .. but i got Question Im a Beginner in Dll Import and all infos i Know are the Infos you mentioned Above so in order to use Specific Dll file i need to know each one of the Dlls Functions so do u got any Sites that include These Dlls Functions Explaination ??? and one more Questions i've Noticed that most of the Function inside these Dlls are written in C++ .. Y is that ? is C++ Better than C# so they used it instead of C# Or what ? Thx For your Answer
Quote:
Originally Posted by CptSky
DLL files are libraries. Using them allow you to use code that somebody written (like System.IO is a DLL). You can use directly .NET DLLs as you do with standard namespaces, but for native DLLs (C/C++), you must convert the CLR data to native (with marshalling). It can be useful for using unported WinAPI functions (User32, Kernel, etc) or to use a C++ library instead of reimplementing everything in .NET.
On MSDN website, the DLL is specified for each WinAPI function. Else, you must know the exported symbols to define the import table in C#.
Note that you'll have an overhead when using native DLLs as you must marshal everything.
|
Excuse me but whats meant by Marchaling ?
|
|
|
01/24/2014, 20:22
|
#6
|
elite*gold: 20
Join Date: Sep 2007
Posts: 1,767
Received Thanks: 1,746
|
Quote:
Originally Posted by shadowman123
First of All thx for your Answer .i've Searched Alot of Internet and Found Alot of Infos about that but couldnt understand them including the Explaination in the link you mentioned Above
i understood What you Posted .. but i got Question Im a Beginner in Dll Import and all infos i Know are the Infos you mentioned Above so in order to use Specific Dll file i need to know each one of the Dlls Functions so do u got any Sites that include These Dlls Functions Explaination ??? and one more Questions i've Noticed that most of the Function inside these Dlls are written in C++ .. Y is that ? is C++ Better than C# so they used it instead of C# Or what ? Thx For your Answer
Excuse me but whats meant by Marchaling ?
|
The best place for you to find all the functions would be to find them by the use you need them for  .
The reason for so much code being written in c++ is efficiency. C# is just like Java it runs on a virtual machine named "CLR". This takes the compiled code, and interprets it for the machine it is on.
C++ however is compiled to a specific CPU architecture and will only work on that specific type of CPU. However if a c++ program is written with the aim of compatibility it will be able to compile on many types of CPUs.
This is because the executable is compiled to machine code (ASM). C# is compiled to CLR instructions which are translated to ASM. Which makes it that bit slower than c++.
|
|
|
01/25/2014, 02:37
|
#7
|
elite*gold: 0
Join Date: Aug 2007
Posts: 1,525
Received Thanks: 230
|
Quote:
Originally Posted by funhacker
The best place for you to find all the functions would be to find them by the use you need them for  .
The reason for so much code being written in c++ is efficiency. C# is just like Java it runs on a virtual machine named "CLR". This takes the compiled code, and interprets it for the machine it is on.
C++ however is compiled to a specific CPU architecture and will only work on that specific type of CPU. However if a c++ program is written with the aim of compatibility it will be able to compile on many types of CPUs.
This is because the executable is compiled to machine code (ASM). C# is compiled to CLR instructions which are translated to ASM. Which makes it that bit slower than c++.
|
Thx Guyz for your very useful and helpful Explaination ..it helped me Alot .. there were some stuffs that i didnt understand like CLR and Marshalling but after spending time on searching i understood alot ..Now i Completely understood everything related to this Part... All i need to do now is Implementing what i understood right now ..
|
|
|
01/25/2014, 13:56
|
#8
|
elite*gold: 0
Join Date: Sep 2013
Posts: 197
Received Thanks: 141
|
Quote:
Originally Posted by funhacker
In this example it uses the two methods within the kernel32.dll for windows to get an extremely accurate timer. You could try to use "DateTime" but this could return incorrect results between updates and would result in slower processing. However using this method allows for a great handle for an infinite loop like that found in games or graphics based software.
|
Kinda off topic, but you know there's a high precision timer in the System.Diagnostics namespace, right?
|
|
|
01/26/2014, 02:50
|
#9
|
elite*gold: 20
Join Date: Sep 2007
Posts: 1,767
Received Thanks: 1,746
|
Quote:
Originally Posted by SteveRambo
Kinda off topic, but you know there's a high precision timer in the System.Diagnostics namespace, right? 
|
Yeah, that's great for the use of multiple timers. However for a single one I would assume that the class would use a little more resources than the one I posted and be unnecessary as it's built using similar code.
|
|
|
01/26/2014, 12:19
|
#10
|
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
|
Add the overhead created by marshaling. Also, the current time is gotten through a simple OS interrupt, so as far as resources go this is a problem that isn`t worth optimizing.
|
|
|
01/26/2014, 13:21
|
#11
|
elite*gold: 0
Join Date: Sep 2013
Posts: 197
Received Thanks: 141
|
Quote:
Originally Posted by funhacker
Yeah, that's great for the use of multiple timers. However for a single one I would assume that the class would use a little more resources than the one I posted and be unnecessary as it's built using similar code.
|
Quote:
Originally Posted by KraHen
Add the overhead created by marshaling. Also, the current time is gotten through a simple OS interrupt, so as far as resources go this is a problem that isn`t worth optimizing.
|
Actually, the timestamp is read using just a single rdstc instruction.
|
|
|
01/28/2014, 00:23
|
#12
|
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
|
Thanks for the clarification on that one, although my point stays valid.
|
|
|
 |
Similar Threads
|
bfbc2 uk import
11/20/2010 - Main - 5 Replies
hi, ich überlege ob ich mir battlefield bad company 2 als uk import hole.
is ca. 30 € billiger. jetz weiß ich nur nich, ob ich mit meinen deutschen freunden spielen kann und ob ich die sprache auch auf deutsch stellen kann ;P.
hoffe der thread is hier richtig ^^
|
XBox 360 UK Import?
10/20/2010 - Consoles - 8 Replies
Hi habe bei amazon ne xbox gefunden is Uk import, nun is meine Frage was für Probleme können da in Deutschland entstehen AUßER ZOLL, z.b Live Registrierung usw?
|
import chrmgr
10/03/2010 - Metin2 Private Server - 2 Replies
Hi,
ich würde gerne wissen wo ich dieses "chrmgr" finden kann
er nimmt es ja irgentwo heer
Es steht in den .py datein aus den root.eix/epk
Gruß.
|
import?
09/29/2009 - General Coding - 8 Replies
Hi,
in dem Quellcode einer datei aus einem entpackten Spielclienten habe ich folgendes drinstehen (die punkkte sollen nur heisen das davor und danach noch was kommt)
...
import snd
import chat
import textTail
import snd
import net
|
Import
05/25/2006 - Off Topic - 4 Replies
Moin
Also,
Im internet werden öfters solche importhändler listen wie zb bei
www.importer-scout.de angeboten
Jetzt würde ich mich dafür interresieren ob jemand schonmal dafür bezahlt hat und
ob es sich lohnt etc
Oder villeicht wer einige importhändlerlisten aus china etc kennt wo man
möglichst billig produkte zum weiterverkauf herbekommt
Würd mich über eure meinungen freun
auch über PM
|
All times are GMT +1. The time now is 09:54.
|
|