Problem creating Registry Keys - VB.NET CF 1.x - Windows Mobile Development and Hacking General

Hi, if i create a registry key i get an NonSupportet Exception.
Can someone Help?
Here the important part of my code:
Code:
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Private Declare Function RegCreateKeyEx Lib "coredll.dll" Alias "RegCreateKeyExW" ( _
ByVal hkey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As String, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
ByRef phkResult As Long, _
ByRef lpdwDisposition As Long) As Long
Public Shared Function CreateNewKey(ByVal lSection As Long, _
ByVal sNewKeyName As String) As Long
Dim hNewKey As Long
Dim lRetVal As Long
RegCloseKey(lSection)
--HERE--> lRetVal = RegCreateKeyEx(lSection, sNewKeyName, 0, _
vbNullString, REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
0, hNewKey, lRetVal)
CreateNewKey = hNewKey
RegCloseKey(hNewKey)
End Function
...
i call for example:
CreateNewKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Today\Items\""Wireless""" )
Please help.
Thanks.

BongoUser said:
Hi, if i create a registry key i get an NonSupportet Exception.
Can someone Help?
Here the important part of my code:
Code:
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Private Declare Function RegCreateKeyEx Lib "coredll.dll" Alias "RegCreateKeyExW" ( _
ByVal hkey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As String, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
ByRef phkResult As Long, _
ByRef lpdwDisposition As Long) As Long
Public Shared Function CreateNewKey(ByVal lSection As Long, _
ByVal sNewKeyName As String) As Long
Dim hNewKey As Long
Dim lRetVal As Long
RegCloseKey(lSection)
--HERE--> lRetVal = RegCreateKeyEx(lSection, sNewKeyName, 0, _
vbNullString, REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
0, hNewKey, lRetVal)
CreateNewKey = hNewKey
RegCloseKey(hNewKey)
End Function
...
i call for example:
CreateNewKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Today\Items\""Wireless""" )
Please help.
Thanks.
Click to expand...
Click to collapse
Hi,
1) I wouldn't use lRetVal for the last parameter and the return function value. The last parameter returns the disposition value and the function return value returns 0 for success or an error that you can find in WINERROR.H and so in MSDN documentation.
If it is not the problem then:
2) In place of trying to create a key in HKLM, try first in HKCU, maybe the problem doesn't reside in the code but in the fact that you are trying to create a key in HKLM where you need "authorization" to do it. Your application needs to have privileges like being signed.
Hope it helps,
Cheers,
.Fred
ps.: use a real program language like C/C++. VB is crap!!!

dotfred said:
Hi,
1) I wouldn't use lRetVal for the last parameter and the return function value. The last parameter returns the disposition value and the function return value returns 0 for success or an error that you can find in WINERROR.H and so in MSDN documentation.
If it is not the problem then:
2) In place of trying to create a key in HKLM, try first in HKCU, maybe the problem doesn't reside in the code but in the fact that you are trying to create a key in HKLM where you need "authorization" to do it. Your application needs to have privileges like being signed.
Hope it helps,
Cheers,
.Fred
ps.: use a real program language like C/C++. VB is crap!!!
Click to expand...
Click to collapse
Hi,
it works nowm thanks.
I have found a working sample in www.

Related

Trapping Hardware buttons

