title: Using ChangeDisplaySettingsEx in Delphi to set primary monitor
body: <p>I'm trying to use  ChangeDisplaySettingsEx in Delphi 7 to set a specific monitor as Primary.
  In Windows.pas, it is defined as </p>
  
  <pre><code>function ChangeDisplaySettingsEx(lpszDeviceName: PChar; var lpDevMode: TDeviceMode;
          wnd: HWND; dwFlags: DWORD; lParam: Pointer): Longint; stdcall;
  </code></pre>
  
  <p>In <a href="http://msdn.microsoft.com/en-us/library/dd183413(VS.85).aspx" rel="nofollow noreferrer">MSDN</a>, the documentation for ChangeDisplaySettingsEx has the following comment for lpDevMode: "If lpDevMode is NULL, all the values currently in the registry will be used for the display setting."</p>
  
  <p>My objective is to change the Primary monitor on a system with two active monitors, without changing anything else - resolution, bit depth, etc, should all remain the same. It seems like passing lpDevMode as null (nil) is the method that is provided to accomplish this.</p>
  
  <p>However, lpDevMode is defined as a packed record type (TDeviceMode), not a pointer type, in Delphi's Windows.pas. Apparently, the Delphi interface to the Windows API performs the translation to the pointers used by Windows API 'behind the scenes'.</p>
  
  <p>I tried calling it like this:</p>
  
  <pre><code>var
     alldevs : array[0..maxdev] of TDisplayDevice;
     lpDevMode : pointer;
  
  begin
     lpDevMode := nil;
     lparam := nil;
     my_hwnd := nil;
  
    {... snip....}
  
    with alldevs[NewPri] do
        ChangeDisplaySettingsEx(devicename,TDeviceMode(lpDevMode),my_hwnd,CDS_SET_PRIMARY,lparam);
  </code></pre>
  
  <p>That gives me an invalid typecast error on "TDeviceMode(lpDevMode)". How can I pass a null pointer to ChangeDisplaySettingsEx?  Or is there a better way to do this?</p>