Jump to content
Muryllo

[Resolvido] SendMessage [USER32.DLL]

Recommended Posts

Muryllo

Boas, faz tempo que não posto algo hehe.

Surgiu-me uma dúvida pessoal, eu tenho um serviço do windows e um processo com uma interface, basicamente oque eu preciso fazer é conectar o serviço a interface. Eu tenho um driver a nível de usuário que me ajuda com umas funções e uma biblioteca padrão do meu projeto que tem várias funções. Entre elas a que eu uso para mandar mensagens do Serviço ao processo da interface é o SENDMESSAGE do USER32.DLL

A questão é ... Eu possuo algumas constantes mas não consigo mandá-las, por exemplo : 131 125 191. Quanto ao processo mandar mensagem ao serviço eu já consegui através do ExecuteCommand do ServiceController. Eis aqui o código que eu uso.

Imports System.ServiceProcess
Imports System.Runtime.InteropServices
Public Class Service
<[DllImport]("USER32.DLL", SetLastError:=True)>
Public Shared Function SendMessage(ByVal HWND As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Long
End Function
Public Shared Function GAV_Send_Message(ByVal GAV_Process As String, ByVal GAV_Command As Integer, ByVal GAV_wParam As Integer, ByVal GAV_lParam As Integer) As Boolean
	Try
		Dim GAV_Current_Process As Process() = Process.GetProcessesByName(GAV_Process)
		If SendMessage(GAV_Current_Process(0).MainWindowHandle, GAV_Command, GAV_wParam, GAV_lParam) = 0 Then
			Return True
		Else
			Return False
		End If
	Catch NTSTATUS As Exception
		Return False
	End Try
End Function
Public Function GAV_Service_Execute(ByVal GAV_Service As String, ByVal GAV_Command As Integer) As Boolean
	Try
		Dim GAV_Current_Services As ServiceController() = ServiceController.GetServices
		For Each GAV_Current_Service As ServiceController In GAV_Current_Services
			If GAV_Current_Service.ServiceName = GAV_Service Then
				GAV_Current_Service.ExecuteCommand(GAV_Command)
			End If
			Exit For
		Next
		Return True
	Catch NTSTATUS As Exception
		Return False
	End Try
End Function
End Class

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.