|
-
Jun 1st, 2010, 05:54 PM
#1
My Windows API Library - New version available for download
EDIT (29/07/2010) : The latest version of this library is available here: http://cjwdev.wordpress.com/2010/07/...2-1-available/
I've been doing a fair amount of work with Windows APIs recently for one reason or another and every time I get one working I add it to a class library that I started months ago and add a managed .NET method that 'wraps' the API and makes it more .NET friendly and easier to reuse. Now that I'm starting to build up a bit of a collection, I thought it would be good to share this class library so that other people can use my managed .NET wrapper methods rather than having to mess about with the Windows APIs directly (I know a lot of people are not keen on doing that).
So in summary: The basic idea is that a developer could add a reference to my DLL and then they would not have to use a lot of Windows APIs directly, they could just call my .NET methods that do all the API work for them. For example one of my wrapper methods named GetTopLevelWindows combines 6 different Windows APIs to return a list of all visible windows with their handle, title bar text, class name, owning process and window icon.
So I'm just looking for some suggestions from people on any particular APIs that they would like to see included in this library. Anything that is a bit of a pain to use and would benefit from a managed version really 
Here is a list of what I've got so far: (EDIT: Updated 29/07/2010)
Managed Methods
RefreshDevices - Causes the OS to refresh its list of connected devices, equivalent to doing "scan for hardware changes" in device manager
GetFreeDiskSpace - Returns the amount of space free on a remote disk, specified via UNC path
GetParentProcess - returns a Process object for the process that started the specified process (aka the parent process)
MapNetworkDrive - creates a network drive mapped to the specified UNC path
RemoveNetworkDrive - deletes an existing mapped network drive
GetUncPathFromNetworkDrive - Returns the UNC path that the specified network drive is mapped to
DoesNativeMethodExist - Determines whether or not a specified method exists in an unmanaged DLL
ShareExistingFolder - shares a folder and assigns the specified share permissions
Is64BitOperatingSystem (property) - Returns true if the OS is 64 bit, even if the process calling this property is running in 32 bit emulation mode.
GetAllIcons - Returns a List(Of Icon) for all of the icons in the specified dll, exe or ico file
GetIconAtIndex - Returns the icon at the specified index in the specified dll, exe or ico file
GetTopLevelWindows - Returns a list of all visible windows with their handle, class name, title bar text, owning process, and window icon
GetChildWindows - Returns a list of all child windows of a specified window, in the same format as GetTopLevelWindows
IsWow64Process - determines whether or not the specified process is a 32 bit process running on a 64 bit OS
ReleaseIpAddresses - releases all IPv4 addresses that were acquired via DHCP
RenewIpAddresses - renews the DHCP lease for all IPv4 addresses that were acquired via DHCP
JoinToDomain - Joins the computer to the specified domain
RemoveFromDomain - Removes the computer from the domain it is joined to (can also be run against a remote computer)
GetStringResource - gets a string from a DLL resource address (e.g @%Systemroot%\system32\wbem\wmisvc.dll,-203)
ReadMemory - reads a specified amount of bytes from another process's virtual memory
GetCommandLineArgs - gets the command line arguments that were passed to any currently running process when it was started (even if it was not started by your program)
GetServices - gets a list of all services that are in the specified state (running, stopped etc) with their process IDs
GetServicesFromProcess - pass in a process and get back a list of any services that are running in that process
FlashWindow - Causes the specified window to flash to get the user's attention
SetWindowState - Make a specified window hide, minimize, maximize, etc
InstallService - Creates a Windows Service with the specified parameters on the local machine or a remote machine
DeleteService - Removes the specified Windows Service from the local machine or a remote machine
EmptyRecycleBin - Empties the recycle bin
GetRecycleBinItemcount - Returns the number of items in the recycle bin
GetRecycleBinSize - Gets the total size of the items in the recycle bin
RenameComputer - Renames the local computer and corresponding domain account
GetWindowFromTitle - Gets a NativeWindow instance for the window with the specified title (NativeWindow instance includes title, owning process, icon, handle etc)
GetWindowsFromPartialTitle - Same as GetWindowFromTitle but finds any windows with the specified string anywhere in their title
GetWindowSize - Gets the size in pixels of any window
GetActiveWindow - Gets the currently active window (aka foreground window)
MakeWindowTopMost - Makes the specified window a topmost window (i.e it stays at the foreground even when not in focus, like task manager)
MakeWindowNotTopMost - Stops a window from being a topmost window if it currently is one
SetParentWindow - Makes the specified window a child of another window
DeleteUserProfile - Removes the specified user's windows profile and settings
Native APIs
GetFreeDiskSpaceEx
WNetCancelConnection
WNetAddConnection2
NetShareAdd
InitializeSecurityDescriptor
SetEntriesInAcl
SetSecurityDescriptorDacl
IsValidSecurityDescriptor
SystemParametersInfo
NetShareAdd
WNetGetConnection
GetProfileType
GetForegroundWindow
ShowWindow
RegisterHotKey
UnregisterHotKey
CM_Reenumerate_DevNode
NtQueryInformationProcess
ExtractIconEx
DestroyIcon
DoesWin32MethodExist
IsWow64Process
GetModuleHandle
GetProcAddress
EnumWindows
EnumChildWindows
GetWindowTextLength
GetWindowText
IsWindowVisible
GetWindowThreadProcessID
GetClassName
SetParent
SendMessage
GetWindowLong
GetClassLong
IpReleaseAddress
IpRenewAddress
GetInterfaceInfo
NetJoinDomain
NetUnjoinDomain
LoadLibrary
FreeLibrary
LoadString
CloseHandle
OpenProcess
ReadProcessMemory
CreateProcess
CreatePipe
PeekNamedPipe
WaitForMultipleObjects
ReadFile
WriteFile
DuplicateHandle
FlashWindowEx
OpenSCManager
EnumServicesStatusEx
CloseServiceHandle
CreateService
DeleteService
OpenService
StartService
SetWindowPos
GetWindowRect
DeleteProfile
SetComputerNameEx
NetRenameMachineInDomain
SHQueryRecycleBin
SHEmptyRecycleBin
GetProfilesDirectory
EnumPwrSchemes
SetActivePwrScheme
GetActivePwrScheme
So yeah... any suggestions that you would like me to add?
Cheers
Chris
Last edited by chris128; Jul 29th, 2010 at 01:38 PM.
-
Jun 1st, 2010, 07:04 PM
#2
Re: My Windows API Pack
BitBlt, GetDC, ReleaseDC, FindWindow(Ex), SetWindowPos, SetParent. EnumWindows and EnumChildWindows especially because I can't get those two to work without an exception.
-
Jun 2nd, 2010, 02:59 AM
#3
Re: My Windows API Pack
Yeah I had some fun with EnumWindows last night... kept getting memory access violations, so I'll try and get that working tonight.
As for SetWindowPos, FindWindow, SetParent - I kind of didnt want to do those because they are relatively simple APIs that I wouldn't really be able to simplify much (if at all) by making a managed wrapper method and there are loads of examples on the internet of how to do them already. I guess I could just include them in the Native API section so people don't have to dig out the definitions and declare them themselves.
-
Jun 2nd, 2010, 12:10 PM
#4
Re: My Windows API Pack
Just looked at 2 of the other APIs you mentioned Minitech, GetDC and ReleaseDC, and I'm not sure how I could make those any simpler either. GetDC just accept a handle to whatever window you want to draw on right? I guess I could make a managed method that avoids the developer having to get the handle to the window - i.e they just pass in the name of a process or the title of a window and the method takes care of finding the handle for it and getting the DC. Is that the kind of thing you were thinking of or did you just mean I should include the definitions for those APIs in the NativeAPI section for people to use directly themselves?
-
Jun 2nd, 2010, 02:03 PM
#5
Re: My Windows API Pack
I was thinking along the lines of "pass in a Control or Process object", and automatically call ReleaseDC() in Finalize().
-
Jun 2nd, 2010, 02:08 PM
#6
Re: My Windows API Pack
Oh right, I was assuming you wanted to call it against external programs but I'm guessing by you saying pass in a Control that you must be referring to the .NET app executing the function? I've not got much (well any) experience with GDI stuff so not sure how well I would be able to design such a function but I dont mind having a go.
Oh and I've got my EnumWindows wrapper method working fine now, although making it a standard synchronous function that just returns a List was fun... because the API uses a callback function to return the results that it calls on another thread, once for every window. Might post a thread about that in a minute actually as I'm not entirely happy with my 'solution'. EDIT: I've since found that this is not the case and the EnumWindows API is synchronous not asynchronous
Last edited by chris128; Jun 3rd, 2010 at 02:06 PM.
-
Jun 2nd, 2010, 02:40 PM
#7
Re: My Windows API Pack
Yeah, having the wrapper for EnumWindows return a List(Of IntPtr) would be great!
-
Jun 2nd, 2010, 03:08 PM
#8
Re: My Windows API Pack
Well I've made it at the moment so it returns a Dictionary(Of IntPtr, String) - the IntPtr is obviously the handle and the String is the title bar text for that window (which I grab via the GetWindowText API) I was going to just return a list of IntPtr but then realised thats not much use as you have no idea which IntPtr (handle) relates to which window, hence the title bar text being included with each item.
I've also currently got it so that it only returns visible windows (by using the IsWindowVisible API), as otherwise I get a massive list of windows that I'm guessing most developers would not be interested in. It still brings back the start menu as a window and a couple of other items that you would not normally class as windows but its nothing compared to the list you get when you dont restrict it to visible windows only.
-
Jun 2nd, 2010, 07:28 PM
#9
Re: My Windows API Pack
Hm, I don't think that's a good idea. But that's just my opinion.
Like, what if you don't know what the text is? I think you should create your own custom class - WindowCollection - from which you can obtain IntPtrs by title text, part of title text, process name, process ID, etc.
-
Jun 3rd, 2010, 02:44 AM
#10
Re: My Windows API Pack
Yeah I had seriously considered that as well, and still am, but even giving you the window text with the handle is more than you would normally get with EnumWindows. Not sure how I would get any process details just from the handle to a window but I'll look into it. EDIT: Actually, looks like I can use GetWindowThreadProcessId for that
Cheers for the suggestions
Last edited by chris128; Jun 3rd, 2010 at 03:49 AM.
-
Jun 3rd, 2010, 03:16 AM
#11
Re: My Windows API Pack
Updated original post to include some of the new APIs and managed methods that I added last night
EDIT: I've also now got my EnumWindows wrapper returning a List(Of ManagedWindow) - where ManagedWindow is my own class that has the following properties: Handle (IntPtr), ClassName (String), Title (String), OwningProcess (Process)
Last edited by chris128; Jun 3rd, 2010 at 08:03 AM.
-
Jun 3rd, 2010, 11:07 AM
#12
Re: My Windows API Pack
How did you get EnumWindows to do that?
... genius.
-
Jun 3rd, 2010, 12:00 PM
#13
Re: My Windows API Pack
Its not the actual API that is returning a List(Of ManagedWindow), its my function that calls the API - but I'm guessing you know that...
I can post the code if you want but its a little long and I'm not 100% happy with the way it works yet - which is what this thread is about: http://www.vbforums.com/showthread.php?t=616959
-
Jun 3rd, 2010, 02:00 PM
#14
Re: My Windows API Pack
Well now that I have got that issue sorted out (was basically just me misunderstanding how the API worked and trying to get around a problem that didnt exist ), here is the code for my EnumWindows wrapper (creatively named GetWindows) if you are interested:
I've not bothered including the API definitions here but you can tell which methods are API calls as they are preceded by NativeAPI.
vb.net Code:
Public Shared Function GetWindows() As List(Of ManagedWindow)
Dim WindowList As New List(Of ManagedWindow)
Dim ListHandle As GCHandle = GCHandle.Alloc(WindowList)
Try
NativeAPI.EnumWindows(New NativeAPI.EnumWindowsProc(AddressOf CallBack), GCHandle.ToIntPtr(ListHandle))
Finally
ListHandle.Free()
End Try
Return WindowList
End Function
Private Shared Function CallBack(ByVal handle As IntPtr, ByVal lParam As IntPtr) As Boolean
If NativeAPI.IsWindowVisible(handle) Then
Dim TitleBuilder As New System.Text.StringBuilder(NativeAPI.GetWindowTextLength(handle) + 1)
Dim WndList As List(Of ManagedWindow) = DirectCast(GCHandle.FromIntPtr(lParam).Target, List(Of ManagedWindow))
NativeAPI.GetWindowText(handle, TitleBuilder, TitleBuilder.Capacity)
Dim ProcessID As Integer = -1
NativeAPI.GetWindowThreadProcessId(handle, ProcessID)
Dim ClassNameBuilder As New System.Text.StringBuilder(255)
NativeAPI.GetClassName(handle, ClassNameBuilder, ClassNameBuilder.Capacity)
WndList.Add(New ManagedWindow(handle, TitleBuilder.ToString, Process.GetProcessById(ProcessID), ClassNameBuilder.ToString))
End If
Return True
End Function
and here's my basic ManagedWindow class:
vb.net Code:
Public Class ManagedWindow
Private _Title As String = String.Empty
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal value As String)
_Title = value
End Set
End Property
Private _Handle As IntPtr
Public Property Handle() As IntPtr
Get
Return _Handle
End Get
Set(ByVal value As IntPtr)
_Handle = value
End Set
End Property
Private _OwningProcess As Process
Public Property OwningProcess() As Process
Get
Return _OwningProcess
End Get
Set(ByVal value As Process)
_OwningProcess = value
End Set
End Property
Private _ClassName As String = String.Empty
Public Property ClassName() As String
Get
Return _ClassName
End Get
Set(ByVal value As String)
_ClassName = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal Hwnd As IntPtr, ByVal TitleText As String, ByVal Owner As Process, ByVal nativeclassname As String)
_Handle = Hwnd
_Title = TitleText
_OwningProcess = Owner
_ClassName = nativeclassname
End Sub
Public Overrides Function ToString() As String
If OwningProcess Is Nothing Then
Return Handle.ToString & " --- " & ClassName & " --- " & Title
Else
Return Handle.ToString & " ---- " & ClassName & " --- " & Title & " ---- " & OwningProcess.ProcessName
End If
End Function
End Class
I'll be adding comments to everything before I make the full project available but hopefully you can tell what that code is doing without them
Last edited by chris128; Jun 3rd, 2010 at 02:10 PM.
-
Jun 3rd, 2010, 02:19 PM
#15
Re: My Windows API Pack
Whoa, I thought it was async too! Well, at least you made it a bit more obvious there.
-
Jun 4th, 2010, 05:37 AM
#16
Re: My Windows API Pack
Yeah well the idea is that someone would just call that GetWindows method instead of having to do all the work that it does every time they wanted to enumerate windows or write their own helper/wrapper method.
e.g:
Code:
For Each Window As ManagedWindow In GetWindows()
MessageBox.Show("Handle: " & Window.Handle.ToString & vbNewLine & _
"Process: " & Window.OwningProcess.ProcessName & vbNewLine & _
"Class: " & Window.ClassName & vbNewLine & _
"Title: " & Window.Title)
Next
I've got EnumChildWindows working in the same way as well now - returning a List(Of ManagedWindow) with all of the relevant info in 
I've included SetParent in the NativeAPI section as well now (cant really think of any way to simplify it with a managed version though) and I'll add FindWindow as you mentioned it earlier - anything else?
Last edited by chris128; Jun 4th, 2010 at 06:02 AM.
-
Jun 5th, 2010, 06:02 PM
#17
Re: My Windows API Pack
Updated list of APIs and wrapper methods in original post now to include some new ones that I've added today for releasing/renewing IP addresses and joining a computer to a domain
-
Jun 6th, 2010, 05:35 PM
#18
Re: My Windows API Pack
 Originally Posted by minitech
