IntPtr BitmapSource::CopyPixelsToMemory() { BitmapSize size = Size; WICRect rect = {0}; rect.X = 0; rect.Y = 0; rect.Width = size.Width; rect.Height = size.Height; // Force the stride to be a multiple of sizeof(DWORD) UINT stride = rect.Width * 4; stride = ((stride + sizeof(DWORD) - 1) / sizeof(DWORD)) * sizeof(DWORD); UINT bufferSize = stride * rect.Height; IntPtr buffer = Marshal::AllocHGlobal(bufferSize); Validate::VerifyResult( CastInterface<IWICBitmapSource>()->CopyPixels( &rect, stride, bufferSize, (BYTE*)buffer.ToPointer()) ); return buffer; }
SQLBRIDGE_API long long begin_tran() { SqlTransaction^ tran = DbHelper::GetOpenConnection(); GCHandle gcHandle = GCHandle::Alloc(tran); IntPtr pointer = GCHandle::ToIntPtr(gcHandle); return pointer.ToInt64(); }
// --------------------------------------------------------------- _DLLAPI long long __stdcall CreateManagedObject(const wchar_t* asmName, const wchar_t* typeName, wchar_t* exType, wchar_t* exMessage) { if (asmName == NULL || typeName == NULL || exType == NULL || exMessage == NULL) return 0; try { Object^ obj = Activator::CreateInstance(gcnew String(GetFullAssemblyName(asmName)), gcnew String(typeName))->Unwrap(); GCHandle handle = GCHandle::Alloc(obj); return (long long)GCHandle::ToIntPtr(handle).ToPointer(); } catch (Exception^ ex) { IntPtr exT = Marshal::StringToHGlobalUni(ex->GetType()->Name); wcsncpy(exType, (const wchar_t*)exT.ToPointer(), 64); Marshal::FreeHGlobal(exT); IntPtr exM = Marshal::StringToHGlobalUni(ex->Message); wcsncpy(exMessage, (const wchar_t*)exM.ToPointer(), 256); Marshal::FreeHGlobal(exM); return 0; } }
Boolean System::Drawing::GLSharp::WGL::MakeCurrent(IntPtr hdc, IntPtr ctx) { HDC m_hdc = (HDC)hdc.ToPointer(); HGLRC m_ctx = (HGLRC)ctx.ToPointer(); return !!::wglMakeCurrent(m_hdc, m_ctx); }
TriangleIndexVertexMaterialArray::TriangleIndexVertexMaterialArray(int numTriangles, IntPtr triangleIndexBase, int triangleIndexStride, int numVertices, IntPtr vertexBase, int vertexStride, int numMaterials, IntPtr materialBase, int materialStride, IntPtr triangleMaterialsBase, int materialIndexStride) : TriangleIndexVertexArray(new btTriangleIndexVertexMaterialArray(numTriangles, (int*)triangleIndexBase.ToPointer(), triangleIndexStride, numVertices, (btScalar*)vertexBase.ToPointer(), vertexStride, numMaterials, (unsigned char*)materialBase.ToPointer(), materialStride, (int*)triangleMaterialsBase.ToPointer(), materialIndexStride)) { }
IChromeHook^ ChromeHookService::Register(IntPtr hwnd) { msclr::lock l(lock); if (!g_ref) { installHook(); } g_ref++; ChromeHookClient^ client = gcnew ChromeHookClient((HWND) hwnd.ToPointer()); registeredWindows[(intptr_t) hwnd.ToPointer()] = client; return client; }
void Versy::PDF::Document::AddAttachedFileFromBuffer(Byte Buffer __gc[], ppUns32 BufferSize, String * FileNameToShowInDocument, String * Title, ppBool Compress) { // PDFDocAppendFileFromBuffer ( // PDFDocHandle Doc, void * Buffer, ppUns32 BufferSize, char * EmbedFileName, char * Title, // ppUns32 TitleLength, ppBool PackData); char* chFileNameToShowInDocument = (char*)Marshal::StringToHGlobalAnsi(FileNameToShowInDocument).ToPointer(); char* chTitle = (char*)Marshal::StringToHGlobalAnsi(Title).ToPointer(); IntPtr ptr = Marshal::AllocHGlobal(BufferSize); Marshal::Copy(Buffer, 0, ptr, BufferSize); PDFDocAppendFileFromBuffer(FDoc, ptr.ToPointer(), BufferSize, chFileNameToShowInDocument, chTitle, Title->Length, Compress); }
bool VdmHelper::MoveWindowToDesktop(IntPtr topLevelWindow, Guid desktopId) { #ifndef _WIN64 BOOL isRunningOnX64 = FALSE; ::IsWow64Process(GetCurrentProcess(), &isRunningOnX64); if(isRunningOnX64) { throw gcnew System::InvalidOperationException("You need call via 64bit dll"); } #endif // convert System.Guid to GUID auto bytes = desktopId.ToByteArray(); pin_ptr<unsigned char> pbytes = &bytes[0]; GUID dest; memcpy(&dest, pbytes, sizeof(GUID)); // allocate & request auto hwnd = (HWND)topLevelWindow.ToPointer(); LPVOID rGuid = VDMAllocGuid(hwnd, &dest); if (isConsoleWindowClass(hwnd)) { VDMInject(hwnd, &dest); } else { SendMessage(hwnd, RequestMoveWindowToDesktopMessage, 0, (LPARAM)rGuid); } VDMReleaseGuid(hwnd, rGuid); return true; }
//----------------------------------------------------------------------------- // <ZWManager::Create> // Create the unmanaged Manager singleton object, and add a watcher //----------------------------------------------------------------------------- void ZWManager::Create ( ) { // Create the Manager singleton Manager::Create(); // Add a notification handler m_onNotification = gcnew OnNotificationFromUnmanagedDelegate( this, &ZWManager::OnNotificationFromUnmanaged ); m_gchNotification = GCHandle::Alloc( m_onNotification ); IntPtr ip = Marshal::GetFunctionPointerForDelegate( m_onNotification ); Manager::Get()->AddWatcher( (Manager::pfnOnNotification_t)ip.ToPointer(), NULL ); // Add a controller state changed handler m_onStateChanged = gcnew OnControllerStateChangedFromUnmanagedDelegate( this, &ZWManager::OnControllerStateChangedFromUnmanaged ); m_gchControllerState = GCHandle::Alloc( m_onStateChanged ); }
static int Read(IntPtr dest) { int numBytesRead; if (!USBReadHelios(dest.ToPointer(), (DWORD*)&numBytesRead)) { throw gcnew Exception("Error reading from USB"); } return numBytesRead; }
IntPtr System::Drawing::GLSharp::WGL::CreateContext(IntPtr hdc) { HDC m_hdc = (HDC)hdc.ToPointer(); HGLRC m_ctx = ::wglCreateContext(m_hdc); return IntPtr::IntPtr(m_ctx); }
D3DDevice1^ D3DDevice1::CreateDeviceAndSwapChain1(IntPtr windowHandle) { RECT rc; Validate::VerifyBoolean(GetClientRect((HWND)windowHandle.ToPointer(), &rc)); UInt32 width = rc.right - rc.left; UInt32 height = rc.bottom - rc.top; Direct3D10::CreateDeviceOptions options = Direct3D10::CreateDeviceOptions::None; #ifdef _DEBUG // Make sure GetEnvironmentVariable is not defined #ifdef GetEnvironmentVariable #undef GetEnvironmentVariable #endif // GetEnvironmentVariable if (!String::IsNullOrEmpty(Environment::GetEnvironmentVariable("DXSDK_DIR"))) { options = Direct3D10::CreateDeviceOptions::Debug; } #endif // _DEBUG SwapChainDescription swapChainDescription = SwapChainDescription(); swapChainDescription.BufferCount = 1; swapChainDescription.BufferDescription = ModeDescription(width, height, Format::R8G8B8A8UNorm, Rational(60, 1)); swapChainDescription.BufferUsage = UsageOptions::RenderTargetOutput; swapChainDescription.OutputWindowHandle = windowHandle; swapChainDescription.SampleDescription = SampleDescription(1, 0); swapChainDescription.Windowed = true; swapChainDescription.SwapEffect = SwapEffect::Discard; swapChainDescription.Options = SwapChainOptions::None; HRESULT hr = S_OK; array<FeatureLevel>^ levels = { FeatureLevel::TenPointOne, FeatureLevel::Ten, FeatureLevel::NinePointThree, FeatureLevel::NinePointTwo, FeatureLevel::NinePointOne, }; for each (FeatureLevel featureLevel in levels) { D3DDevice1^ device; hr = TryCreateDeviceAndSwapChain1(nullptr, DriverType::Hardware, nullptr, options, featureLevel, swapChainDescription, device); if (SUCCEEDED(hr)) { return device; } }
void KbFilterController::ActivateDevice() { devices = gcnew array<HANDLE>(MAX_DEVICE_COUNT); for (int i = 0; i < MAX_DEVICE_COUNT; i++) { String ^ deviceName = L"\\\\.\\MyDLPKBF" + i; IntPtr cPtr = Marshal::StringToHGlobalUni(deviceName); devices[i] = CreateFile((LPCWSTR)cPtr.ToPointer(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); Marshal::FreeHGlobal(cPtr); if ( devices[i] == INVALID_HANDLE_VALUE ) { Logger::GetInstance()->Info ("CreateFile Failed, device not exists " + GetLastError()); } else { Logger::GetInstance()->Debug ("Opened Device: " + i); } } }
//----------------------------------------------------------------------------- //Spying Process functions follow //----------------------------------------------------------------------------- void Desktop::EnableHook(IntPtr windowHandle) { HINSTANCE hinstDLL; hinstDLL = LoadLibrary((LPCTSTR) _T("ManagedSpyLib.dll")); DisableHook(); DWORD tid = GetWindowThreadProcessId((HWND)windowHandle.ToPointer(), NULL); _messageHookHandle = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)GetProcAddress(hinstDLL, "MessageHookProc"), hinstDLL, tid); }
Adapter^ Factory::CreateSoftwareAdapter( IntPtr softwareModule ) { if( softwareModule == IntPtr::Zero ) throw gcnew ArgumentNullException( "softwareModule" ); HINSTANCE instance = reinterpret_cast<HINSTANCE>( softwareModule.ToPointer() ); IDXGIAdapter* adapter = 0; RECORD_DXGI( InternalPointer->CreateSoftwareAdapter( instance, &adapter ) ); if( adapter == 0 ) return nullptr; return Adapter::FromPointer( adapter ); }
// --------------------------------------------------------------- _DLLAPI void __stdcall DestroyManagedObject(long long hObject, wchar_t* exType, wchar_t* exMessage) { if (hObject <= 0 || exType == NULL || exMessage == NULL) return; try { GCHandle handle = GCHandle::FromIntPtr(IntPtr((HANDLE)hObject)); handle.Free(); } catch (Exception^ ex) { IntPtr exT = Marshal::StringToHGlobalUni(ex->GetType()->Name); wcsncpy(exType, (const wchar_t*)exT.ToPointer(), 64); Marshal::FreeHGlobal(exT); IntPtr exM = Marshal::StringToHGlobalUni(ex->Message); wcsncpy(exMessage, (const wchar_t*)exM.ToPointer(), 256); Marshal::FreeHGlobal(exM); } }
DataStream::DataStream( IntPtr userBuffer, Int64 sizeInBytes, bool canRead, bool canWrite ) { if( userBuffer == IntPtr::Zero ) throw gcnew ArgumentNullException( "userBuffer" ); if( sizeInBytes < 1 ) throw gcnew ArgumentOutOfRangeException( "sizeInBytes" ); m_Buffer = static_cast<char*>( userBuffer.ToPointer() ); m_Size = sizeInBytes; m_CanRead = canRead; m_CanWrite = canWrite; GC::SuppressFinalize( this ); }
bool KeyboardHook::InstallHook(IntPtr windowHandle) { UninstallHook(); DWORD tid = GetWindowThreadProcessId((HWND)windowHandle.ToPointer(), NULL); HINSTANCE hinstDLL; hinstDLL = LoadLibrary((LPCTSTR) _T("WindowsHook.dll")); HOOKPROC llMouseProc = (HOOKPROC)GetProcAddress(hinstDLL, "LowLevelKeyProc"); if(hinstDLL != NULL) { _keyBoardHook = SetWindowsHookEx(WH_KEYBOARD_LL, llMouseProc,hinstDLL,0); } return _keyBoardHook != NULL; }
void TessellatorReceiver::AddVertex(IntPtr vIdx) { int index = vIdx.ToInt32(); if(_pointTally==0) _fanStartIndex=index; if(_pointTally < 3) //first time { _indices->Add(index); } else { switch(_meshType) { case GL_TRIANGLES:// 0x0004 _indices->Add(index); break; case GL_TRIANGLE_STRIP:// 0x0005 if(_pointTally % 2 ==0) { _indices->Add(_previousToLastIndex); _indices->Add(_lastIndex); } else { _indices->Add(_lastIndex); _indices->Add(_previousToLastIndex); } _indices->Add(index); break; case GL_TRIANGLE_FAN:// 0x0006 _indices->Add(_fanStartIndex); _indices->Add(_lastIndex); _indices->Add(index); break; } } _previousToLastIndex = _lastIndex; _lastIndex = index; _pointTally++; }
D3DDevice^ D3DDevice::CreateDeviceAndSwapChain(IntPtr windowHandle) { RECT rc; Validate::VerifyBoolean(GetClientRect((HWND)windowHandle.ToPointer(), &rc)); UInt32 width = rc.right - rc.left; UInt32 height = rc.bottom - rc.top; Direct3D11::CreateDeviceOptions options = Direct3D11::CreateDeviceOptions::None; #ifdef _DEBUG // Make sure GetEnvironmentVariable is not defined #ifdef GetEnvironmentVariable #undef GetEnvironmentVariable #endif if (!String::IsNullOrEmpty(System::Environment::GetEnvironmentVariable("DXSDK_DIR"))) { options = Direct3D11::CreateDeviceOptions::Debug; } #endif SwapChainDescription swapChainDescription = SwapChainDescription(); swapChainDescription.BufferCount = 1; swapChainDescription.BufferDescription = ModeDescription(width, height, Graphics::Format::R8G8B8A8UNorm, Rational(60, 1)); swapChainDescription.BufferUsage = Graphics::UsageOptions::RenderTargetOutput; swapChainDescription.OutputWindowHandle = windowHandle; swapChainDescription.SampleDescription = SampleDescription(1, 0); swapChainDescription.Windowed = true; swapChainDescription.SwapEffect = SwapEffect::Discard; swapChainDescription.Options = SwapChainOptions::None; return CreateDeviceAndSwapChain(nullptr, Direct3D11::DriverType::Hardware, nullptr, options, nullptr, swapChainDescription); }
using namespace msclr::interop; namespace Interop { Interoperation::Interoperation():m_hTinyFS(NULL) { } Interoperation::~Interoperation() { } int Interoperation::LoadTinyFSAssemble(System::String^ strAssemble) { IntPtr intPtr = Marshal::StringToHGlobalAnsi(strAssemble); LPCSTR pcszAssemble = static_cast<LPCSTR>(intPtr.ToPointer()); m_hTinyFS = LoadLibraryA(pcszAssemble); if (m_hTinyFS == NULL) return 0; return 1; } void Interoperation::UnloadTinyFSAssemble() { if (m_hTinyFS) { FreeLibrary(m_hTinyFS); m_hTinyFS = NULL; } }
void PDFWrapper::FitToHeight(IntPtr handler){ //if(doc.IsNull()) // throw gcnew System::NullReferenceException(); long hwnd=(long)handler.ToPointer(); _pdfDoc->FitScreenHeight(hwnd); }
bool PDFWrapper::DrawPageHDC(IntPtr hdc){ long lhdc =(long)hdc.ToPointer(); _pdfDoc->RenderHDC(lhdc); return true; }
// これは メイン DLL ファイルです。 #include "stdafx.h" #include "libApplicationList.h" extern "C" __declspec(dllexport) void initializer(void** extData, FREContextInitializer* ctxInitializer, FREContextFinalizer* ctxFinalizer); extern "C" __declspec(dllexport) void finalizer(void** extData); void ConvertToUni(String^ _str, char* szBuf, const int bufLen) { IntPtr ptr = Marshal::StringToHGlobalUni(_str); const char* str = static_cast<const char*>(ptr.ToPointer()); WideCharToMultiByte(CP_UTF8, 0, (wchar_t*)str, -1, szBuf, bufLen, NULL, NULL); Marshal::FreeHGlobal(ptr); } FREObject GetApplicationList(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){ FREObject resultObj; FREObject elementObj; ApplicationList_CS::AppList_CS^ cs = gcnew ApplicationList_CS::AppList_CS(); ArrayList^ list = gcnew ArrayList(); list = cs->getApplicationNames(); // Application Name buffer const int bufLen = 1024; char szBuf[bufLen]; const int count = list->Count;
#include "ButtonRemote.h" namespace Vrpn { namespace Internal { delegate void ButtonChangeCallback(void *userData, const vrpn_BUTTONCB info); } } using namespace System; using namespace System::Runtime::InteropServices; using namespace Vrpn; using namespace Vrpn::Internal; ButtonRemote::ButtonRemote(String ^name) { IntPtr hAnsiName = Marshal::StringToHGlobalAnsi(name); const char *ansiName = static_cast<const char *>(hAnsiName.ToPointer()); m_button = new ::vrpn_Button_Remote(ansiName); Marshal::FreeHGlobal(hAnsiName); RegisterHandler(); m_disposed = false; } ButtonRemote::ButtonRemote(System::String ^name, Vrpn::Connection ^connection) { IntPtr hAnsiName = Marshal::StringToHGlobalAnsi(name);
InputManager::InputManager(System::IntPtr _windowHandle) { IntPtr hInst = System::Runtime::InteropServices::Marshal::GetHINSTANCE(this->GetType()->Module); m_Pimpl = new RE::InputNative::InputManager(hInst.ToPointer(), (int*)_windowHandle.ToPointer()); }
m_myTessBaseAPIInstance = NULL; m_pageRes = NULL; } tessnet2::Tesseract::~Tesseract() { Clear(); } int tessnet2::Tesseract::Init(String^ lang, bool numericMode) { Clear(); m_myTessBaseAPIInstance = new MyTessBaseAPI; // IntPtr _dataPath = Marshal::StringToHGlobalAnsi(dataPath); IntPtr _lang = Marshal::StringToHGlobalAnsi(lang); int result = m_myTessBaseAPIInstance->InitWithLanguage(NULL, NULL, (char *)_lang.ToPointer(), NULL, numericMode, 0, NULL); SetVariable("tessedit_write_ratings", true); //SetVariable("tessedit_zero_rejection", true); Marshal::FreeHGlobal(_lang); // Marshal::FreeHGlobal(_dataPath); return result; } void tessnet2::Tesseract::Clear () { page_image.destroy(); if (m_pageRes) delete m_pageRes; m_pageRes = NULL;
extern "C" int WINRT_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) { #if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8) /* Sadly, Windows Phone 8 doesn't include the MessageDialog class that * Windows 8.x/RT does, even though MSDN's reference documentation for * Windows Phone 8 mentions it. * * The .NET runtime on Windows Phone 8 does, however, include a * MessageBox class. Perhaps this could be called, somehow? */ return SDL_SetError("SDL_messagebox support is not available for Windows Phone 8.0"); #else SDL_VideoDevice *_this = SDL_GetVideoDevice(); #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP const int maxbuttons = 2; const char * platform = "Windows Phone 8.1+"; #else const int maxbuttons = 3; const char * platform = "Windows 8.x"; #endif if (messageboxdata->numbuttons > maxbuttons) { return SDL_SetError("WinRT's MessageDialog only supports %d buttons, at most, on %s. %d were requested.", maxbuttons, platform, messageboxdata->numbuttons); } /* Build a MessageDialog object and its buttons */ MessageDialog ^ dialog = ref new MessageDialog(WINRT_UTF8ToPlatformString(messageboxdata->message)); dialog->Title = WINRT_UTF8ToPlatformString(messageboxdata->title); for (int i = 0; i < messageboxdata->numbuttons; ++i) { UICommand ^ button = ref new UICommand(WINRT_UTF8ToPlatformString(messageboxdata->buttons[i].text)); button->Id = safe_cast<IntPtr>(i); dialog->Commands->Append(button); if (messageboxdata->buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) { dialog->CancelCommandIndex = i; } if (messageboxdata->buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) { dialog->DefaultCommandIndex = i; } } /* Display the MessageDialog, then wait for it to be closed */ /* TODO, WinRT: Find a way to redraw MessageDialog instances if a GPU device-reset occurs during the following event-loop */ auto operation = dialog->ShowAsync(); while (operation->Status == Windows::Foundation::AsyncStatus::Started) { WINRT_PumpEvents(_this); } /* Retrieve results from the MessageDialog and process them accordingly */ if (operation->Status != Windows::Foundation::AsyncStatus::Completed) { return SDL_SetError("An unknown error occurred in displaying the WinRT MessageDialog"); } if (buttonid) { IntPtr results = safe_cast<IntPtr>(operation->GetResults()->Id); int clicked_index = results.ToInt32(); *buttonid = messageboxdata->buttons[clicked_index].buttonid; } return 0; #endif /* if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP / else */ }
int Helper::GetListViewItemNumber (IntPtr listViewHWnd) { return ListView_GetItemCount ((HWND) listViewHWnd.ToPointer ()); } // GetListViewItemNumber
void MaterialProperties::TriangleMaterialsBase::set(IntPtr value) { _native->m_triangleMaterialsBase = (const unsigned char *)value.ToPointer(); }