Hi,
anyone know how, or if it is possible to trap the green 'call' button on the xda ii. I can trap the camera, voice recorder and top 2 buttons, but i need to trap the call button
Thanks
Pete
use GetAsyncKeyState
Hi,
tried trapping it in a timer with getasynckeystate , but only seem to pick up the 'd' pad, not any of the other keys.
Using registerhotkey for the other 4 which works fine, just not for the call button
Thanks
Pete
Could you please let me know how you could trap the camera and the two top buttons.
Could you also trap the Red button ?
Many Thanks
Hi,
Paste the following code into a module, and call in in the form_load as follows:-
Dim messageWindow As Hwbuttons.hwMessageWindow
Me.messageWindow = New Hwbuttons.hwMessageWindow(Me)
RegisterHKeys.RegisterRecordKey(Me.messageWindow.Hwnd)
The original code for this comes from www.opennetcf.org - I modified it for my needs, so kudos to the original poster(s).
I have still not found a way to trap the 'green and red' keys
Pete
Imports Microsoft.WindowsCE.Forms
Imports System.Runtime.InteropServices
Public Enum KeyModifiers As Integer
None = 0
Alt = 1
Control = 2
Shift = 4
Windows = 8
Modkeyup = &H1000
End Enum
Public Enum KeysHardware As Integer
Hardware1 = 193
Hardware2 = 194
Hardware3 = 195
Hardware4 = 196
Hardware5 = 202
End Enum
Public Module RegisterHKeys
<DllImport("coredll.dll", Entrypoint:="RegisterHotKey", setLastError:=True)> _
Public Function RegisterHotKey( _
ByVal hWnd As IntPtr, _
ByVal id As Integer, _
ByVal Modifiers As KeyModifiers, _
ByVal key As Integer) As Boolean
End Function
<DllImport("coredll.dll")> _
Private Function UnregisterFunc1( _
ByVal modifiers As KeyModifiers, _
ByVal keyID As Integer) As Boolean
End Function
Public Sub RegisterRecordKey(ByVal hWnd As IntPtr)
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware1, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware1, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware1, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware2, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware2, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware2, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware3, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware3, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware3, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware4, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware4, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware4, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware5, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware5, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware5, Integer))
End Sub
Public Class Hwbuttons
Inherits System.Windows.Forms.Form
Public Shared messageWindow As hwMessageWindow
Public Class hwMessageWindow
Inherits messageWindow
Public Const WM_HOTKEY = &H312
Dim example As frmComms
Public Sub New(ByVal example As frmComms)
Me.example = example
End Sub
Protected Overrides Sub WndProc(ByRef msg As Message)
Select Case msg.Msg
Case WM_HOTKEY
'ButtonPressed(msg.WParam.ToInt32())
Return
End Select
MyBase.WndProc(msg)
End Sub
Public Sub ButtonPressed(ByVal button As Integer)
Select Case button
Case KeysHardware.Hardware1
MessageBox.Show("Button 1 pressed!")
Exit Sub
Case KeysHardware.Hardware2
MessageBox.Show("Button 2 pressed!")
Exit Sub
Case KeysHardware.Hardware3
MessageBox.Show("Button 3 pressed!")
Exit Sub
Case KeysHardware.Hardware4
MessageBox.Show("Button 4 pressed!")
Exit Sub
Case KeysHardware.Hardware5
MessageBox.Show("Button 5 pressed!")
Exit Sub
End Select
End Sub
End Class
End Class
End Module
Many Thanks.
I will give it a go.
Please let me know if you could find a way to control the Green and Red Buttons.
Thanks Again
:lol:
the green+red keys are already registered to the cprog.exe phone app.
you can grab them, by killing cprog.exe and then registering them.
this will prevent the original phone app from starting up.
( it is automatically restarted every minute orso, by shell32.exe )
Hi,
thanks for that - but using PHM task manager I am unable to stop the process from running.
I will take the 'o2active' from the startup and generally poke around to see if i can get it to stop
Thanks
Pete
I mean you should stop it from your own program, using 'TerminateProcess'
see http://www.xs4all.nl/~itsme/projects/xda/tools.html itsutils.cpp
for how to use TerminateProcess
Hi,
thanks - pkill does terminate the process - I thought PHM task manager would work using 'end process' but it does not.
Right - when I kill it, I then start 'button finder' to trap the hardware buttons, but as soon as I hit the green button, cprog relaunches
Thanks for your help
Pete
you should program it your self:
Code:
#define VK_ANSWER 0x72
#define VK_HANGUP 0x73
TerminateProcess(...); // kill cprog.exe
RegisterHotKey(..., 1, 0, VK_ANSWER); // steal hotkey
RegisterHotKey(..., 1, 0, VK_HANGUP); // steal hotkey
Isn't there some win32 way to "steal" messages from another application? If you can do that, you could steal the WM_HOTKEY message from the phone app, that way, you wouldn't have to kill it. I am not sure if killing it would cause you to miss calls or not.
Has anyone posted a clear solution
I have been searching all over the net for a clear solution on hhow to trap these hardware keys and I just can't find anything. Does anyone have a nice clear solution yet?
I have to get the green call key and the red hang up key.
thanks,
Dan
Re: Has anyone posted a clear solution
I've seen several games that intercept "call" and "hang" buttons using GAPI. I have not tested this myself, but you can try.
You can unregister and register the buttons to your own app without killing the phone process, using the same functions as the code pete posted:-
UnregisterFunc1(KeyModifiers.None, CType(KeysHardware.Answer, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Answer, Integer), KeyModifiers.None, CType(KeysHardware.Answer, Integer))
UnregisterFunc1(KeyModifiers.None, CType(KeysHardware.Hangup, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hangup, Integer), KeyModifiers.None, CType(KeysHardware.Hangup, Integer))
Where KeysHardware.Answer = &H72 and KeysHardware.Hangup = &h73
The difference between these two keys and the other hardware keys is they are not sent with the Windows key modifier.
Peter
sorry to bring back this old post, i have tried the code in this thread and successfully capture the green button, but after my application quit how can i restore back the button original function? anyone can help?

