Sha256: 830e96ad1c69727ad76d83760b9b0be6caaa22e6858514cc867d365dc144af21

Contents?: true

Size: 921 Bytes

Versions: 9

Compression:

Stored size: 921 Bytes

Contents

#pragma once

using namespace System::Runtime::InteropServices;

ref class StringHelper
{
public:
  static void CopyToUnmanagedString(Exception^ e, char* destination, const int destinationSize)
  {
    CopyToUnmanagedString(e->Message + e->StackTrace, destination, destinationSize);
  }

  static void CopyToUnmanagedString(String^ source, char* destination, const int destinationSize)
  {
    auto unmanagedString = Marshal::StringToHGlobalAnsi(source);
    strncpy_s(destination, destinationSize, (const char*)(void*)unmanagedString,  _TRUNCATE);
    Marshal::FreeHGlobal(unmanagedString);
  }

  static char* ToUnmanaged(String^ source)
  {
    if( nullptr == source ) return NULL;

    const int numberOfBytes = source->Length + 1;
    auto unmanagedString = new char[numberOfBytes];
    CopyToUnmanagedString(source, unmanagedString, numberOfBytes);
    return unmanagedString;
  }
};

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
uia-1.0 ext/UiaDll/UiaDll/StringHelper.h
uia-0.8 ext/UiaDll/UiaDll/StringHelper.h
uia-0.7 ext/UiaDll/UiaDll/StringHelper.h
uia-0.7.alpha.1 ext/UiaDll/UiaDll/StringHelper.h
uia-0.6 ext/UiaDll/UiaDll/StringHelper.h
uia-0.5 ext/UiaDll/UiaDll/StringHelper.h
uia-0.4.4 ext/UiaDll/UiaDll/StringHelper.h
uia-0.4.3 ext/UiaDll/UiaDll/StringHelper.h
uia-0.4.2 ext/UiaDll/UiaDll/StringHelper.h