Классы должны помещаться на экране.
Если вам нужно использовать полосу прокрутки, чтобы увидеть весь ваш класс, ваш класс слишком велик.
Разбор кода и миниатюрные шрифты обманывают.
Самый простой способ сделать это в C ++ / CLI - использовать pin_ptr
:
#include <vcclr.h>
void CallFindFirstFile(System::String^ s)
{
WIN32_FIND_DATA data;
pin_ptr<const wchar_t> wname = PtrToStringChars(s);
FindFirstFile(wname, &data);
}
To convert a System::String ot LPCWSTR in C++/CLI you can you use the Marshal::StringToHGlobalAnsi function to convert managed strings to unmanaged strings.
System::String ^str = "Hello World";
IntPtr ptr = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);
HANDLE hFind = FindFirstFile((LPCSTR)ptr.ToPointer(), data);
System::Runtime::InteropServices::Marshal::FreeHGlobal(ptr);
You need to use P/Invoke. Check this link: http://www.pinvoke.net/default.aspx/kernel32/FindFirstFile.html
Simply add the DllImport
native function signature:
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
static extern IntPtr FindFirstFile
(string lpFileName, out WIN32_FIND_DATA lpFindFileData);
and CLR will do managed to native type marshaling automatically.
[Edit] I just realized you're using C++/CLI. In that case, you can also use implicit P/Invoke, which is a feature which only C++ supports (opposed to C# and VB.NET). This articles shows several examples: