title: Using PyModule_AddIntConstant() in an extension
body: <p>I have seen <a href="https://stackoverflow.com/questions/23788140/adding-symbolic-constants-with-hex-values-to-python-extension-module">Adding symbolic constants with hex values to Python extension module</a> and I am trying to reproduce this effect:</p>
  
  <pre><code>#include &lt;Python.h&gt;
  #include &lt;Windows.h&gt;
  
  static PyObject * sys_shutdown(PyObject *self, PyObject *args) {
      int val;
  
      if (!PyArg_ParseTuple(args, "i", &amp;val))
          val = SHTDN_REASON_MINOR_OTHER; // Provide failsafe
  
      ExitWindowsEx(EWX_POWEROFF, val); // Shutdown
      return Py_BuildValue("");
  }
  
  static PyObject * sys_restart(PyObject *self, PyObject *args) {
      int val;
  
      if (!PyArg_ParseTuple(args, "i", &amp;val))
          val = SHTDN_REASON_MINOR_OTHER; // Provide failsafe
      ExitWindowsEx(EWX_REBOOT, val); // Restart
      return Py_BuildValue("");
  }
  
  static PyObject * sys_log_out(PyObject *self, PyObject *args) {
      int val;
  
      if (!PyArg_ParseTuple(args, "i", &amp;val))
          val = SHTDN_REASON_MINOR_OTHER; // Provide failsafe
  
      ExitWindowsEx(EWX_LOGOFF, val); // Log out
      return Py_BuildValue("");
  }
  
  static PyMethodDef localMethods[] = {
      {"shutdown", (PyCFunction)sys_shutdown, METH_VARARGS, "..."},
      {"restart", (PyCFunction)sys_restart, METH_VARARGS, "..."},
      {"log_out", (PyCFunction)sys_log_out, METH_VARARGS, "..."},
      {NULL, NULL, 0, NULL}
  };
  
  static struct PyModuleDef func = {
      PyModuleDef_HEAD_INIT,
      "utilities",
      "...",
      -1,
      localMethods,
  };
  
  PyMODINIT_FUNC PyInit_utilities(void) {
      PyObject *value;
  
      value = PyModule_New(&amp;func);
  
      PyModule_AddIntConstant(value, "DEFINED", AF_INET);
  
      return PyModule_Create(&amp;func);
  }
  </code></pre>
  
  <p>Setup Script:</p>
  
  <pre><code>from distutils.core import setup, Extension
  
  module = Extension(
      "utilities", 
      sources = ["main.c"],
          libraries = ["user32"]
  )
  
  setup (
      name = "Utilities",
      version = "1.0",
      ext_modules = [module])
  </code></pre>
  
  <p>Everything builds as expected, however I cannot use <code>DEFINED</code> in my extension:</p>
  
  <pre><code>import utilities
  for i in utilities.__dict__: print(i)
  utilities.DEFINED # AttributeError: module 'utilities' has no attribute 'DEFINED'
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>__name__
  __doc__
  __package__
  __loader__
  __spec__
  shutdown
  restart
  log_out
  __file__
  </code></pre>
  
  <p>I thought of returning <code>value</code> like so:</p>
  
  <pre><code>return PyModule_Create(&amp;value);
  </code></pre>
  
  <p>But that returns:</p>
  
  <blockquote>
    <p>LINK : fatal error LNK1104: cannot open file 'build\lib.win32-3.6\WinUtils.cp36-win32.pyd'
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\WDExpress\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\link.exe' failed with exit status 1104</p>
  </blockquote>
  
  <p>How can I add the <code>DEFINED</code> value to my extension (so that I can run <code>utilities.DEFINED</code>)?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>As mentioned in the answer below closing everything and trying again builds the extension successfully, however using <code>return PyModule_Create(&amp;value);</code> still crashes.</p>