Using GetOpenFileName in Dev C++, VS
<p>I am fairly new to programming and compilers. I had a 1 year C++ class in university. Last month I started a project where I wanted to automate some processes for work. The program takes a phone directory and then creates .cfg files from it. Nothing very advanced, mostly reading, storing and writing data.</p>

<p>I made my project using Dev C++ IDE. It works fine and it is simple to use for a beginner like me. Lately I was trying to use a Visual C++ function called GetOpenFileName. I got an example from the internet but it doesn't compile in Dev C++ .... Here is the example : </p>

<pre><code>#include "stdafx.h"
#include &lt;windows.h&gt;
#include &lt;Commdlg.h&gt;
// 
// Gobal Variables and declarations.
// 
OPENFILENAME ofn ;
// a another memory buffer to contain the file name
char szFile[100] ;
int WINAPI WinMain( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nCmdShow )
{

    // open a file name
    ZeroMemory( &amp;ofn , sizeof( ofn));
    ofn.lStructSize = sizeof ( ofn );
    ofn.hwndOwner = NULL  ;
    ofn.lpstrFile = szFile ;
    ofn.lpstrFile[0] = '\0';
    ofn.nMaxFile = sizeof( szFile );
    ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
    ofn.nFilterIndex =1;
    ofn.lpstrFileTitle = NULL ;
    ofn.nMaxFileTitle = 0 ;
    ofn.lpstrInitialDir=NULL ;
    ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;
    GetOpenFileName( &amp;ofn );

    // Now simpley display the file name 
    MessageBox ( NULL , ofn.lpstrFile , "File Name" , MB_OK);
    return 0;
}
</code></pre>

<p>I understand this is VC++ and I am coding in C++, my question is : is it possible to make it work in Dev C++ and how ?</p>

<p>I get the following error : </p>

<blockquote>
  <p>C:\Users\Gabriel\Documents\Programs\Test\main.o   main.cpp:(.text+0xb4):
  undefined reference to `__imp_GetOpenFileNameA'</p>
</blockquote>

<p>I tried to install another IDE (Microsoft Visual Studio 2015 with the C++ package). In VS, my code won't compile at all (but it compiles fine in Dev C++). I get a load of errors:</p>

<blockquote>
  <p>2015\projects\consoleapplication1\consoleapplication1\consol‌​eapplication1.cpp(23‌​):
  error C2440: '=': cannot convert from 'char [100]' to 'LPWSTR' 1>
  c:\users\gabriel\documents\visual studio
  2015\projects\consoleapplication1\consoleapplication1\consol‌​eapplication1.cpp(23‌​):
  note: Types pointed to are unrelated; conversion requires
  reinterpret_cast, C-style cast or function-style cast</p>
</blockquote>

<p>There is something I don't get...  Why my code doesn't compile in VS but it does in Dev C++ ? I heard that the VS compiler is "out of date". Any way to update it?</p>

<p>Or is there any way to use VC++ in Dev C++ ?</p>