-
May 13th, 2010, 09:38 AM
#1
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
Code:
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
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;
}
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++?
thanks
-
May 13th, 2010, 11:01 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|