I've been starting to worry about the details of software copyright. This brought up the question whether using source code from an official documentation, that is copyrighted as usual, is actually legal? If you for example want to work with Graphics APIs like OpenGL or DirectX, you're basically forced to see how you use these APIs and set things up. Yet the publishers of those API documentations do not put the how-to examples in public domain.

Lets for example consider the following snippet from a Win32 tutorial from Microsoft that shows you how to setup a window:

#ifndef UNICODE
#define UNICODE

#include <windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
    // Register the window class.
    const wchar_t CLASS_NAME[]  = L"Sample Window Class";
    WNDCLASS wc = { };

    wc.lpfnWndProc   = WindowProc;
    wc.hInstance     = hInstance;
    wc.lpszClassName = CLASS_NAME;


    // Create the window.

    HWND hwnd = CreateWindowEx(
        0,                              // Optional window styles.
        CLASS_NAME,                     // Window class
        L"Learn to Program Windows",    // Window text
        WS_OVERLAPPEDWINDOW,            // Window style

        // Size and position

        NULL,       // Parent window    
        NULL,       // Menu
        hInstance,  // Instance handle
        NULL        // Additional application data

    if (hwnd == NULL)
        return 0;

    ShowWindow(hwnd, nCmdShow);

    // Run the message loop.

    MSG msg = { };
    while (GetMessage(&msg, NULL, 0, 0))

    return 0;

    switch (uMsg)
    case WM_DESTROY:
        return 0;

    case WM_PAINT:
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);

            FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));

            EndPaint(hwnd, &ps);
        return 0;

    return DefWindowProc(hwnd, uMsg, wParam, lParam);

Microsoft's Terms of Use at the bottom of the page clearly state, that use is is limited to personal, non-commercial use. What now? Sure, I can change the code. But then its a derivative work. One idea to overcome this issue might be to have someone else read the documentation and write down the necessary API calls and then have someone else given only those notes figure out how to set everything up by just looking up the plain API calls like CreateWindowEx.

1 Answer 1


The example code explains a procedure or method of accomplishing a goal, in the process conveying certain ideas.

17 USC 102 (b) provides:

(b) In no case does copyright protection for an original work of authorship extend to any idea, procedure, process, system, method of operation, concept, principle, or discovery, regardless of the form in which it is described, explained, illustrated, or embodied in such work.

The laws of other countries are similar on this point. Making use of the procedure or method is not copyright infringement. Under US law, making use of the example code would probably be a fair use, whatever the license may say. But even if it were not held to be a fair use, writing code that is similar to implement the same procedure is not infringement, because there are only a limited number of ways to implement this procedure, and to protect all of them, would be to protect an idea, which copyright never does.

In general when there are only a few ways to express an idea, or implement a procedure, copyright cannot be used to protect any of them.

  • This issue went to the SCOTUS very recently. The justices did not understand the issue as well as this answer does but did vote that google copying the entire Java API was not copyright infringement. en.m.wikipedia.org/wiki/Google_LLC_v._Oracle_America,_Inc. Oct 10, 2021 at 22:13
  • 1
    @GeorgeWhite Google vs. Oracle is a bit different, though. In this case Google copied the public interface declarations, but they did not copy any of the implementing sourcecode. This question is about implementing sourcecode.
    – Philipp
    Oct 11, 2021 at 9:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .