Results 1 to 5 of 5

Thread: [RESOLVED] Getting Started with MSDN

  1. #1

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Resolved [RESOLVED] Getting Started with MSDN

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting Started with MSDN

    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:
    Code:
    [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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: Getting Started with MSDN

    I didn't realize it was simply showing this:

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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting Started with MSDN

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: Getting Started with MSDN

    Thank you so much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width