CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2010

    HANDLE and CreateFile Function

    I am trying to create a HANDLE to file location for opening and reading from that file. I have done this before in Borland Tools with success.

    I am using the free visual C++ 2008 express edition to accomplish the same thing. But, I am receiving an error:

    \form1.cpp(53) : error C2664: 'strcpy' : cannot convert parameter 2 from 'System::String ^' to 'const char *'
    No user-defined-conversion operator available, or
    Cannot convert a managed type to an unmanaged type
    .\form1.cpp(58) : error C2664: 'CreateFileW' : cannot convert parameter 1 from 'char [256]' to 'LPCWSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    Here is the code of the .h
    String ^mapFileLoc;
    private: System::Void MapBrowseButton_Click(System::Object^  sender, System::EventArgs^  e) {			
    	if( this->MapFileOpenDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
    				 mapFileLoc = this->MapFileOpenDialog->FileName::get();
    			 this->MapTextBox->Text = mapFileLoc;  
    Here is the code of the .cpp
    HANDLE mMapFile;
    char mapTemp[256];
    strcpy(mapTemp, mapFileLoc);
    mMapFile = CreateFile (mapTemp, GENERIC_READ,   //create a handle to the MAP file
                             FILE_SHARE_READ, NULL, OPEN_EXISTING,
       if(mMapFile == INVALID_HANDLE_VALUE)
    	   MessageBox::Show("Map File cannot be opened.");
          //return;// error;
    The problem is with the mapTemp not being the proper type for parameter 1. This successfully built with the borland tools.

    My question is what needs to be changed to get this to build in visual C++?


  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: HANDLE and CreateFile Function

    Your project is NOT a VC++ one, it is C++/CLI (managed C++).
    Either create a new *real* VC++ project or ask your question in a managed C++/CLI forum.
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.