本文整理汇总了C#中IntPtr.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# IntPtr.ToString方法的具体用法?C# IntPtr.ToString怎么用?C# IntPtr.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntPtr
的用法示例。
在下文中一共展示了IntPtr.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScreenHelpers
private ScreenHelpers()
{
_hwnd = Win32Helpers.GetForegroundWindow();
_windowId = _hwnd.ToString();
#if UNITY_EDITOR
_gameWindow = GetMainGameView();
#endif
}
示例2: MySafeHandle
public MySafeHandle(IntPtr handleValue)
: base(IntPtr.Zero, true)
{
handle = handleValue;
if (handle != handleValue)
{
throw new Exception("Handle value is not assigned correctly, handleValue = " + handleValue + ", Handle = " + handle.ToString());
}
}
示例3: PosTest6
public bool PosTest6()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest6: Call Ctor with IntPtr reference and set trackResurrection to true");
try
{
Object desiredValue = IntPtr.Zero;
WeakReference reference = new WeakReference(desiredValue, true);
if ((reference.TrackResurrection != true) || (!reference.Target.Equals(desiredValue)))
{
TestLibrary.TestFramework.LogError("006.1", "Calling Ctor with valid target reference and set trackResurrection to false constructs wrong instance");
TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] reference.TrackResurrection = " + reference.TrackResurrection.ToString() +
", reference.Target = " + reference.Target.ToString() +
", desiredValue = " + desiredValue.ToString());
retVal = false;
}
desiredValue = new IntPtr(TestLibrary.Generator.GetInt32(-55));
reference = new WeakReference(desiredValue, false);
if ((reference.TrackResurrection != false) || (!reference.Target.Equals(desiredValue)))
{
TestLibrary.TestFramework.LogError("006.2", "Calling Ctor with valid target reference and set trackResurrection to false constructs wrong instance");
TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] reference.TrackResurrection = " + reference.TrackResurrection.ToString() +
", reference.Target = " + reference.Target.ToString() +
", desiredValue = " + desiredValue.ToString());
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("006.3", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例4: Socket
/// <devdoc>
/// <para>
/// Called by the class to create a socket to accept an
/// incoming request.
/// </para>
/// </devdoc>
//protected Socket(IntPtr fd) {
private Socket(IntPtr fd) {
//new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
//
// this should never happen, let's check anyway
//
if (fd==SocketErrors.InvalidSocketIntPtr) {
throw new ArgumentException(SR.GetString(SR.net_InvalidSocketHandle, fd.ToString()));
}
m_Handle = fd;
addressFamily = Sockets.AddressFamily.Unknown;
socketType = Sockets.SocketType.Unknown;
protocolType = Sockets.ProtocolType.Unknown;
}
示例5: Complete
// This method is guaranteed to be called only once. If called with a non-zero userToken, the context is not flowed.
protected override void Complete(IntPtr userToken)
{
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("ContextAwareResult#" + LoggingHash.HashString(this) + "::Complete() _Context(set):" + (_context != null).ToString() + " userToken:" + userToken.ToString());
}
// If no flowing, just complete regularly.
if ((_flags & StateFlags.PostBlockStarted) == 0)
{
base.Complete(userToken);
return;
}
// At this point, IsCompleted is set and CompletedSynchronously is fixed. If it's synchronous, then we want to hold
// the completion for the CaptureOrComplete() call to avoid the context flow. If not, we know CaptureOrComplete() has completed.
if (CompletedSynchronously)
{
return;
}
ExecutionContext context = _context;
// If the context is being abandoned or wasn't captured (SuppressFlow, null AsyncCallback), just
// complete regularly, as long as CaptureOrComplete() has finished.
//
if (userToken != IntPtr.Zero || context == null)
{
base.Complete(userToken);
return;
}
ExecutionContext.Run(context, s => ((ContextAwareResult)s).CompleteCallback(), this);
}
示例6: StopSound
private void StopSound(IntPtr tag)
{
foreach (var sound in soundInstanceList) {
if (sound.AudioTag == tag.ToString()) {
sound.Stop();
}
}
}
示例7: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2: Verify ctor can set correct handle value for constructor with parameters");
try
{
IntPtr ptr = new IntPtr(TestLibrary.Generator.GetInt32(-55));
MySafeHandle msf = new MySafeHandle(ptr);
if (msf.Handle != ptr)
{
TestLibrary.TestFramework.LogError("002.1", "Ctor can not set correct handle value");
TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] msf.Handle = " + msf.Handle.ToString() +
", desiredValue = " + ptr.ToString());
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例8: PosTest4
public bool PosTest4()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest4: DangerousGetHandle should return handle value for valid safe handle");
try
{
int randValue = TestLibrary.Generator.GetInt32(-55);
IntPtr desiredValue = new IntPtr(randValue);
SafeHandle handle = new MySafeInValidHandle(desiredValue);
IntPtr handleValue = handle.DangerousGetHandle();
if (handleValue != desiredValue)
{
TestLibrary.TestFramework.LogError("004.1", "DangerousGetHandle returns wrong handle value for valid safe handle");
TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString());
retVal = false;
}
handleValue = handle.DangerousGetHandle();
if (handleValue != desiredValue)
{
TestLibrary.TestFramework.LogError("004.2", "DangerousGetHandle returns wrong handle value for valid safe handle");
TestLibrary.TestFramework.LogInformation("WARNING: [LOCAL VARIABLES] handleValue = " + handleValue.ToString() + ", desiredValue = " + desiredValue.ToString());
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004.3", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例9: VerifyPointer
private static void VerifyPointer(IntPtr ptr, long expected)
{
Assert.Equal(expected, ptr.ToInt64());
int expected32 = (int)expected;
if (expected32 != expected)
{
Assert.Throws<OverflowException>(() => ptr.ToInt32());
return;
}
int i = ptr.ToInt32();
Assert.Equal(expected32, ptr.ToInt32());
Assert.Equal(expected.ToString(), ptr.ToString());
Assert.Equal(expected.ToString("x"), ptr.ToString("x"));
Assert.Equal(ptr, new IntPtr(expected));
Assert.True(ptr == new IntPtr(expected));
Assert.False(ptr != new IntPtr(expected));
Assert.NotEqual(ptr, new IntPtr(expected + 1));
Assert.False(ptr == new IntPtr(expected + 1));
Assert.True(ptr != new IntPtr(expected + 1));
}
示例10: CopyMonitoringInConsole
void CopyMonitoringInConsole(ErrorCode in_errorCode, ErrorLevel in_errorLevel, uint in_playingID, IntPtr in_gameObjID, string in_msg)
{
string msg = "Wwise: " + in_msg;
if (in_gameObjID != (IntPtr)AkSoundEngine.AK_INVALID_GAME_OBJECT)
{
GameObject obj = EditorUtility.InstanceIDToObject((int)in_gameObjID) as GameObject;
string name = obj != null ? obj.ToString() : in_gameObjID.ToString();
msg += "(Object: " + name + ")";
}
if (in_errorLevel == ErrorLevel.ErrorLevel_Error)
Debug.LogError(msg);
else{
//Debug.Log(msg);
}
}
示例11: EyeXViewportBoundsProvider
/// <summary>
/// Initializes a new instance of the <see cref="EyeXViewportBoundsProvider"/> class.
/// </summary>
protected EyeXViewportBoundsProvider()
{
_hwnd = FindWindowWithThreadProcessId();
GameWindowId = _hwnd.ToString();
}
示例12: Complete
//
// Is guaranteed to be called only once. If called with a non-zero userToken, the context is not flowed.
//
protected override void Complete(IntPtr userToken)
{
GlobalLog.Print("ContextAwareResult#" + ValidationHelper.HashString(this) + "::Complete() _Context(set):" + (_Context != null).ToString() + " userToken:" + userToken.ToString());
// If no flowing, just complete regularly.
if ((_Flags & StateFlags.PostBlockStarted) == 0)
{
base.Complete(userToken);
return;
}
// At this point, IsCompleted is set and CompletedSynchronously is fixed. If it's synchronous, then we want to hold
// the completion for the CaptureOrComplete() call to avoid the context flow. If not, we know CaptureOrComplete() has completed.
if (CompletedSynchronously)
{
return;
}
ExecutionContext context = _Context;
if (userToken != IntPtr.Zero || context == null)
{
base.Complete(userToken);
return;
}
ExecutionContext.Run((_Flags & StateFlags.ThreadSafeContextCopy) != 0 ? context.CreateCopy() : context,
new ContextCallback(CompleteCallback), null);
}
示例13: TestPointer
private static void TestPointer(IntPtr p, long expected)
{
long l = p.ToInt64();
Assert.Equal(l, expected);
int expected32 = (int)expected;
if (expected32 != expected)
{
Assert.Throws<OverflowException>(() => { int i = p.ToInt32(); });
return;
}
{
int i = p.ToInt32();
Assert.Equal(i, expected32);
}
string s = p.ToString();
string sExpected = expected.ToString();
Assert.Equal(s, sExpected);
s = p.ToString("x");
sExpected = expected.ToString("x");
Assert.Equal(s, sExpected);
bool b;
b = (p == new IntPtr(expected));
Assert.True(b);
b = (p == new IntPtr(expected + 1));
Assert.False(b);
b = (p != new IntPtr(expected));
Assert.False(b);
b = (p != new IntPtr(expected + 1));
Assert.True(b);
}
示例14: EffectKeyValue
public EffectKeyValue(string key, IntPtr value)
{
this.key = key;
this.value = value.ToString();
}
示例15: NativeToHostEntry
internal static IPHostEntry NativeToHostEntry(IntPtr nativePointer) {
#endif
//
// marshal pointer to struct
//
hostent Host = (hostent)Marshal.PtrToStructure(nativePointer, typeof(hostent));
IPHostEntry HostEntry = new IPHostEntry();
if (Host.h_name != IntPtr.Zero) {
HostEntry.HostName = Marshal.PtrToStringAnsi(Host.h_name);
GlobalLog.Print("HostEntry.HostName: " + HostEntry.HostName);
}
// decode h_addr_list to ArrayList of IP addresses.
// The h_addr_list field is really a pointer to an array of pointers
// to IP addresses. Loop through the array, and while the pointer
// isn't NULL read the IP address, convert it to an IPAddress class,
// and add it to the list.
ArrayList TempList = new ArrayList();
int IPAddressToAdd;
string AliasToAdd;
IntPtr currentArrayElement;
//
// get the first pointer in the array
//
currentArrayElement = Host.h_addr_list;
nativePointer = Marshal.ReadIntPtr(currentArrayElement);
while (nativePointer != IntPtr.Zero) {
//
// if it's not null it points to an IPAddress,
// read it...
//
IPAddressToAdd = Marshal.ReadInt32(nativePointer);
#if BIGENDIAN
// IP addresses from native code are always a byte array
// converted to int. We need to convert the address into
// a uniform integer value.
IPAddressToAdd = (int)( ((uint)IPAddressToAdd << 24) |
(((uint)IPAddressToAdd & 0x0000FF00) << 8) |
(((uint)IPAddressToAdd >> 8) & 0x0000FF00) |
((uint)IPAddressToAdd >> 24) );
#endif
GlobalLog.Print("currentArrayElement: " + currentArrayElement.ToString() + " nativePointer: " + nativePointer.ToString() + " IPAddressToAdd:" + IPAddressToAdd.ToString());
//
// ...and add it to the list
//
TempList.Add(new IPAddress(IPAddressToAdd));
//
// now get the next pointer in the array and start over
//
currentArrayElement = IntPtrHelper.Add(currentArrayElement, IntPtr.Size);
nativePointer = Marshal.ReadIntPtr(currentArrayElement);
}
HostEntry.AddressList = new IPAddress[TempList.Count];
TempList.CopyTo(HostEntry.AddressList, 0);
//
// Now do the same thing for the aliases.
//
TempList.Clear();
currentArrayElement = Host.h_aliases;
nativePointer = Marshal.ReadIntPtr(currentArrayElement);
while (nativePointer != IntPtr.Zero) {
GlobalLog.Print("currentArrayElement: " + ((long)currentArrayElement).ToString() + "nativePointer: " + ((long)nativePointer).ToString());
//
// if it's not null it points to an Alias,
// read it...
//
AliasToAdd = Marshal.PtrToStringAnsi(nativePointer);
//
// ...and add it to the list
//
TempList.Add(AliasToAdd);
//
// now get the next pointer in the array and start over
//
currentArrayElement = IntPtrHelper.Add(currentArrayElement, IntPtr.Size);
nativePointer = Marshal.ReadIntPtr(currentArrayElement);
}
HostEntry.Aliases = new string[TempList.Count];
TempList.CopyTo(HostEntry.Aliases, 0);
return HostEntry;
//.........这里部分代码省略.........