pin_ptr and interior_ptr in vc++

1.4k views Asked by At

I am working on a project that was written(a HID inteface for STM32) by a person who worked before in visual c++ 2008. So to imitate the line that is causing problem, I created a sample winform application in VC++ 2008. Here is the click event with this one line giving build error only when built for x64, but a win32 build doesn't give any building error and works fine.

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             String^ devPath =  this->textBox1->Text;
             MessageBox::Show(devPath);
             pin_ptr<const TCHAR> pPath = PtrToStringChars(devPath); *error line
         }
};

and the the build error that appears only for x64 build is:

Error   1 error C2440: 'initializing' : cannot convert from 'cli::interior_ptr<Type>' to 'cli::pin_ptr<Type>'

Thanks.

2

There are 2 answers

0
Vikyboss On BEST ANSWER
  1. Right Click on the project
  2. Properties
  3. Configuration Properties
  4. General
  5. Character-Set "Use Unicode Character Set"

This fixed the problem.

2
Ben Voigt On

The "better" solution is probably:

pin_ptr<const WCHAR> pPath = PtrToStringChars(devPath);

and then use CreateFileW, because you have a Unicode string.

That way your code will work regardless of project-file Unicode configuration.