title: Why could i get an Unhandled exception Access violation writing in c++/CLI?
body: <p>I have been struggeling writing a solution excisting out of an c++ win32console and a c++ dll. i finally managed to get them talking without linker errors (so i am assuming both are fully managed c++/CLI projects) but when i run the console i get the following error.</p>
  
  <blockquote>
    <p>Unhandled exception at 0x03f71849 in
    Company.Pins.Bank.Win32Console.exe:
    0xC0000005: Access violation writing
    location 0x00000001.</p>
  </blockquote>
  
  <p>The console also shows the following</p>
  
  <blockquote>
    <p>Unhandled Exception:
    System.NullReferenceException: Object
    reference not set to an instance of an
    object. at wmain in c:...\win32console.cpp:line
    20 at _wmainCRTStartup()</p>
  </blockquote>
  
  <p>but i am assuming this is because of the unhandled exception.</p>
  
  <p>tracking down this error as well as i can the error occurs when doing the return in the below code block. (the method linked by the return seems to step through fine, just when returning it seems to go bad.) <strong>Just in case you hadn't noticed, i did not write the below code myself, it was generated by visual studio.</strong></p>
  
  <pre><code>#ifdef WPRFLAG
  int wmainCRTStartup(
  #else  /* WPRFLAG */
  int mainCRTStartup(
  #endif  /* WPRFLAG */
  
  #endif  /* _WINMAIN_ */
          void
          )
  {
          /*
           * The /GS security cookie must be initialized before any exception
           * handling targetting the current image is registered.  No function
           * using exception handling can be called in the current image until
           * after __security_init_cookie has been called.
           */
          __security_init_cookie();
  
          return __tmainCRTStartup();
  }
  
  #include "stdafx.h"
  #include "UInstruction.h"
  
  #define DllExport  __declspec(dllexport)
  #define DllImport  __declspec(dllimport)
  
  using namespace System;
  </code></pre>
  
  <p>edit: and the win32console.cpp code is below.</p>
  
  <pre><code>//int main(array&lt;System::String ^&gt; ^args)
  int _tmain(int argc, _TCHAR* argv[])
  {
      auto P2 = (TCHAR *)"3 Barrowstead";
      TCHAR* P3 = (TCHAR *)"3 Barrowstead";
      double* P1;
      P1[0] = 13;
  
      UserInstruction(P1, P2, P3);
  }
  </code></pre>