Windows api urlencode - windows

String:
Polo Perú Qatar 2022 - Mujer - Colección Fútbol
I need obtain: Polo+Per%C3%BA+Qatar+2022+-+Mujer+-+Colecci%C3%B3n+F%C3%BAtbol
I need to get the urlencode in windows api or similar. Is there any way?
When I refer to windows api I mean functions similar to these
MessageBox( 0, "Test", "Title here", MB_OK )
GetSystemMetrics( SM_CXSCREEN )
ShellExecute( 0, "open", "c:\myfile.txt", 0, 0, 1 )
Beep( 1000, 250 )
and more...

Related

Perl script for starting a process as another user not working properly

I have a Perl script which uses Win32::API and the command CreateProcessWithLogonW in order to start a process as another user. However, when I run this script from a browser, the following error message appears on the server screen:
"The application failed to initiate properly (0xc0000142). Click on OK to terminate the application."
I have, however, discovered that if I stop Apache as a service and start it directly by double-clicking on httpd.exe, my perl script works without a problem. How can I get it to work when Apache is running as a service?
My code is as follows:
#!C:\usr\bin\perl
use CGI::Carp qw(fatalsToBrowser);
use Win32::API;
sub A2W{ pack 'S*', unpack 'C*', $_[0] }
my $CreateProcessWithLogon = new Win32::API('advapi32.dll', 'CreateProcessWithLogonW', ['P','P','P','P','P','P','P','P','P','P','P'],'N') || return $^E;
my $si = pack('LLLLLLLLLLLL SS LLLL',68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1|0x100, 1, 0, 0, -1, -1, -1);
my $num=$CreateProcessWithLogon->Call(
A2W( 'username' ),
A2W( '\\.\ ' ),
A2W( 'password' ),
0,
0,
A2W( 'myprocess' ),
0,
0,
0,
$si,
chr(0) x 100
) or die $^E;
print "Content-type:text/html\n\n";
print $num;

How can i style my GUI as Aero Glass GUI with AutoIt?

