|
-
Aug 15th, 2005, 02:01 AM
#1
DllImport question
There's one thing I'm not quite understanding. I'm looking at this page on MSDN and the DllImport syntax is confusing me:
[DllImport("KERNEL32.DLL", EntryPoint="MoveFileW", SetLastError=true,
CharSet=CharSet.Unicode, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern bool MoveFile(String src, String dst);
when they use EntryPoint, what does entryPoint refer to ? is it an application wide variable? why doesn't the app compile if I remove the "entrypoint=" part? it's a bit confusing
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Aug 15th, 2005, 02:22 AM
#2
Re: DllImport question
There is a MoveFile function and a MoveFileW function in that library, which is why it still compiles without it. MoveFileW is the Unicode implemetation. The EntryPoint is the actual library function that gets called, while the in the declaration is the name you will use in code. You only need to use EntryPoint if the declared name and the actual name are different.
-
Aug 15th, 2005, 02:35 AM
#3
Re: DllImport question
oh umm thanks
I'm not actually concerned about that particular function. What I don't understand is that it looks like "entryPoint" is a variable and a string is being assigned to it (look at the red part?). The other parameters are like this also.
I mean why cant I do dllImport ("kernel32.dll", "moveFileW", true, ...)
why is it assigning things to variables? I don't have those "variables" defined anywhere in my app either, but still it compiles
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Aug 15th, 2005, 03:24 AM
#4
Re: DllImport question
What you are doing is setting the EntryPoint field of the DllImportAttribute object being applied to the library function you are declaring. Have a look in the help or on MSDN for the DllImportAttribute class and its members.
-
Aug 15th, 2005, 09:32 AM
#5
Frenzied Member
Re: DllImport question
I think I get what you're asking, MrPolite. The reason it works like that is because DllImport is an attribute. Attributes have their own convention, so "EntrypPoint" has nothing to do with a variable in your code, but everything to do with the DllImportAttribute.
I'm not qualified to give you all the details, but it's explained quite well in the book Inside C#, Second Edition (and probably other places as well).
Just for kicks, check out the MSIL that's produced from your attribute:
Code:
.method public hidebysig static pinvokeimpl("KERNEL32.DLL" as "MoveFileW" nomangle unicode lasterr)
bool MoveFile(string src,
string dst) cil managed preservesig
{
}
You can see that the compiler uses the tags, which are defined by the attribute, to create the MSIL.
-
Aug 15th, 2005, 01:19 PM
#6
Re: DllImport question
aha interesting. thanks guys
I'm not so used to these attributes so they didn't make too much sense to me
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Aug 15th, 2005, 03:10 PM
#7
Re: DllImport question
Attributes are really weird. I need to read up on them. Its like half way between precompiler arguments and normal code.
I don't live here any more.
-
Aug 15th, 2005, 04:50 PM
#8
Re: DllImport question
aha interesting
do these stuff exist in C++ also (not the .NET version), or is the idea new to .NET?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Aug 15th, 2005, 10:08 PM
#9
Frenzied Member
Re: DllImport question
 Originally Posted by MrPolite
do these stuff exist in C++ also (not the .NET version), or is the idea new to .NET?
From what I've read (not from a deep understanding of many programming languages), attributes are a new feature in .NET. "Nothing short of groundbreaking" says one.
Again I'd have to refer you to Inside C#. "Chapter 6 Attributes" has the most excellent explanation of System.Attribute I've seen, better than you can find on MSDN.
If you don't want to buy the book, at least get a latte and read chapter 6 
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|