BitBlt, GetDC, ReleaseDC, FindWindow(Ex), SetWindowPos, SetParent. EnumWindows and EnumChildWindows especially because I can't get those two to work without an exception.
I just started looking at GetDC and ReleaseDC and although I got them to work and created a Drawing.Graphics object from the DC they retrieved, I found you can do the exact same thing without using APIs by just using Drawing.Graphics.FromHwnd
Or were you using them for some other purpose? I'm just wondering if its worth including those two APIs or not.
-
Jun 7th, 2010, 02:46 PM
#19
Re: My Windows API Pack
... really? Learned something new Guess those aren't necessary.
How about Read/WriteProcessMemory? I'm having trouble with those ones It would be great to provide some good and easy-to-follow documentation on them.
-
Jun 7th, 2010, 03:18 PM
#20
Re: My Windows API Pack
I was going to but I couldn't think of a legit purpose for using them so one problem is that I wouldn't really be able to test it and the second problem is that I dont want to be helping people make malicious software.
Oh and also, I'm just adding FindWindow - do you think its worth making a wrapper method that just lets you specify the window title rather than having to specify the class name as well to make it simpler for people who are not used to using the APIs? Also perhaps an overloaded version that lets you specify the process name (and then obviously it brings back a list of all windows owned by that process, rather than a single window)
-
Jun 7th, 2010, 03:22 PM
#21
Re: My Windows API Pack
I just thought it seemed interesting. I don't have VS Pro, so I can't use the Memory Viewing window, and I wanted to see what memory actually looked like. That's not malicious, right? 
But I agree, there are too many people who would take that and make a game bot or something. I guess you're right.
-
Jun 7th, 2010, 03:30 PM
#22
Re: My Windows API Pack
Well if you are just curious, you can read your own program's memory without using any Windows APIs, just use Runtime.InteropServices.Marshal.ReadByte. All memory looks like though is a series of Bytes - you have to know what each byte corresponds to in that given chunk of memory to be able to make any sense of it. So you could see the same type of thing that you would see when you read memory by simply declaring a Byte array and doing System.Text.Encoding.ASCII.GetBytes - just a series of numbers between 0 and 255 basically, nothing exciting I'm afraid I believe with ReadProcessMemory you just end up with a byte array too, so without documentation of how a particular program stores its in memory data I'm not sure how people actually make any use of it... perhaps just a lot of trial and error but it seems unlikely.
-
Jun 7th, 2010, 03:40 PM
#23
Re: My Windows API Pack
No, I would pass it to System.Text.Encoding.ASCII.GetString, so I could pick out strings in my program's memory. Just for fun. But thanks for the tip!!! I would give you rep, but I can't right now.
-
Jun 9th, 2010, 06:20 PM
#24
Re: My Windows API Pack
Updated original post with several new native and managed APIs that I've added over the last few days 
There's just a few more that I want to get working before I release this but if anyone has any suggestions for additional APIs they would like to see in this then I'll be happy to add them if I can get them working
-
Jun 9th, 2010, 07:35 PM
#25
Re: My Windows API Pack
That's quite a list. Maybe you should consider grouping them? So like:
Code:
Namespace API
Public Module Window
' ...
End Module
Public Module Icons
' ...
End Module
Public Module Process
' ...
End Module
' etc.
End Namespace
-
Jun 10th, 2010, 02:55 AM
#26
Re: My Windows API Pack
Yeah I have well with classes rather than modules but yeah I thought to keep this thread simple I'd just leave them listed as they were before
-
Jun 12th, 2010, 07:07 PM
#27
Re: My Windows API Pack
Perhaps FlashWindowEx()? And maybe the simpler FlashWindow?
I could write the handler for FlashWindow() for you, but FlashWindowEx() would drive me mad.
-
Jun 12th, 2010, 07:52 PM
#28
Re: My Windows API Pack
Ah yeah good call, I'll get FlashWindowEx added in there with a managed wrapper for it (compared to the last couple I've been working on it should be quite straight forward )
-
Jun 12th, 2010, 08:01 PM
#29
Re: My Windows API Pack
I just looked at FlashWindowEx()....I could actually do that one! I feel smart now!
But if you're doing it, I won't bother.
Perhaps you should get on MSN *hint hint*...
-
Jun 12th, 2010, 08:25 PM
#30
Re: My Windows API Pack
Too late I've already done it My managed method can be used like this:
vb Code:
FlashWindow(Me.Handle, FlashItemOption.FlashTitleAndTaskbar, FlashDurationOption.FlashUntilFlashStopSet)
and I've made another named StopFlashWindow (bet you cant guess what that does) :
vb Code:
StopFlashWindow(Me.Handle)
I figured having 2 separate parameters for the FlashWindow method, one for the object to flash (title bar, taskbar or both) and one for the duration of the flash (until StopFlashWindow is called or just until the window gets focus) would be easier for people who aren't familiar with bitwise addition 
Here's my definitions (with comments) if anyone is interested:
vb Code:
<StructLayoutAttribute(LayoutKind.Sequential)> _
Public Structure FLASHWINFO
''' <summary>
''' The size of this structure
''' </summary>
Public cbSize As UInteger
''' <summary>
''' A handle to the window to flash
''' </summary>
''' <remarks></remarks>
Public hwnd As System.IntPtr
''' <summary>
''' The flash parameters that specify what to flash and for how long
''' </summary>
Public dwFlags As UInteger
''' <summary>
''' The number of times to flash the window. 0 = infinite
''' </summary>
Public uCount As UInteger
''' <summary>
''' The length of time between flashes. 0 = OS default
''' </summary>
Public dwTimeout As UInteger
End Structure
''' <summary>
''' Flashes a window to alert the user that it requires attention
''' </summary>
''' <param name="pfwi">A FLASHWINFO structure that specifies parameters for the flash</param>
<DllImportAttribute("user32.dll", EntryPoint:="FlashWindowEx")> _
Public Shared Function FlashWindowEx(<InAttribute()> ByVal pfwi As FLASHWINFO) As <MarshalAsAttribute(UnmanagedType.Bool)> Boolean
End Function
and my managed methods / enums :
vb Code:
''' <summary>
''' Flashes a window to alert a user that it requires attention
''' </summary>
''' <param name="Handle">A handle to the window to flash</param>
''' <param name="Item">The part of the window to flash - title bar, taskbar, or both</param>
''' <param name="Duration">Determines when the flashing stops</param>
Public Shared Sub FlashWindow(ByVal Handle As IntPtr, ByVal Item As FlashItemOption, ByVal Duration As FlashDurationOption)
Dim FlashInfo As New FLASHWINFO
FlashInfo.hwnd = Handle
FlashInfo.dwFlags = Item Or Duration
FlashInfo.cbSize = CUInt(Marshal.SizeOf(FlashInfo))
FlashWindowEx(FlashInfo)
End Sub
''' <summary>
''' Stops a window from flashing
''' </summary>
''' <param name="Handle">A handle to the window to stop flashing</param>
Public Shared Sub StopFlashWindow(ByVal Handle As IntPtr)
Dim FlashInfo As New FLASHWINFO
FlashInfo.hwnd = Handle
FlashInfo.dwFlags = 0 'FLASHW_STOP
FlashInfo.cbSize = CUInt(Marshal.SizeOf(FlashInfo))
FlashWindowEx(FlashInfo)
End Sub
Public Enum FlashItemOption As UInteger
''' <summary>
''' Only flashes the window's title bar and border, not the window's item/icon on the taskbar
''' </summary>
FlashTitleBar = 1
''' <summary>
''' Only flashes the window's item/icon on the taskbar
''' </summary>
FlashTaskbar = 2
''' <summary>
''' Flashes both the item on the taskbar and the window itself.
''' Equivelant to using both FlashTitleBar and FlashTaskbar
''' </summary>
FlashTitleAndTaskbar = 3
End Enum
Public Enum FlashDurationOption As UInteger
''' <summary>
''' Flash until StopFlashWindow is called
''' </summary>
FlashUntilFlashStopSet = 4
''' <summary>
''' Flash until the window has got focus
''' </summary>
FlashUntilWindowActivated = &HC
End Enum
Oh and yeah I'll go on MSN in a minute
-
Jun 14th, 2010, 05:52 PM
#31
Re: My Windows API Pack
Added some new APIs and managed methods today for installing and uninstalling windows services on the local computer or a remote computer 
Once I've done a couple of other windows service related APIs, I'm getting quite close to the end of the ones I can think of to add. Got a couple of random ones to do like one that gets information about the page file(s) and one that turns high contrast mode on, but after that I'm out of ideas really so if anyone has any other suggestions let me know!
-
Jul 2nd, 2010, 03:52 PM
#32
Re: My Windows API Pack
Haven't had much chance over the last week to work on this so I think I'll just tidy some of it up and finish the methods I've already got then release it for others to use as I've had a couple of people asking for it already. I'll stick a link here when it is done
-
Jul 2nd, 2010, 03:53 PM
#33
Re: My Windows API Pack
Just so you know, I'm unable to get FlashWindowEx() to work or the wrapper. It constantly returns false >.<, I don't know why.
-
Jul 2nd, 2010, 04:28 PM
#34
Re: My Windows API Pack
That's odd as it works fine for me - do you mean the code I posted in this thread or the source code I sent you for the API pack?
-
Jul 2nd, 2010, 07:35 PM
#35
-
Jul 3rd, 2010, 07:46 AM
#36
Re: My Windows API Pack
Ah I think I've found the issue - it only seems to work correctly on my machine when I set the program to compile to x64, though I could have sworn I tested it on x86 as I normally do... but I guess I cant have. From a quick glance at the code I cant see why that would be the case but I'll look into it and get it sorted, thanks for letting me know!
-
Jul 3rd, 2010, 07:49 AM
#37
Re: My Windows API Pack
Try this declaration of the API instead -the only difference is that it is using ByRef instead of ByVal and that seems to have got it working on my machine so that it works in both x86 and x64 mode.
vb Code:
''' <summary>
''' Flashes a window to alert the user that it requires attention
''' </summary>
''' <param name="pfwi">A FLASHWINFO structure that specifies parameters for the flash</param>
<DllImportAttribute("user32.dll", EntryPoint:="FlashWindowEx")> _
Public Shared Function FlashWindowEx(<InAttribute()> ByRef pfwi As FLASHWINFO) As <MarshalAsAttribute(UnmanagedType.Bool)> Boolean
End Function
-
Jul 3rd, 2010, 11:44 AM
#38
Re: My Windows API Pack
Perfect. That seemed to work just fine Thanks!
-
Jul 3rd, 2010, 11:53 AM
#39
Re: My Windows API Pack
Just one small point to note: when applying attributes, you can leave the 'Attribute' part out of the type name, e.g.
vb.net Code:
''' <summary>
''' Flashes a window to alert the user that it requires attention
''' </summary>
''' <param name="pfwi">A FLASHWINFO structure that specifies parameters for the flash</param>
<DllImport("user32.dll", EntryPoint:="FlashWindowEx")> _
Public Shared Function FlashWindowEx(<In()> ByRef pfwi As FLASHWINFO) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
-
Jul 3rd, 2010, 12:58 PM
#40
Re: My Windows API Pack
Yeah I was aware of that thanks, I just got into the habit of putting it in because that's how the API viewer that Microsoft released writes it and I used to use that a lot. I never normally include it for DllImport though so no idea why I did in that example...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|