little coding help needed

hey folks,
here's what I wanna do:
I need a program that runs in the background and checks if my mda2 is in the cradle or not. if it's plugged in the cradle I want it to change in my connection settings from work to internet. I need this for the following reason: my cellphone provider only offers grps over a proxy and that proxy wount work in the cralde when I share my PC connection via active sync. so right now I always need to switch between work and internet connection by myself.
I only know visual basic so I guess I need to take a look at eVB.
Is such a tool even possible in eVB? if so, where would I start? can someone point me in the right direction? maybe give me some links for research.
thanks for your help in advance
cyas
ait, did some research.
looks like just turning the proxy off should do the trick.
I tried doing this via the registry.
for now I just wanted to read out a key. this is what I got so far:
Code:
Option Explicit
Public Declare Function RegOpenKeyEx Lib "Coredll" Alias "RegOpenKeyExW" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "Coredll" Alias "RegQueryValueExW" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Public Declare Function RegCloseKey Lib "Coredll" (ByVal hKey As Long) As Long
Const ERROR_SUCCESS = &O0
Const HKEY_LOCAL_MACHINE = &H80000001
Private Sub Command1_Click()
Dim lngSize As Long, hlngSubKey As Long
Dim lngType As Long, lngResult As Long
Dim RegData As Integer
lngSize = 256
RegData = String(lngSize, 0)
lngResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\ConnMgr\Providers\{EF097F4C-DC4B-4c98-8FF6-AEF805DC0E8E}\HTTP-{18AD9FBD-F716-ACB6-FD8A-1965DB95B814}", 0, 0, hlngSubKey)
lngResult = RegQueryValueEx(hlngSubKey, "Proxy", 0, lngType, RegData, lngSize)
MsgBox RegData, vbOKOnly, "o2 proxy"
lngResult = RegCloseKey(hlngSubKey)
End Sub
Private Sub Form_OKClick()
App.End
End Sub
unfortunately when I press the button I only get a blank window. it wount show the proxy.
can someone tell me what I'm doing wrong?
oh and I still dont know how I could detect wether there is an active sync connection open or not. any ideas on that?
uhm, no one here who knows some eVB?
_4saken_ said:
Dim RegData As Integer
Click to expand...
Click to collapse
RegData should be declared as
Code:
Dim RegData As String
thanks for the answer but changing it to string didnt help. I still get an empty msg box.
any other ideas what I'm doing wrong?

SetDevicePower questions

i have this code:
<DllImport("coredll")> _
Private Shared Function SetDevicePower(ByVal pvDevice As String, ByVal dwDeviceFlags As Integer, ByVal DeviceState As devicepowerstate) As Integer
End Function
Public Enum devicepowerstate : int
Unspecified = -1
D0 = 0
D1 = 1
D2 = 2
D3 = 3
D4 = 4
End Enum
Const POWER_NAME As Integer = &H1
SetDevicePower("BKL1:", POWER_NAME, devicepowerstate.D3)
when i use D3, my backlight goes DIM (which is what i am aiming for) but when my LCD goes off (idle mode) and then i click on any key to reactivate my DIMMED backlight, the LCD does TURN ON but my backlight stays OFF.
im using it on my T-Mobile SDA WM5.

timer in vb.net cf

