Desktop Functions: Smart Device Functions:
|
Search Results for "Hi" in [All]wlanapi
private const uint WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES = 0x00000002;
WlanGetAvailableNetworkList(ClientHandle, ref pInterfaceGuid, WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES, new IntPtr(), ref ppAvailableNetworkList); On Windows 7, this function returns 87 (ERROR_INVALID_PARAMETER) even if your parameters are correct when wireless is disabled. Wireless must be enable in order for that function to return success.
// Do something here with the connection info....
' Do something here with the connection info.... 4: WlanScan This method just tells the interface to start doing a scan. If you want to get results as they come back, you have to register a callback function. An easier way is to call this method, wait a while, then use WlanGetAvailableNetworkList kernel325: 1 This page needs to be deleted!MFC automatically manages activation context switching for fusion/winsxs support. Interop dll's don't. I had to add support for this in our application. To do so, define
public ushort wProcessorArchitecture;
private const uint ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID = 0x001; 7: AddAtom [System.String.Intern] is the closest thing, although an atom is different from a string. 9: AllocConsole This is a simple way to create a "dual-mode" application can be a console or windows forms application.
Console.WriteLine("Just saying 'hi' from the console.. :)") 10: APIGetVersionEx
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(osVersionInfo); // don't forget this line, please! 11: AttachConsole, There might be one, but it is pretty easy and lightweight just to do it this way, in fact there are many wrapper classes out there to do this. But why when you can make your own in about 2 minutes flat? When running an application that is GUI from a console window, you may want to echo something to that console window (such as command line options when the user specifies /? on the command line), but also don't want a console window popping up when you don't need it (such is the behavior of a windows C# 'Console Application'). In this case these work great, and are fully compatible thereafter with the .NET Console.xxx static functions.
To duplicate the 'Console Application' feel, you can use the below code and call AllocateConsole as soon as Main() is called. This will cause it to act just as a console application would normally. Except you have the freedom to not show the console window at all if you don't want to (ie, if you have a /SHOWGUI option, which you prefer never creates a console in the first place).
/// always pass this with AttachConsole in .NET for stability reasons and mainly because
/// I have NOT tested interprocess attaching in .NET so dont blame me if it doesnt work! </summary>
/// Allocate a console if application started from within windows GUI.
This Pinvoke Example was written by Gabriel Sharp from scratch and is property of pinvoke.net, and you may use it however you wish wherever you wish without credit to me. Not that I have to say it but theres alot of this going on: don't take full credit for other people's articles! I see alot of this, and it benefits nobody, and just makes you look like an.. you know Questions or comments on this or other paradisim: [http://paradisim.uuuq.com/ig] 12: AttachConsole There might be one, but it is pretty easy and lightweight just to do it this way, in fact there are many wrapper classes out there to do this. But why when you can make your own in about 2 minutes flat? When running an application that is GUI from a console window, you may want to echo something to that console window (such as command line options when the user specifies /? on the command line), but also don't want a console window popping up when you don't need it (such is the behavior of a windows C# 'Console Application'). In this case these work great, and are fully compatible thereafter with the .NET Console.xxx static functions.
To duplicate the 'Console Application' feel, you can use the below code and call AllocateConsole as soon as Main() is called. This will cause it to act just as a console application would normally. Except you have the freedom to not show the console window at all if you don't want to (ie, if you have a /SHOWGUI option, which you prefer never creates a console in the first place).
/// always pass this with AttachConsole in .NET for stability reasons and mainly because
/// I have NOT tested interprocess attaching in .NET so dont blame me if it doesnt work! </summary>
/// Allocate a console if application started from within windows GUI.
This Pinvoke Example was written by Gabriel Sharp from scratch and is property of pinvoke.net, and you may use it however you wish wherever you wish without credit to me. Not that I have to say it but theres alot of this going on: don't take full credit for other people's articles! I see alot of this, and it benefits nobody, and just makes you look like an.. you know Questions or comments on this snippet you can write me: 14: ClearCommBreak
''' <param name="hFile">The handle into file, a <see cref="CreateFile"/> handle is returning the handle for this.</param> 15: CloseHandle External values of type 'bool' could represent a 1-byte (e.g. C++ bool), 2-byte (e.g. COM VARIANT_BOOL) or 4-byte (e.g. Windows BOOL) value. The distinction is less important for parameters, but for the return, the value would be stored in either (on x86) AL (1 byte), AX (2 bytes) or EAX (4 bytes). By telling interop of the native return type, it knows which parts of EAX to interpret. I understand the conversion between 1 to 4 bytes for the different types of bools. However, isn't [MarshalAs(UnmanagedType.Bool)] the default for marshalling a .NET bool? Therefore making it unnecessary to specify any marshal on the return value. Please let me know if I'm wrong about this. 16: CompareString
Public Const LOCALE_NAME_USER_DEFAULT As String = Nothing 17: ConsoleFunctions This has not been tested and is provided for convenience as a roll-up of the individual console functions here on pinvoke.net into one location.
// HISTORY
// http://pinvoke.net/default.aspx/kernel32/GetConsoleHistoryInfo.html
static extern bool GetConsoleHistoryInfo(
out CONSOLE_HISTORY_INFO ConsoleHistoryInfo
// TODO: Test - what's an out uint[] during interop? This probably isn't quite right, but provides a starting point:
// http://pinvoke.net/default.aspx/kernel32/SetConsoleHistoryInfo.html
static extern bool SetConsoleHistoryInfo(
CONSOLE_HISTORY_INFO ConsoleHistoryInfo
//CHAR_INFO struct, which was a union in the old days
public struct CONSOLE_HISTORY_INFO
ushort HistoryBufferSize;
ushort NumberOfHistoryBuffers; Only fibers can execute other fibers. If a thread needs to execute a fiber, it must call ConvertThreadToFiber or ConvertThreadToFiberEx to create an area in which to save fiber state information. The thread is now the current fiber. The state information for this fiber includes the fiber data specified by lpParameter. To compile an application that uses this function, define WIN32WINNT as 0x0400 or later. 19: COORD
this.X = X;
this.Y = Y; 20: CopyFile
CopyFileEx(oldFile, newFile, new CopyProgressRoutine(this.CopyProgressHandler), IntPtr.Zero, ref pbCancel, CopyFileFlags.COPY_FILE_RESTARTABLE); 21: CopyFileEx
CopyFileEx(oldFile, newFile, new CopyProgressRoutine(this.CopyProgressHandler), IntPtr.Zero, ref pbCancel, CopyFileFlags.COPY_FILE_RESTARTABLE);
* IntPtr.Zero - Since I did not need to pass it on to a child process, I decided to leave this pointer as null.
* 1 - Found this value on the Internet. It worked so I left it there.
* 0 - MSDN documentation says this must be null.
23: CreateEvent
// Create an manual-reset event, which is initially set. The following class object provides some interprocess event signaling style synchronization within the .NET environment. Specifically, using named events, processes can signal each other out of an effecient wait. This reach goes beyond .NET can allow .NET and Win32 processes to signal each other. There are some security issues, in that the default security context of the process is used. NOTE: This class needs some changes. The CloseHandle call will destroy the event when the last handle is closed. This makes it hard for one application to "lock" the event while making another wait on it since this class is always closing the handle. An alternative that I found to work is to have the CreateEvent call in the constructor and implement IDisposable by moving the CloseHandle call to the Dispose method.
/// Win32 security is a critical issue. This class does not support specifically
/// This class is best suitable for processes run in the same security context,
public NamedEvent(string EventName ) : this( EventName, false ) {}
/// Pulse the named event, which results in a single waiting thread to exit the Wait method.
/// Pulse the event with the given name, which results in a single waiting thread to exit the Wait method. I think that in .NET 2.0 the System.Threading.EventWaitHandle class does the same that the example. 24: CreateFiber This function creates fiber in some thread that invoke this function. Fiber executes lpStartAddressFunction. http://blogs.msdn.com/dinoviehland/archive/2004/09/16/230656.aspx 25: CreateFile
uint dwMaximumSizeHigh,
dwMaximumSizeHigh As UInteger, _
private static extern IntPtr CreateFileMapping(IntPtr hFile, IntPtr lpAttributes, FileMapProtection flProtect, Int32 dwMaxSizeHi, Int32 dwMaxSizeLow, string lpName);
int Hi = (Int32)(ddMaxSize / Int32.MaxValue);
return CreateFileMapping(File.SafeFileHandle.DangerousGetHandle(), IntPtr.Zero, flProtect, Hi, Lo, lpName);
private static extern IntPtr MapViewOfFile(IntPtr hFileMapping, FileMapAccess dwDesiredAccess, Int32 dwFileOffsetHigh, Int32 dwFileOffsetLow, Int32 dwNumberOfBytesToMap);
int Hi = (Int32)(ddFileOffset / Int32.MaxValue);
return MapViewOfFile(hFileMapping, dwDesiredAccess, Hi, Lo, dwNumberOfBytesToMap);
internal ushort wProcessorArchitecture;
uint dwMaximumSizeHigh,
dwMaximumSizeHigh As UInteger, _
private static extern IntPtr CreateFileMapping(IntPtr hFile, IntPtr lpAttributes, FileMapProtection flProtect, Int32 dwMaxSizeHi, Int32 dwMaxSizeLow, string lpName);
int Hi = (Int32)(ddMaxSize / Int32.MaxValue);
return CreateFileMapping(File.SafeFileHandle.DangerousGetHandle(), IntPtr.Zero, flProtect, Hi, Lo, lpName);
private static extern IntPtr MapViewOfFile(IntPtr hFileMapping, FileMapAccess dwDesiredAccess, Int32 dwFileOffsetHigh, Int32 dwFileOffsetLow, Int32 dwNumberOfBytesToMap);
int Hi = (Int32)(ddFileOffset / Int32.MaxValue);
return MapViewOfFile(hFileMapping, dwDesiredAccess, Hi, Lo, dwNumberOfBytesToMap);
internal ushort wProcessorArchitecture; 27: CreateHardLink Delphi Prism Signature:28: CreateJobObject
j_handle = CreateJobObject(Nothing, Nothing)
HighMemoryResourceNotification = 1, 30: CreateMutex
/// This value can be returned by CreateMutex() and is found in
// check GetLastError value (MUST use this call. See MSDN)
// already another instance of this application running.
// So, don't allow this instance to run.
// within the frmMain constructor. I tried to format as well as possible, but this thing is a bit weird. If I leave one blank line, this darn thing leaves two. If I leave none, it leaves none. :s This implements a Mutex using a Null DACL (with all the security problems with that). This allows the Mutex to be sharable cross-process. In my implementation I access this Mutex from both ASP.Net and a Windows service running under different ids. I put this together from links on this site as well as searching other sites. Credit to all those who posted to help me implement this.
/// This value can be returned by CreateMutex() and is found in
// Nevertheless, we have nothing to lose by giving it one last try. 31: CreateNamedPipe /* A complete wrapper for named pipes (both client and server sides). Yes, its overkill for this p/invoke entry, but
/// of implementing named pipe support in .Net. (If you doubt this, try it the hard way... we'll wait.)
/// 2. Call Listen(). This will block until a client connects. Sorry, the alternatives
/// And yes, you can attach TextReader and TextWriter instances to this stream.
/// There is a test driver class at the end of this file which can be cannibalized for sample usage code.
ref uint bytesAvail, ref uint BytesLeftThisMessage);
/// instead, which automatically does a disconnect of any old connection.
uint bytesRead = 0, avail = 0, thismsg = 0;
null, 0, ref bytesRead, ref avail, ref thismsg);
while (stream.DataAvailable)
} while (stream.IsConnected);
} while (true); 32: CreateProcess This is great for starting an external app and then using the PID and handle for calls to functions such as WaitForSingleObject and all window message functions. Add this in constructor of a class to logically treat the app as an object. If the approach outlined above does not work verbatim, try the variation by Thottam R. Sriram: http://blogs.msdn.com/thottams/archive/2006/08/11/696013.aspx Here's a sample of using CreateRemoteThread from C#: http://blogs.msdn.com/jmstall/archive/2006/09/28/managed-create-remote-thread.aspx 35: CreateThread Warning: All signatures on this page are wrong as of 2014-01-24. dwStackSize is SIZE_T and ThreadStart has the wrong delegate signature. It only works by coincidence.36: CreateTimerQueue
/// The callback function is invoked by the timer thread itself. This flag should be used only for short tasks or it could affect other timer operations.
/// The callback function is queued to an I/O worker thread. This flag should be used if the function should be executed in a thread that waits in an alertable state.
/// The callback function is queued to a thread that never terminates. It does not guarantee that the same thread is used each time. This flag should be used only for short tasks or it could affect other timer operations.
/// The callback function can perform a long wait. This flag helps the system to decide if it should create a new thread.
/// The timer will be set to the signaled state only once. If this flag is set, the Period parameter must be zero.
/// Callback functions will use the current access token, whether it is a process or impersonation token. If this flag is not specified, callback functions execute only with the process token.
/// Windows XP/2000:  This flag is not supported until Windows XP with SP2 and Windows Server 2003.
/// The callback function is invoked by the timer thread itself. This flag should be used only for short tasks or it could affect other timer operations.
/// The callback function is queued to an I/O worker thread. This flag should be used if the function should be executed in a thread that waits in an alertable state.
/// The callback function is queued to a thread that never terminates. It does not guarantee that the same thread is used each time. This flag should be used only for short tasks or it could affect other timer operations.
/// The callback function can perform a long wait. This flag helps the system to decide if it should create a new thread.
/// The timer will be set to the signaled state only once. If this flag is set, the Period parameter must be zero.
/// Callback functions will use the current access token, whether it is a process or impersonation token. If this flag is not specified, callback functions execute only with the process token.
/// Windows XP/2000:  This flag is not supported until Windows XP with SP2 and Windows Server 2003. You may find that you when calling CreateToolhelp32Snapshot that you must specify SnapshotFlag.NoHeaps in addition to any other flags or you will get an invalid handle and an "Out of Memory" error (ERROR_NOT_ENOUGH_MEMORY = 0x8). This is a seemingly undocumented flag. See the bottom of the MSDN page http://msdn.microsoft.com/en-us/library/windows/desktop/ms682489(v=vs.85).aspx
} while (Process32Next(handleToSnapshot, ref procEntry));
Thread t = new Thread(new ThreadStart(this.NewThread)); 40: DebugBreak 41: DeleteFile In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path or "\\?\UNC\" for fileshares on server, respectively. e.g. "\\?\D:\very long path" or "\\?\UNC\server\share" 42: DeviceIoControl This is great for interacting with devices; now perhaps someone can help with the SetupDi calls to actually discover the device handles, etc...? If you are able to conquer it (I wasn't) toss me a mail at dotnet at richardgoodwin dot com
If DeviceIoControl(hDriver, IOCTL_FARC_GET_CARDID, Nothing, 0, ip, 13, dwBytesReceived, Nothing) Then
DiskHistogramStructure = (EFileDevice.Disk << 16) | (0x000c << 2) | EMethod.Buffered | (0 << 14),
DiskHistogramData = (EFileDevice.Disk << 16) | (0x000d << 2) | EMethod.Buffered | (0 << 14),
DiskHistogramReset = (EFileDevice.Disk << 16) | (0x000e << 2) | EMethod.Buffered | (0 << 14),
DiskGetLengthInfo = (EFileDevice.Disk << 16) | (0x0017 << 2) | EMethod.Buffered | (FileAccess.Read << 14),
FsctlMarkAsSystemHive = (EFileDevice.FileSystem << 16) | (19 << 2) | EMethod.Neither | (0 << 14),
private int mFieldOffset_InternalHigh = 0;
private int mFieldOffset_OffsetHigh = 0;
mFieldOffset_InternalHigh = Marshal.OffsetOf(typeof (NativeOverlapped), "InternalHigh").ToInt32();
mFieldOffset_OffsetHigh = Marshal.OffsetOf(typeof (NativeOverlapped), "OffsetHigh").ToInt32();
public IntPtr InternalHigh
get { return Marshal.ReadIntPtr(mPtrOverlapped, mFieldOffset_InternalHigh); }
set { Marshal.WriteIntPtr(mPtrOverlapped, mFieldOffset_InternalHigh, value); }
public int OffsetHigh
get { return Marshal.ReadInt32(mPtrOverlapped, mFieldOffset_OffsetHigh); }
set { Marshal.WriteInt32(mPtrOverlapped, mFieldOffset_OffsetHigh, value); }
/// Pass this into the DeviceIoControl and GetOverlappedResult APIs
InternalHigh = IntPtr.Zero;
OffsetHigh = 0; Use the above class something like this:
Dim bCylHighReg As Byte ' // IDE high order cylinder value
.bCylHighReg = 0
public uint dwHighDateTime; Sample and signature code originally used System.Runtime.InteropServices.FILETIME, but this uses ints instead of uints (DWORDs) meaning that this line:
long hFT2 = (((long) ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
public uint dwHighDateTime;
//Reference: http://www.aspemporium.com/howto.aspx?hid=26
long longfiletime = (long)(((ulong)filetime.dwHighDateTime << 32) + 44: DuplicateHandle
DUPLICATE_CLOSE_SOURCE = (0x00000001),// Closes the source handle. This occurs regardless of any error status returned. Returns ERROR_SUCCESS on success or an error code on failure. Unless only the primary computer name is requested, the buffer will be filled with a series of null-terminated strings followed by a final null terminator. To measure the required number of characters, not including the final null terminator, use a null buffer and a zero size. This function is similar to GetComputerNameEx, and delegates to it to obtain the primary computer name. The caller may request the primary name only, the alternate names only, or all computer names. Each name returned is a fully qualified DNS name. This function has both ANSI and Unicode versions, but since it only exists on XP and later, the signature shown will always use Unicode.
Dim dll_hInst As IntPtr
dll_hInst = LoadLibraryEx(Filename.Text, 0, 1)
If Not dll_hInst.Equals(IntPtr.Zero) Then
EnumResourceNames(dll_hInst, "AVI", AddressOf EnumResNameProc, IntPtr.Zero)
FreeLibrary(dll_hInst)
static extern bool EnumResourceNamesWithID(
if (EnumResourceNamesWithID(hMod, RT_ICON, new EnumResNameDelegate(EnumRes), IntPtr.Zero) == false)
If IntPtr.Zero.Equals(hMod) Then Return Nothing
If IsNothing(resources) OrElse resources.Length = 0 Then resources = _
Dim SLst As List(Of String) = Nothing I needed to enumerate the installed code pages on a Windows machine, and wanted to present the possible encoding interpretations to a user via a ComboBox. By using the Win32 API ::EnumSystemCodePages() via PInvoke, and the System.Text.Encoding.GetEncoding() static method, I could get the mapping from the code page to an Encoding instance which returns "pretty" names like 'Japanese (Shift-JIS)'.
LOCALE_WINDOWS = 0x00000001, // shipped locales and/or replacements for them
LOCALE_WINDOWS = 0x00000001, // shipped locales and/or replacements for them
LOCALE_IGEOID =0x0000005B, // geographical location id
LOCALE_SCONSOLEFALLBACKNAME =0x0000006e, // Fallback name for within the console
LOCALE_WINDOWS = 0x00000001, // shipped locales and/or replacements for them
LOCALE_WINDOWS = 0x00000001, // shipped locales and/or replacements for them
LOCALE_IGEOID =0x0000005B, // geographical location id
LOCALE_SCONSOLEFALLBACKNAME =0x0000006e, // Fallback name for within the console 51: EnumUILanguages For Windows XP, dwFlags must be 0 (which gets the language ID).
// Do something with langID here... 52: ExitProcess This API is dangerous and you should avoid using it. See MSDN docs for details. System.Environment.ExpandEnvironmentVariables I think
dwHighDateTime = BitConverter.ToInt32(fileTime, 4) this function is contained in "coredll.dll" not "kernel32.dll"
string highDT = string.Format("{0}{1}{2}{3}",
fileTime.dwHighDateTime = int.Parse(highDT, System.Globalization.NumberStyles.HexNumber);
long hFT2 = (((long)fileTime.dwHighDateTime) << 32) | ((uint)fileTime.dwLowDateTime); You really do not need to use this function as you could use the FromFileTime or FromFileTimeUtc on DateTime class. Refer to the sample code provided in the FileTime page. 56: FindAtom [System.String.IsInterned] is the closest thing, although an atom is different from a string. Constants to pass for dwNotifyFilter. Found in winnt.h by searching for the ones used in the msdn example. C++ Language example using this api call. 58: FindFirstFile
while (FindNextFile(hFile, out findData)); The FileInfo() class provides managed access to this information. As with all .NET file handling (as of framework 4) it is constrained in terms of the length of filename allowed. 59: FindFirstFileEx
while (FindNextFile(hFile, out findData)); The FileInfo() class provides managed access to this information. As with all .NET file handling (as of framework 4) it is constrained in terms of the length of filename allowed. 60: FindFirstVolume
} while (FindNextVolume(volumeHandle, volume, bufferLength)); Cut off search results after 60. Please refine your search. |