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
Here is the code of the .cppCode: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; }
The problem is with the mapTemp not being the proper type for parameter 1. This successfully built with the borland tools.Code: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, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); if(mMapFile == INVALID_HANDLE_VALUE) { MessageBox::Show("Map File cannot be opened."); //return;// error; }
My question is what needs to be changed to get this to build in visual C++?
thanks




Reply With Quote