How can i get the Aero Glass effect for my Autoit GUI?
I am playing a bit with AutoIt to increase my knowledge about GUI stuff. Usually i just create scripts without the usage of a GUI, but i would like to have a nice looking areo glass GUI when i just start to work with.
I already experiment with WinSetTrans but this is not exactly what i want. It should look more like the image below.
My current code is:
#include <GUIConstants.au3>
$iWidthGui = 450
$iHeightGui = 300
$hGui = GUICreate("Glass GUI", $iWidthGui, $iHeightGui, -1, -1, -1, $WS_EX_TOPMOST)
$cExit = GUICtrlCreateButton("Exit", $iWidthGui / 2 - 50, $iHeightGui / 2 - 15, 100, 30)
GUISetState( #SW_SHOW )
WinSetTrans($hGui, "", 180)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $cExit
GUIDelete($hGui)
ExitLoop
EndSwitch
WEnd
Is it possible with Autoit? How can i do that?
Yes it is possible. This should work at least for Windows 7. I couldn't test the script on a Windows 10 machine.
Improved code:
#include-once
#include <GUIConstants.au3>
Global $iWidthGui = 450
Global $iHeightGui = 300
Global $hGui = GUICreate("Glass GUI", $iWidthGui, $iHeightGui, -1, -1, -1, $WS_EX_TOPMOST)
Global $cExit = GUICtrlCreateButton("Exit", $iWidthGui / 2 - 50, $iHeightGui / 2 - 15, 100, 30)
GUISetState( #SW_SHOW, $hGui )
Func _aeroGlassEffect( $hWnd, $iLeft = #DesktopWidth, $iRight = #DesktopWidth, $iTop = #DesktopWidth, $iBottom = #DesktopWidth )
$hStruct = DllStructCreate( 'int left; int right; int height; int bottom;' )
DllStructSetData( $hStruct, 'left', $iLeft )
DllStructSetData( $hStruct, 'right', $iRight )
DllStructSetData( $hStruct, 'height', $iTop )
DllStructSetData( $hStruct, 'bottom', $iBottom )
GUISetBkColor( '0x000000' )
Return DllCall( 'dwmapi.dll', 'int', 'DwmExtendFrameIntoClientArea', 'hWnd', $hWnd, 'ptr', DllStructGetPtr( $hStruct ) )
EndFunc
_aeroGlassEffect( $hGui )
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $cExit
GUIDelete($hGui)
ExitLoop
EndSwitch
WEnd
I switched WinSetTrans() for _aeroGlassEffect(). You can change the function parameters $iLeft, $iRight, $iTop, $iBottom.

MQL4 - ERROR 4111 when calling OrderSend() method

I am trying to place order, but my call to OrderSend() method ( https://docs.mql4.com/trading/ordersend )is failing:
2016.08.01 00:51:09.710 2016.07.01 01:00 s EURUSD,M1: OrderSend error 4111
void OnTick() {
if ( OrdersTotal() == 0 ){
int result = OrderSend( NULL, OP_SELL, 0.01, Bid, 5, 0, Bid - 0.002, NULL, 0, 0, clrGreen );
if ( result < 0 ) Print( "Order failed #", GetLastError() );
else Print( "Order success" );
}
}
Do you know what am I doing wrong please?
Let's dis-assemble the OrderSend() call first:
int result = OrderSend( NULL, // string: _Symbol,
OP_SELL, // int: OP_SELL,
0.01, // double: NormalizeLOTs( nLOTs ),
Bid, // double: NormalizeDouble( Bid, Digits ),
5, // int: slippagePOINTs,
0, // double: { 0 | NormalizeDouble( aSlPriceTARGET, Digits ) },
Bid-0.002, // double: { 0 | NormalizeDouble( aTpPriceTARGET, Digits ) },
NULL, // string: { NULL | aBrokerUnguaranteedStringCOMMENT },
0, // int: { 0 | aMagicNUMBER },
0, // datetime: { 0 | aPendingOrderEXPIRATION },
clrGreen // color: { clrNONE | aMarkerCOLOR }
);
For one's further peace-of-mind, one ought always normalise all the values, that have some restrictive handling on the MQL4-side ( prices + lot ( quantised ) values -- as these are not continuous values in R domain, but rather quantum-stepped:
prices: having a 0.00001 or 0.0001 or 0.001 or 0.01 or 0.1 or 1.0 etc. stepping,
lot-volumes: being more restricted by the Broker-specific settings, per instrument, of three key values, all allowable volume sizes have to meet: [aMinLOTs<=, +aMinLotSTEP, <=aMaxLOTs] + a proper digit normalisation~ thus a double NormalizeLOTs( aProposedVOLUME ) {...} is a handy tool for a seamless implementation of both parts of this need.
Error 4111:
There are a few other barriers, that prevent your MetaTrader Terminal 4 from running your code smooth:
4111
ERR_SHORTS_NOT_ALLOWED
Shorts are not allowed. Check the Expert Advisor properties
if ( !TerminalInfoInteger( TERMINAL_TRADE_ALLOWED ) )
Alert( "Check if automated trading is allowed in the terminal settings!" );
else if ( !MQLInfoInteger( MQL_TRADE_ALLOWED ) )
Alert( "Automated trading is forbidden in the program settings for ",
__FILE__
);
This instructs user to revise MetaTrader Terminal 4 settings,under MT4 -> Tools -> Options -> ExpertAdvisor Taband Broker-side Trading Instrument conditions, where shorting for some instruments may be restricted in general, or just for certain Account type(s).
if ( !AccountInfoInteger( ACCOUNT_TRADE_EXPERT ) )
Alert( "Automated trading is forbidden for the account",
AccountInfoInteger( ACCOUNT_LOGIN ),
" at the trade server side. Contact Broker's Customer Care Dept."
);
For more details, printScreens and demonstrated programmatic handling of this group of both Terminal-side / Broker-side barriers: ref.-> MQL4 Reference / MQL4 programs / Trade Permission

Unable to create StatusBar in Visual C++ express 2010 using plain win32 api

I am using plain Win32 API (no MFC I mean) to create a simple app. I use CreateWindowEx with STATUSCLASSNAME as specified in MSDN but the handle returned is NULL. I made a call to InitCommonControlsEx as indicated but that returns FALSE! So I suspect that's the reason why the bar isn't created. What's going on? Please help.
I am on Windows 7 64 bit.
hStatusBar = ::CreateWindowExW(
0,
L"STATUSCLASSNAME",
L"",
WS_VISIBLE|WS_CHILD|WS_BORDER,
0,0,0,0, hWnd, 0, hInstance, NULL
);
There is one simple mistake in your code. STATUSCLASSNAME is not a value this is a constant from < commctrl.h >. So you code actually should looks like this:
#include <commctrl.h>
.
.
.
hStatusBar = ::CreateWindowExW(
0,
STATUSCLASSNAME,
L"",
WS_VISIBLE|WS_CHILD|WS_BORDER,
0,0,0,0, hWnd, 0, hInstance, NULL
);
I suppose you was looking into this http://msdn.microsoft.com/en-us/library/bb775491%28v=VS.85%29.aspx#STATUSCLASSNAME but as it specified, there are constants in the left column not values
if you are using W (wide) chars and functions you have to change constant name (see inside commcrtl.h). I used:
status = CreateWindowExW(0, STATUSCLASSNAMEW,
L"Spec.chars fine - Czech=Česky", WS_VISIBLE | WS_CHILD | WS_BORDER,
0, 0, 0, 0, hwnd, 0, NULL, NULL);
and is seems to be ok.

How to get COM object for embedded IE browser?

How to translate this function from AutoIt's IE.au3 UDF to Ruby? Intention is to use Watir with an Internet Explorer browser (embedded in another application).
The AutoIt function works fine but I prefer Watir (which is Ruby). I can get the handle of the embedded browser using ControlGetHandle(), which is not available from the AutoIt dll.
Below is the function to translate (also 2 others which I don't need).
;===============================================================================
;
; Function Name: __IEControlGetObjFromHWND()
; Description: Returns a COM Object Window reference to an embebedded Webbrowser control
; Parameter(s): $hWin - HWND of a Internet Explorer_Server1 control obtained for example:
; $hwnd = ControlGetHandle("MyApp","","Internet Explorer_Server1")
; Requirement(s): Windows XP, Windows 2003 or higher.
; Windows 2000; Windows 98; Windows ME; Windows NT may install the
; Microsoft Active Accessibility 2.0 Redistributable:
; http://www.microsoft.com/downloads/details.aspx?FamilyId=9B14F6E1-888A-4F1D-B1A1-DA08EE4077DF&displaylang=en
; Return Value(s): On Success - Returns DOM Window object
; On Failure - 0 and sets #ERROR = 1
; Author(s): Larry with thanks to Valik
;
;===============================================================================
Func __IEControlGetObjFromHWND(ByRef $hWin)
DllCall("ole32.dll", "int", "CoInitialize", "ptr", 0)
Local Const $WM_HTML_GETOBJECT = __IERegisterWindowMessage("WM_HTML_GETOBJECT")
Local Const $SMTO_ABORTIFHUNG = 0x0002
Local $lResult, $typUUID, $aRet, $oIE
MsgBox(0, "msg", $WM_HTML_GETOBJECT)
__IESendMessageTimeout($hWin, $WM_HTML_GETOBJECT, 0, 0, $SMTO_ABORTIFHUNG, 1000, $lResult)
$typUUID = DllStructCreate("int;short;short;byte[8]")
DllStructSetData($typUUID, 1, 0x626FC520)
DllStructSetData($typUUID, 2, 0xA41E)
DllStructSetData($typUUID, 3, 0x11CF)
DllStructSetData($typUUID, 4, 0xA7, 1)
DllStructSetData($typUUID, 4, 0x31, 2)
DllStructSetData($typUUID, 4, 0x0, 3)
DllStructSetData($typUUID, 4, 0xA0, 4)
DllStructSetData($typUUID, 4, 0xC9, 5)
DllStructSetData($typUUID, 4, 0x8, 6)
DllStructSetData($typUUID, 4, 0x26, 7)
DllStructSetData($typUUID, 4, 0x37, 8)
MsgBox(0, "lResult", $lResult)
$aRet = DllCall("oleacc.dll", "long", "ObjectFromLresult", "lresult", $lResult, "ptr", DllStructGetPtr($typUUID), _
"wparam", 0, "idispatch*", 0)
MsgBox(0, "aRet4", $aRet[4])
If IsObj($aRet[4]) Then
$oIE = $aRet[4] .Script()
; $oIE is now a valid IDispatch object
Return $oIE.Document.parentwindow
Else
SetError(1)
Return 0
EndIf
EndFunc ;==>__IEControlGetObjFromHWND
;===============================================================================
; Function Name: __IERegisterWindowMessage()
; Description: Required by __IEControlGetObjFromHWND()
; Author(s): Larry with thanks to Valik
;===============================================================================
Func __IERegisterWindowMessage($sMsg)
Local $aRet = DllCall("user32.dll", "int", "RegisterWindowMessage", "str", $sMsg)
If #error Then Return SetError(#error, #extended, 0)
Return $aRet[0]
EndFunc ;==>__IERegisterWindowMessage
;===============================================================================
; Function Name: __IESendMessageTimeout()
; Description: Required by __IEControlGetObjFromHWND()
; Author(s): Larry with thanks to Valik
;===============================================================================
Func __IESendMessageTimeout($hWnd, $msg, $wParam, $lParam, $nFlags, $nTimeout, ByRef $vOut, $r = 0, $t1 = "int", $t2 = "int")
Local $aRet
$aRet = DllCall("user32.dll", "long", "SendMessageTimeout", "hwnd", $hWnd, "int", $msg, $t1, $wParam, _
$t2, $lParam, "int", $nFlags, "int", $nTimeout, "int*", "")
If #error Then
$vOut = 0
Return SetError(#error, #extended, 0)
EndIf
$vOut = $aRet[7]
If $r >= 0 And $r <= 4 Then Return $aRet[$r]
Return $aRet
EndFunc ;==>__IESendMessageTimeout
My code so far:
def get_control_from_hwnd(hnd)
Win32API.new("ole32", "CoInitialize", ['P'] , 'I').call(0)
reg_msg = Win32API.new("user32", "RegisterWindowMessage", ['P'] ,'I').call("WM_HTML_GETOBJECT")
puts "msg: " + reg_msg.to_s
result=" "*16
aInt = [0xA7, 0x31, 0x0, 0xA0, 0xC9, 0x8, 0x26, 0x37].pack 'I*'
a = [0x626FC520, 0xA41E, 0x11CF, aInt].pack 'IIIP'
sendMessagetimeout = Win32API.new("user32", "SendMessageTimeout", ['L','I','I','I','I','I','P'] , 'L')
sendMessagetimeout.call(hnd.hex, reg_msg, 0, 0, SMTO_ABORTIFHUNG, 1000, result)
puts "result unpacked: " + result.unpack("L").to_s #i can confirm this is the same as the lResult from the autoit functioin
idisp=0
#the problem is likely either here or the next line afterwards
oIE = Win32API.new("oleacc", "ObjectFromLresult", ['P','P','I','P'] , 'L')
oIE.call(result, a, 0, idisp)
puts "idisp: " + idisp.to_s
# returning zero
puts idisp.unpack("L")
end
Can't believe we are doing the same, albeit I'm trying to do it in Perl. I dunno Ruby but looking at the script, it almost looks like similar to Perl. Take a look at this thread at autoIt, where I am still trying to tackle the issue http://www.autoitscript.com/forum/index.php?showtopic=104894. But I think I might have gotten the idisp though. Two changes:
1) The way I am packing the struct is a bit different. My $iid looks like this:
pack('LSSC8',0x626FC520,0xA41E,0x11CF,0xA7,0x31,0x00,0xA0,0xC9,0x08,0x26,0x37). So in Ruby I guess it'd be [0x626FC520,0xA41E,0x11CF,0xA7,0x31,0x00,0xA0,0xC9,0x08,0x26,0x37].pack 'LSSC8'? I dunno the right syntax, but you get the idea.
2) I unpack the "result" from SendMessageTimeout & then pass it to ObjectFromLresult. If I pass the result directly, I get 0 as you were getting it.
But that is as far as I've gone.

Resources