I am trying to create a simple stopwatch like app and am having a hard time figuring it out.
in vb.net i can simply use Timer.Start() or Timer.Stop()
This will not work in the .net cf though. I googled the topic for over an hour and did a quick search on the forum and found no result.
Can anyone help me with a way around this, there has to be something simple I am missing or another way to do it. I just need a timer i can start, stop, pause and resume.
Thanks in advance.
Set the timer's Enabled property to true/false.
that works to start and stop it but if i want to pause and then resume it starts from the very begging instead of where it was paused.
ex: pause after 10sec. wait 10sec and hit resume....the timer jumps to 20sec instead of going to 11sec
Why not increment a variable when the timer ticks? Post some sample code here and we could help you debug it....
Do the calculations by using DateTime and TimeSpan.
Code:
Public Class Form1
Dim startTime As DateTime
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
Dim span As TimeSpan = DateTime.Now.Subtract(startTime)
lblTimer.Text = span.Hours.ToString & ":" & span.Minutes.ToString & ":" & span.Seconds.ToString
btnStop.Enabled = True
btnPause.Enabled = True
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
startTime = DateTime.Now()
Timer.Start()
If (Timer.Enabled = True) Then
btnStart.Text = "Restart"
End If
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
If (Timer.Enabled) Then
Timer.Stop()
End If
End Sub
Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
If (Timer.Enabled) Then
Timer.Stop()
btnPause.Text = ("Resume")
Else : Timer.Start()
btnPause.Text = ("Pause")
End If
End Sub
End Class
now the problem is timer.start and timer.stop do not work as they are not included in the cf
I code in C#, but don't you need to declare a variable of type Timer to use it? I don't think there are any static methods for the Timer class.
the above code works fine in the standard .net framework but the start and stop methods are not in the compact framework so i need to find a way around that
Sorry, I got confused with the naming conventions - I thought Timer was a class reference.
Start and Stop works in the full framework, but the logic of your code is wrong - you are always subtracting the _start_ time from the current time when the timer ticks. This is why when you resume, it's still counting how many seconds has passed since you pressed Start.
This should work:
Code:
Public Class Form1
Dim startTime As DateTime
Dim span As TimeSpan
Dim hours, minutes, seconds As Integer
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
span = DateTime.Now.Subtract(startTime)
lblTimer.Text = span.Hours.ToString & ":" & span.Minutes.ToString & ":" & span.Seconds.ToString
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
startTime = DateTime.Now()
Timer.Enabled = True
If (Timer.Enabled = True) Then
btnStart.Text = "Restart"
End If
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Timer.Enabled = False
End Sub
Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
If (Timer.Enabled) Then
Timer.Enabled = False
btnPause.Text = ("Resume")
hours = span.Hours
minutes = span.Minutes
seconds = span.Seconds
Else
startTime = DateTime.Now.Subtract(New TimeSpan(hours, minutes, seconds))
Timer.Enabled = True
btnPause.Text = ("Pause")
End If
End Sub
End Class
Man, coding in VB brings back memories...
...i see your point thanks a lot...as soon as i am done backing the hard drive up in my msi wind i will give this a shot...thanks again

Hiding/showing a form (vb.net)

I am trying to replace my contacts program with one I wrote myself but I'm having a little problem getting the form to hide and then show again?
I would like to start my app from a button, easy enough but I'm a little confused with hiding it again. I can hide the form but if I press the button again nothing happens but I'd like my app to show itself again?
Could someone please help the village idiot and point me in the right direction please?
Ok solved my problem. I used another exe to boot the program and if it was already booted then show the program via the API.
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Module ModMain
<DllImport("coredll")> _
Public Function FindWindow(ByVal lpClass As String, ByVal lpTitle As String) As IntPtr
End Function
<DllImport("CoreDll")> _
Public Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function
<DllImport("CoreDll")> _
Public Function SetForegroundWindow(ByVal hWnd As IntPtr) As Boolean
End Function
Const SW_HIDE As Integer = 0
Const SW_SHOW As Integer = 5
Public Sub Main()
Dim hWnd As Long = FindWindow("#NETCF_AGL_BASE_", "Contacts")
If hWnd = IntPtr.Zero Then
Dim AP As New Process
AP.StartInfo.FileName = "Program Files\ContactsList2\ContactsList2.exe"
AP.Start()
Else
ShowWindow(hWnd, SW_SHOW)
SetForegroundWindow(hWnd)
End If
End Sub
End Module

Categories

Resources