Search code examples
visual-c++pin-ptr

pin_ptr and interior_ptr in vc++


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.


Solution

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

    This fixed the problem.