PDA

Click to See Complete Forum and Search --> : [RESOLVED] Getting Started with MSDN


gjon
Sep 6th, 2007, 06:19 PM
Ok, bear with me. I am wanting to learn exactly this. How you find what you think you need to work with and how to work with it.

I wanted to work on a project that would motivate me to learn. What I thought would be a small project; to make a program that would allow the computer to shut down each night at a certain time. The hardest part seems to be finding what I need and knowing how to use it.

Ok, so here's what I believe to be a method in the MSDN Library concerning the shutting down of a windows computer system. It's at the page:
http://msdn2.microsoft.com/en-us/library/Aa376873.aspx

Now this is the methods(?) code:

BOOL WINAPI InitiateSystemShutdown(
LPTSTR lpMachineName,
LPTSTR lpMessage,
DWORD dwTimeout,
BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown
);

And below it tells what I believe these fields are for. I am confused as to what all this represents.

But how do you use it? How do you guys figure out what to do with this stuff? The MSDN Library seems like
some cryptic dictionary. This is nothing like how a book shows you how to code. The book gives you everything you need
and you just work with it.
My biggest struggle is the real life scenario where there is no book to follow. Finding what I need to work with and how
to begin using it.

This seems like the most complicated part. Yet most posts say, do a simple search and there's your answer.
Baffles me...

Thanks in advance for any explanations.

jmcilhinney
Sep 6th, 2007, 07:08 PM
That isn't the method's code. It's the method's signature. To use Windows API functions in C# code you have to declare a method with a matching signature using 'extern' key word. The extern key word tells the system that the actual function is exported from a compiled DLL and the signature tells the system where it is and how to call it. Note that the same external function can often be declared in several different ways in .NET code.

I suggest that you download the API Viewer and the API Guide. They will give you information about API functions as well as function signatures. The API Viewer can be set to provide C# signatures too. Here's what it produced for that function:[DllImport("advapi32.dll", EntryPoint="InitiateSystemShutdownA")]
static extern int InitiateSystemShutdown (
string lpMachineName,
string lpMessage,
int dwTimeout,
int bForceAppsClosed,
int bRebootAfterShutdown);You can also get the PInvoke.net VS add-in that will paste signatures straight into the IDE, although it can be a little flaky.

gjon
Sep 6th, 2007, 09:58 PM
I didn't realize it was simply showing this:

InitiateSystemShutdown( NULL, NULL, 0, TRUE, FALSE );

jmcilhinney
Sep 6th, 2007, 10:32 PM
The MSDN documentation for the the Windows API was written a long time ago for C++ developers. The documentation for the .NET Framework is much clearer, but there is no specific documentation for .NET developers calling Windows API functions. There is information in the .NET Framework documentation on the general principles of calling functions exported from unmanaged libraries. There is nothing on the use of specific functions in managed code, nor will there ever be. That's why there's a flourishing community dedicated to accessing the Windows API from managed code.

Using the MSDN library, Spy++, WinID, API Viewer, API Guide and PInvoke.net together you can get almost anything you need in this area. The API Guide shows you all documentation functions grouped by the type of functionality, which you can then cross-reference with the MSDN library to find the appropriate function(s) for the task at hand. PInvoke.net will give you more information and API Viewer will give you a signature in your chosen language. WinID and Spy++ will give you all the information you need on which windows to interact with and their properties, if you need that kind of information. Like everything, the more you use these tools in concert the better you get at using them. The API forum on this site is also a useful resource.

gjon
Sep 7th, 2007, 12:26 AM
Thank you so much.