- AMD Device Library eXtra
- Programming with ADLX
- Overview
- ADLX Programming Guide
- ADLX Samples
- Overview
- C++ Samples
- Overview
- Display
- Display
- Display3DLUT
- DisplayBlanking
- DisplayColorDepth
- DisplayConnectivityExperience
- DisplayCustomColor
- DisplayCustomResolution
- DisplayEvents
- DisplayFreeSync
- DisplayGamma
- DisplayGamut
- DisplayGPUScaling
- DisplayHDCP
- DisplayInfo
- DisplayIntegerScaling
- DisplayPixelFormat
- DisplayScalingMode
- DisplayVariBright
- DisplayVSR
- Performance Monitoring
- Receiving Events Notifications
- C Samples
- Overview
- Display
- Display
- Display3DLUT
- DisplayBlanking
- DisplayColorDepth
- DisplayConnectivityExperience
- DisplayCustomColor
- DisplayCustomResolution
- DisplayEvents
- DisplayFreeSync
- DisplayGamma
- DisplayGamut
- DisplayGPUScaling
- DisplayHDCP
- DisplayInfo
- DisplayIntegerScaling
- DisplayPixelFormat
- DisplayScalingMode
- DisplayVariBright
- DisplayVSR
- Performance Monitoring
- Receiving Events Notifications
- ADLX SDK References
- Overview
- ADLX Helpers
- ADLX Interfaces
- Overview
- 3D Graphics
- 3D Graphics
- iadlx3danisotropicfiltering
- iadlx3dantialiasing
- iadlx3dframeratetargetcontrol
- iadlx3dimagesharpening
- iadlx3dradeonsuperresolution
- iadlx3dsettingschangedevent
- IADLX3DSettingsChangedEvent
- GetGPU
- IsAnisotropicFilteringChanged
- IsAntiAliasingChanged
- IsAntiLagChanged
- IsBoostChanged
- IsChillChanged
- IsEnhancedSyncChanged
- IsFrameRateTargetControlChanged
- IsImageSharpeningChanged
- IsMorphologicalAntiAliasingChanged
- IsRadeonSuperResolutionChanged
- IsResetShaderCache
- IsTessellationModeChanged
- IsWaitForVerticalRefreshChanged
- iadlx3dsettingschangedhandling
- iadlx3dsettingsservices
- Display
- Display
- iadlxdisplay3dlut
- IADLXDisplay3DLUT
- ClearUser3DLUT
- GetAllUser3DLUT
- GetHDRUser3DLUT
- GetSCEDynamicContrast
- GetSCEDynamicContrastRange
- GetSDRUser3DLUT
- GetUser3DLUTIndex
- IsCurrentSCEDisabled
- IsCurrentSCEDynamicContrast
- IsCurrentSCEVividGaming
- IsSupportedSCE
- IsSupportedSCEDynamicContrast
- IsSupportedSCEVividGaming
- IsSupportedUser3DLUT
- SetAllUser3DLUT
- SetHDRUser3DLUT
- SetSCEDisabled
- SetSCEDynamicContrast
- SetSCEVividGaming
- SetSDRUser3DLUT
- iadlxdisplay3dlutchangedevent
- iadlxdisplayblanking
- iadlxdisplaychangedhandling
- IADLXDisplayChangedHandling
- AddDisplay3DLUTEventListener
- AddDisplayGammaEventListener
- AddDisplayGamutEventListener
- AddDisplayListEventListener
- AddDisplaySettingsEventListener
- RemoveDisplay3DLUTEventListener
- RemoveDisplayGammaEventListener
- RemoveDisplayGamutEventListener
- RemoveDisplayListEventListener
- RemoveDisplaySettingsEventListener
- iadlxdisplayconnectivityexperience
- IADLXDisplayConnectivityExperience
- GetDPLinkRate
- GetNumberOfActiveLanes
- GetNumberOfTotalLanes
- GetRelativePreEmphasis
- GetRelativeVoltageSwing
- IsEnabledHDMIQualityDetection
- IsEnabledLinkProtection
- IsSupportedDPLink
- IsSupportedHDMIQualityDetection
- SetEnabledHDMIQualityDetection
- SetRelativePreEmphasis
- SetRelativeVoltageSwing
- iadlxdisplaycustomcolor
- IADLXDisplayCustomColor
- GetBrightness
- GetBrightnessRange
- GetContrast
- GetContrastRange
- GetHue
- GetHueRange
- GetSaturation
- GetSaturationRange
- GetTemperature
- GetTemperatureRange
- IsBrightnessSupported
- IsContrastSupported
- IsHueSupported
- IsSaturationSupported
- IsTemperatureSupported
- SetBrightness
- SetContrast
- SetHue
- SetSaturation
- SetTemperature
- iadlxdisplaycustomresolution
- iadlxdisplaygamma
- IADLXDisplayGamma
- GetGammaCoefficient
- GetGammaRamp
- IsCurrentDeGammaRamp
- IsCurrentReGamma36
- IsCurrentReGammaBT709
- IsCurrentRegammaCoefficient
- IsCurrentReGammaPQ
- IsCurrentReGammaPQ2084Interim
- IsCurrentReGammaRamp
- IsCurrentReGammaSRGB
- IsSupportedReGamma36
- IsSupportedReGammaBT709
- IsSupportedReGammaPQ
- IsSupportedReGammaPQ2084Interim
- IsSupportedReGammaSRGB
- ResetGammaRamp
- SetDeGammaRamp
- SetReGamma36
- SetReGammaBT709
- SetReGammaCoefficient
- SetReGammaPQ
- SetReGammaPQ2084Interim
- SetReGammaRamp
- SetReGammaSRGB
- iadlxdisplaygammachangedevent
- Miscellaneous
- Performance Monitoring
- Legal Information and Compliance/Disclaimers
ShareMemory
Navigation: Programming with ADLX → ADLX Samples → C++ Samples → ServiceCall
C++
Code
C++
//// Copyright Advanced Micro Devices, Inc. All rights reserved.////-------------------------------------------------------------------------------------------------
/// \file ShareMemory.cpp/// \brief This document demonstrate how to use shared memory.
#include <Windows.h>#include "GlobalDefs.h"
// ConstructorShareMem::ShareMem () : file_ (NULL), buffer_ (NULL), size_ (0){}
// DestructorShareMem::~ShareMem (){ if (file_) { CloseHandle (file_); file_ = NULL; }
if (buffer_) { UnmapViewOfFile (buffer_); buffer_ = NULL; }}
// Create shared memorybool ShareMem::Create (ULONG filesize, PCWCHAR filename){ DWORD errCode = 0;
SECURITY_DESCRIPTOR sd; SECURITY_ATTRIBUTES sa; size_ = filesize;
// After setting this permission, the general application does not have administrator privileges // In order to start to open mapping file Otherwise Access Denny InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl (&sd, TRUE, (PACL)NULL, FALSE);
sa.nLength = sizeof (SECURITY_ATTRIBUTES); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = &sd;
// Create a mapped file file_ = CreateFileMappingW (INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, filesize, filename); if (file_ == NULL) { XTrace (L"ADLX Call Service: ShareMem::Create: CreateFileMappingW, error: %d\n", GetLastError()); return false; }
// In the external function can be directly manipulate the variables to get the memory-mapped file. if (buffer_) { UnmapViewOfFile (buffer_); buffer_ = NULL; }
buffer_ = MapViewOfFile (file_, FILE_MAP_ALL_ACCESS, 0, 0, filesize); if (buffer_ == NULL) { XTrace (L"ADLX Call Service: ShareMem::Create: MapViewOfFile, error: %d\n", GetLastError ()); return false; }
XTrace (L"ADLX Call Service: ShareMem::Create: OK\n");
return true;}
// Write data to shared memorybool ShareMem::WriteBuffer (PVOID buffer, ULONG size){ if (buffer && size > 0) { memcpy_s (buffer_, size, buffer, size); return true; }
return false;}
// Read data from shared memorybool ShareMem::ReadBuffer (PVOID buffer, ULONG size){ SECURITY_DESCRIPTOR sd; SECURITY_ATTRIBUTES sa; bool ret = false; InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl (&sd, TRUE, (PACL)NULL, FALSE);
sa.nLength = sizeof (SECURITY_ATTRIBUTES); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = &sd;
if (file_) { if (buffer_) { memcpy_s (buffer, size, buffer_, size); ret = true; } }
return ret;}