Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Q: SendMessageTimeOut 1

Status
Not open for further replies.

Kostarsus

Programmer
Nov 30, 2000
86
DE
Hi,

Today I'd read an API-Statement in the MSDN, where I have some problems to implement this statement in VB. The statement is like all statements in C++.

Here is the API-Statement:

SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
(LPARAM) "Environment", SMTO_ABORTIFHUNG,
5000, &dwReturnValue);

Well, I've solved the problem of WM_SETTINGCHANGE. It is a problem because this windowmessage isn't in the WinApi32.txt textfile. So I use the message WM_WININICHANGE because it is of the same value. (I'd checked it in the header files of VC++)

Now my problem is the part (LPARAM) "Environment".
VB requires a long-value. You can't cast in VB like in VC++.
Now, any idea which value the 4th parameter should have?
I tried 0 but than the statement throws an error (dwReturnValue was 0)

In reguards and hope for help
Kostarsus
 
From MSDN:

WM_SETTINGCHANGE
The system sends the WM_SETTINGCHANGE message to all top-level windows when theSystemParametersInfo function changes a system-wide setting. The system sends this message only if the SystemParametersInfo caller specifies the SPIF_SENDCHANGE flag.

An application can send WM_SETTINGCHANGE to all top-level windows when it makes changes to system parameters. For example, you can send this message after a call to theWriteProfileString,WriteProfileSection, orSetLocaleInfo functions, or after making changes to system parameters in the registry.

The WM_SETTINGCHANGE message is the same as the older WM_WININICHANGE message.

WM_SETTINGCHANGE
wParam = wFlag; // system-wide parameter flag
lParam = (LPARAM) (LPCTSTR) pszSection; // name of changed section or registry

Parameters
wFlag
Value of wParam. When the system sends the message as a result of aSystemParametersInfo call, this parameter is a flag that indicates the system parameter that was changed. For a list of values, see the SystemParametersInfo function.
When an application sends the message, this parameter must be NULL.

pszMetrics
Value of lParam. Pointer to a string that indicates the area containing the system parameter that was changed. For example, this string can be the name of a registry key or the name of a section in the WIN.INI file.
This parameter is not particularly useful in determining which system parameter changed. For example, when the string is a registry name, it typically indicates only the leaf node in the registry, not the whole path. In addition, some applications send this message with lParam set to NULL. In general, when you receive this message, you should check and reload any system parameter settings that are used by your application.

Return Values
If you process this message, return zero.

Remarks
To send the WM_SETTINGCHANGE message to all top-level windows, use the SendMessageTimeout function with the hwnd parameter set to HWND_BROADCAST.

Calls to functions that change the WIN.INI file might be mapped to the registry instead. This mapping occurs when the WIN.INI file and the section being changed are specified in the registry under the following keys:

HKEY_LOCAL_MACHINE\Software\MicrosoftWindows NT\CurrentVersion\IniFileMapping

The change in the storage location has no effect on the behavior of this message.


-Sean
 
Well,

I read this text, too. But it don't answr my question for the 4th parameter in VB.

cu Kostarsus
 
Your fourth Parameter will be a String passed by value that will contain the path of the Registry value that you changed.

-Sean
 
hi,

but the 4th parameter must be a long not a string value. So it is declared by the API Viewer.

cu Kostarsus
 
When you pass a String by value in VB it is the same as passing it by Pointer in C. A Pointer is a Long. If you note the MSDN Article states that is should be a LPCTSTR.

From MSDN:

LPCTSTR A 32-bit pointer to a constant character string that is portable for Unicode and DBCS.

-Sean
 
Hi,

well if I write ByVal "Registrykey" the compiler throws a type mismatch error.

cu Kostarsus
 
Try taking the defination from the api viewer:

Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long

and editing it so it reads:

Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As String, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long

Then just pass the string to it.

-Sean
 
There are many ways to handle this problem.

The simplest solution is to change the declaration of lParam to String as SeanGriffin suggests. Or you can declare this variable as Any so that you can pass Strings, Longs and other data types as well in this argument if required.

If you do not want to change the declaration then you can also pass a string pointer to this function.
But you have to do a unicode-to-ansi conversion before passing it as a parameter. Something like this;
___
Dim S As String
S = &quot;Environment&quot; '<< This is the registry key name.
S = StrConv(S, vbFromUnicode) 'Convert from Unicode.

SendMessageTimeout HWND_BROADCAST, WM_SETTINGCHANGE, 0, _
StrPtr(S), SMTO_ABORTIFHUNG, 5000, dwReturnValue
 
Thanks, I'd changed the declaration and now it works.

cu Kostarsus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top