Skysnake

DllCall() with C example

15 posts in this topic

#1 ·  Posted (edited)

bool SMSAPI_sendsms(
const LPSMSAPI_NETWORKCONFIGURATION lpNetConfig, 
const LPSMSAPI_ACCOUNTINFO lpAccInfo, 
const LPSMSAPI_MESSAGEINFO lpMsgInfo, 
LPSMSAPI_RESPONSEINFO lpResponseInfo);

The previous posts:

struct in dllcall and my attempt plus documentation

I have put everything I have come up with on the forum.  I need help.  I do not understand the syntax, nor the process.  

The idea is to have a simple little GUI with two options, one for config (such as server name account name and password)

and the second with a simple input for SMS destination number and the message...

Problem is, I dont know how to do that.  Obviously once the basics are done, this kind of integration can go anywhere...

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

I got registered on that page but the y don't send me any code (maybe because I from South America) 

Also I notice you can use the web API for send message. (look easier than Desltop App API)

Saludos

 

Share this post


Link to post
Share on other sites

Dany, perhaps because you are not in an area where they have a server?

If you are keen I can send you my credentials and you can have a look?  PM?

Thank you for the response. Much appreciated.


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

The name of the function that you'd call from the dll is "smsapi_sendsms" and not "SMSAPI_sendsms" nor "sms_sendsms".
Same goes for any other function that you tried to call. 

Go back to Danyfirex's code and change the function's names.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Thx, but it is more involved than that.  See the "const" item in the Dllcall...?  What does that translate as ?  This is a complex example and the name of the function is a small part of it.

I will do as suggested. Thank you


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

"Const" is irrelevant for you.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

What confuses me is why would you even consider using third party dll to access SMS API interface. It's obviously only a thin wrapper around something as simple as this:

#include "Crypt.au3"
#include "WinHttp.au3"


$sFrom = "Info" ; what goes here?
$sTo = "555555" ; some phone number?
$sMessage = "Test Message Text. Works?"

$sRet = SMS_Send($sFrom, $sTo, $sMessage)
ConsoleWrite("Error = " & @error & ", Response code = " & @extended & @CRLF)
ConsoleWrite("> Returned = " & $sRet & @CRLF)



Func SMS_Send($sFrom, $sTo, $sMessage, $fBackup = False)
    Local Const $sAddress = $fBackup ? "https://api2.smsapi.com/sms.do" : "https://api.smsapi.com/sms.do"
    Local Const $sUserName = "you@whatever.com" ; account mail here
    Local Const $sPassword = "password" ; your password

    ; Construct the form (API's post method)
    Local Const $sForm = _
            '<form action="' & $sAddress & '" method="post" enctype="multipart/form-data">' & _
            ' <input name="username"/>' & _ ;
            ' <input name="password"/>' & _
            ' <input name="from"/>' & _
            ' <input name="to"/>' & _
            ' <input name="message"/>' & _
            '</form>'

    ; Initialize and get session handle
    Local $hOpen = _WinHttpOpen()
    ; Get connection handle
    Local $hConnect = $sForm
    ; Fill the form
    Local $sRead = _WinHttpSimpleFormFill($hConnect, $hOpen, _
            Default, _ ; location of the form
            "name:username", $sUserName, _
            "name:password", Hex(_Crypt_HashData($sPassword, $CALG_MD5)), _
            "name:from", $sFrom, _
            "name:to", $sTo, _
            "name:message", $sMessage)
    ; Collect error number and HTTP status code
    Local $iErr = @error, $iStatus = @extended

    If $iStatus <> $HTTP_STATUS_OK And Not $fBackup Then
        $sRead = SMS_Send($sFrom, $sTo, $sMessage, True)
        $iErr = @error
        $iStatus = @extended
    EndIf

    ; Close handles
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

    Return SetError($iErr, $iStatus, $sRead)
EndFunc

By using dll you just make your life harder.

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

It confuses me because I can not code.  I do not understand C.  I can not make a C app and put the code into whatever I am doing.  I do not even understand what I am looking at.  If you say ""Const" is irrelevant for you." then I can only agree because I do not have the knowledge nor insight to argue.  I use AutoIt as a tool to automate reports in my office.  And I can do lots of things easily and quickly that used to take hours.  Learning AutoIt is a hobby.  I simply do not have the time to learn C.  Reality is such a hassle.  Problem is, in order to increase the potential benefit to be derived from AutoIt I need to use new tools, one of which is a 3rd Party DLL such as that under discussion.

As far as the HTTP sender is concerned, it works, I have done it manually and it is ugly.  The reason for using  the smsdll is simple, once developed it can be integrated almost anywhere and seamlessly integrate into future projects.

I presume you are an engineer or software developer.  You have been trained to deal with this and for you a simple DllCall is trivial.  My background is very different and far removed from software development.  For me it presents an almost insurmountable challenge.  I can not even tell whether "const" is an issue or not.

Thank you kindly for the code above.  I will experiment. with it.  If it means anything, I have an existing BulkSMS account loaded with credits.  I just can't get it to work with such code as I have written (and posted here).

Thanks again for taking the time to read and the patience to provide an answer.  I really do appreciate.

S


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@Trancexx I ran your code :) 

Error = 0, Response code = 200
> Returned = ERROR:101

 

The reason is that your code is designed for smsapi, while I am trying to runb with BulkSMS.

smsapi and BulkSMS are not the same.  Bear in mind practical issues like non-availability in the target area

 

I will keep on playing.  Maybe you are right.  Maybe I am trying to overkill.  This is obviously much easier and I understand the code :) 

By using dll you just make your life harder.

 

Seems you are right :)

 

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

That one seems even simpler.

#include "WinHttp.au3"


$sTo = "5555555554" ; some phone number?
$sMessage = "Test Message Text. Works?"

$sRet = SMS_Send($sTo, $sMessage)
ConsoleWrite("Error = " & @error & ", Response code = " & @extended & @CRLF)
ConsoleWrite("> Returned = " & $sRet & @CRLF)



Func SMS_Send($sTo, $sMessage)
    Local Const $sAddress = "https://bulksms.vsms.net/eapi/submission/send_sms/2/2.0" ; your's here
    Local Const $sUserName = "you" ; your user name
    Local Const $sPassword = "password" ; your password

    ; Construct the form (API's post method)
    Local Const $sForm = _
            '<form action="' & $sAddress & '" method="post" enctype="application/x-www-form-urlencoded">' & _
            ' <input name="username"/>' & _ ;
            ' <input name="password"/>' & _
            ' <input name="msisdn"/>' & _
            ' <input name="message"/>' & _
            '</form>'

    ; Initialize and get session handle
    Local $hOpen = _WinHttpOpen()
    ; Get connection handle
    Local $hConnect = $sForm
    ; Fill the form
    Local $sRead = _WinHttpSimpleFormFill($hConnect, $hOpen, _
            Default, _ ; location of the form
            "name:username", $sUserName, _
            "name:password", $sPassword, _
            "name:msisdn", $sTo, _
            "name:message", $sMessage)
    ; Collect error number and HTTP status code
    Local $iErr = @error, $iStatus = @extended

    ; Close handles
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

    Return SetError($iErr, $iStatus, $sRead)
EndFunc

 

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

wow.

I go to https://www.smsapi.com/contact and what I see this is Polish product: https://www.smsapi.pl/
I was using this 2 years ago.

even here:

https://www.smsapi.com/rest

you can see in example #2:

$password 'password-md5');               //lub $password = md5('open-text-password'),

lub >> or 

$password 'password-md5');               //or $password = md5('open-text-password'),

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Here is my full UDF 

_Example()
Func _Example()

    _SMSApi_URL('https://api.smsapi.com/sms.do')
    _SMSApi_UserName('my@email.pl')
    _SMSApi_Password('SOMEPASSWORDINMD5')
    Local $output = _SMSApi_Sender('Eco', '48502xxxxxx', 'Hello World.'.)
    ConsoleWrite(_SMSApi_Error($output) & @CRLF)
EndFunc

Func _SMSApi_Password($vPassword_Param = Default)
    Local Static $sPassword = ''
    If $vPassword_Param = Default Then
        Return SetError(0,0,$sPassword)
    ElseIf IsString($vPassword_Param) Then
        $sPassword = $vPassword_Param
        Return SetError(0,1,$sPassword)
    Else
        Return SetError(1,0,$sPassword)
    EndIf
EndFunc

Func _SMSApi_UserName($vUserName_Param = Default)
    Local Static $sUserName = ''
    If $vUserName_Param = Default Then
        Return SetError(0,0,$sUserName)
    ElseIf IsString($vUserName_Param) Then
        $sUserName = $vUserName_Param
        Return SetError(0,1,$sUserName)
    Else
        Return SetError(1,0,$sUserName)
    EndIf
EndFunc

Func _SMSApi_URL($vURL_Param = Default)
    Local Static $sURL = 'https://ssl.smsapi.pl/sms.do'
    If $vURL_Param = Default Then
        Return SetError(0,0,$sURL)
    ElseIf IsString($vURL_Param) Then
        $sURL = $vURL_Param
        Return SetError(0,1,$sURL)
    Else
        Return SetError(1,0,$sURL)
    EndIf
EndFunc

Func _SMSApi_Sender($sSenderName, $sRecipient, $sSmsMessage)
;~  https://ssl.smsapi.pl/sms.do?username=uzytkownik&password=hasloMD5&from=nazwa&to=48500XXX000&message=test wiadomosci
;~  https://ssl.smsapi.pl/sms.do?username=USERNEAME&password=PASSWORDMD5&from=SENDERNAME&to=RECIPIENT&message=SMS_MESSAGE

    If $sSenderName = Default Then $sSenderName = "INFO"
    Local $sURL
    $sURL = _SMSApi_URL()
    $sURL &= '?username=' & _SMSApi_UserName() & '&password=' & _SMSApi_Password()
    $sURL &= '&from=' & $sSenderName & '&to=' & $sRecipient
    $sURL &= '&message=' & $sSmsMessage

    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output
EndFunc   ;==>_SMSApi_Sender

Func _SMSApi_Status($iStatus)
    Local $sDescription_1
    Local $sDescription_2
    Switch Number($iStatus)
        Case 401
            $sDescription_1 = 'Nie istnieje'
            $sDescription_2 = 'Błędny numer ID wiadomości lub raport wygasł.'
        Case 402
            $sDescription_1 = 'Przedawniona'
            $sDescription_2 = 'Wiadomość niedostarczona z powodu zbyt długiego czasu niedostępność numeru.'
        Case 403
            $sDescription_1 = 'Wysłana'
            $sDescription_2 = 'Wiadomość została wysłana ale operator nie zwrócił jeszcze raportu doręczenia.'
        Case 404
            $sDescription_1 = 'Dostarczona'
            $sDescription_2 = 'Wiadomość dotarła do odbiorcy.'
        Case 405
            $sDescription_1 = 'Niedostarczona'
            $sDescription_2 = 'Wiadomość niedostarczona (np.: błędny numer, numer niedostępny).'
        Case 406
            $sDescription_1 = 'Nieudana'
            $sDescription_2 = 'Błąd podczas wysyłki wiadomości (prosimy o zgłoszenie problemu).'
        Case 408
            $sDescription_1 = 'Nieznany'
            $sDescription_2 = 'Brak raportu doręczenia dla wiadomości.'
        Case 409
            $sDescription_1 = 'Kolejka'
            $sDescription_2 = 'Wiadomość zaplanowana.'
        Case 410
            $sDescription_1 = 'Zaakceptowana'
            $sDescription_2 = 'Wiadomość przyjęta przez operatora.'
        Case 411
            $sDescription_1 = 'Ponawianie'
            $sDescription_2 = 'Wykonana była próba połączenia która nie została odebrana, połączenie zostanie ponowione.'
    EndSwitch
    Return $iStatus & ': ' & $sDescription_1 & ': ' & $sDescription_2
EndFunc   ;==>_SMSApi_Status

Func _SMSApi_Error($sError)
    Local $sDescription
    Switch $sError
        Case 'ERROR:8'
            $sDescription = 'Błąd w odwołaniu (Prosimy zgłosić)'
        Case 'ERROR:11'
            $sDescription = 'Zbyt długa lub brak wiadomości lub ustawiono parametr nounicode i pojawiły się znaki specjalne w wiadomości. Dla wysyłki VMS błąd oznacza brak pliku WAV lub treści TTS.'
        Case 'ERROR:12'
            $sDescription = 'Wiadomość zawiera ponad 160 znaków (gdy użyty parametr &single=1).'
        Case 'ERROR:13'
            $sDescription = 'Brak prawidłowych numerów telefonów (numery błędne, znajdujące się na czarnej liście lub zagraniczne przy wyłączonej opcji wysyłki za granicę).'
        Case 'ERROR:14'
            $sDescription = 'Nieprawidłowe pole nadawcy.'
        Case 'ERROR:17'
            $sDescription = 'Nie można wysłać FLASH ze znakami specjalnymi.'
        Case 'ERROR:18'
            $sDescription = 'Nieprawidłowa liczba parametrów.'
        Case 'ERROR:19'
            $sDescription = 'Za dużo wiadomości w jednym odwołaniu.'
        Case 'ERROR:20'
            $sDescription = 'Nieprawidłowa liczba parametrów IDX.'
        Case 'ERROR:21'
            $sDescription = 'Wiadomość MMS ma za duży rozmiar (maksymalnie 300kB).'
        Case 'ERROR:22'
            $sDescription = 'Błędny format SMIL.'
        Case 'ERROR:23'
            $sDescription = 'Błąd pobierania pliku dla wiadomości MMS lub VMS.'
        Case 'ERROR:24'
            $sDescription = 'Błędny format pobieranego pliku.'
        Case 'ERROR:25'
            $sDescription = 'Parametry &normalize oraz &datacoding nie mogą być używane jednocześnie.'
        Case 'ERROR:26'
            $sDescription = 'Za długi temat wiadomości. Temat może zawierać maksymalnie 30 znaków.'
        Case 'ERROR:27'
            $sDescription = 'Parametr IDX za długi. Maksymalnie 255 znaków.'
        Case 'ERROR:30'
            $sDescription = 'Brak parametru UDH jak podany jest datacoding=bin.'
        Case 'ERROR:31'
            $sDescription = 'Błąd konwersji TTS'
        Case 'ERROR:32'
            $sDescription = 'Nie można wysyłać wiadomości Eco, MMS i VMS na zagraniczne numery.'
        Case 'ERROR:33'
            $sDescription = 'Brak poprawnych numerów.'
        Case 'ERROR:35'
            $sDescription = 'Błędna wartość parametru tts_lector. Dostępne wartości: agnieszka, ewa, jacek, jan, maja.'
        Case 'ERROR:36'
            $sDescription = 'Nie można wysyłać wiadomości binarnych z ustawioną stopką.'
        Case 'ERROR:40'
            $sDescription = 'Brak grupy o podanej nazwie'
        Case 'ERROR:41'
            $sDescription = 'Wybrana grupa jest pusta (brak kontaktów w grupie).'
        Case 'ERROR:50'
            $sDescription = 'Nie można zaplanować wysyłki na więcej niż 3 miesiące w przyszłość.'
        Case 'ERROR:51'
            $sDescription = 'Ustawiono błędną godzinę wysyłki, wiadomość VMS mogą być wysyłane tylko pomiędzy godzinami 8 a 22 lub ustawiono kombinację parametrów try i interval powodującą możliwość próby połączenia po godzinie 22.'
        Case 'ERROR:52'
            $sDescription = 'Za dużo prób wysyłki wiadomości do jednego numeru (maksymalnie 10 prób w przeciągu 60sek do jednego numeru).'
        Case 'ERROR:53'
            $sDescription = 'Nieunikalny parametr idx. Została już przyjęta wiadomość z identyczną wartością parametru idx przy wykorzystaniu parametru &check_idx=1.'
        Case 'ERROR:54'
            $sDescription = 'Błędny format daty. Ustawiono sprawdzanie poprawności daty &date_validate=1.'
        Case 'ERROR:55'
            $sDescription = 'Brak numerów stacjonarnych w wysyłce i ustawiony parametr skip_gsm.'
        Case 'ERROR:56'
            $sDescription = 'Różnica pomiędzy datą wysyłki a datą wygaśnięcia nie może być mniejsza niż 15 minut i większa niż 12 godzin.'
        Case 'ERROR:57'
            $sDescription = 'Numer znajduje się na czarnej liście dla danego użytkownika.'
        Case 'ERROR:60'
            $sDescription = 'Grupa kodów o podanej nazwie nie istnieje.'
        Case 'ERROR:61'
            $sDescription = 'Data ważności grupy kodów minęła.'
        Case 'ERROR:62'
            $sDescription = 'Brak wolnych kodów w podanej grupie (wszystkie kody zostały już wykorzystane).'
        Case 'ERROR:65'
            $sDescription = 'Brak wystarczającej liczby kodów rabatowych dla wysyłki. Liczba niewykorzystanych kodów w grupie musi być co najmniej równa liczbie numerów w wysyłce.'
        Case 'ERROR:66'
            $sDescription = 'W treści wiadomości brak jest znacznika [%kod%] dla wysyłki z parametrem &discount_group (znacznik taki jest wymagany).'
        Case 'ERROR:70'
            $sDescription = 'Błędny adres CALLBACK w parametrze notify_url.'
        Case 'ERROR:72'
            $sDescription = 'Parametr notify_url może być używany tylko dla odwołań z jednym numerem (nie może być stosowany dla wysyłek masowych).'
        Case 'ERROR:101'
            $sDescription = 'Niepoprawne lub brak danych autoryzacji. UWAGA! Hasło do API może różnić się od hasła do Panelu Klienta.'
        Case 'ERROR:102'
            $sDescription = 'Nieprawidłowy login lub hasło.'
        Case 'ERROR:103'
            $sDescription = 'Brak punktów dla tego użytkownika.'
        Case 'ERROR:104'
            $sDescription = 'Brak szablonu.'
        Case 'ERROR:105'
            $sDescription = 'Błędny adres IP (włączony filtr IP dla interfejsu API).'
        Case 'ERROR:110'
            $sDescription = 'Usługa (SMS, MMS, VMS lub HLR) nie jest dostępna na danym koncie.'
        Case 'ERROR:200'
            $sDescription = 'Nieudana próba wysłania wiadomości, prosimy ponowić odwołanie.'
        Case 'ERROR:201'
            $sDescription = 'Wewnętrzny błąd systemu (prosimy zgłosić).'
        Case 'ERROR:202'
            $sDescription = 'Zbyt duża ilość jednoczesnych odwołań do serwisu, wiadomość nie została wysłana (prosimy odwołać się ponownie).'
        Case 'ERROR:300'
            $sDescription = 'Nieprawidłowa wartość pola points (przy użyciu pola points jest wymagana wartość 1).'
        Case 'ERROR:301'
            $sDescription = 'Wiadomość o podanym ID nie istnieje lub jest zaplanowana do wysłania w przeciągu najbliższych 60 sekund (nie można usunąć takiej wiadomości).'
        Case 'ERROR:400'
            $sDescription = 'Nieprawidłowy ID statusu wiadomości.'
        Case 'ERROR:999'
            $sDescription = 'Wewnętrzny błąd systemu (prosimy zgłosić).'
        Case 'ERROR:1000'
            $sDescription = 'Akcja dostępna tylko dla użytkownika głównego.'
        Case 'ERROR:1001'
            $sDescription = 'Nieprawidłowa akcja (oczekiwane jedna z add_user, set_user, get_user, credits).'
        Case 'ERROR:1010'
            $sDescription = 'Błąd dodawania podużytkownika.'
        Case 'ERROR:1020'
            $sDescription = 'Błąd edycji konta podużytkownika.'
        Case 'ERROR:1021'
            $sDescription = 'Brak danych do edycji, przynajmniej jeden parametr musi być edytowany.'
        Case 'ERROR:1030'
            $sDescription = 'Błąd pobierania danych użytkownika.'
        Case 'ERROR:1032'
            $sDescription = 'Nie istnieje podużytkownik o podanej nazwie dla danego użytkownika głównego.'
        Case 'ERROR:1100'
            $sDescription = 'Błąd danych podużytkownika.'
        Case 'ERROR:1110'
            $sDescription = 'Błędna nazwa tworzonego podużytkownika.'
        Case 'ERROR:1111'
            $sDescription = 'Nie podano nazwy tworzonego konta podużytkownika.'
        Case 'ERROR:1112'
            $sDescription = 'Nazwa konta podużytkownika za krótka (minimum 3 znaki).'
        Case 'ERROR:1113'
            $sDescription = 'Nazwa konta podużytkownika za długa, łączna długość nazwy podużytkownika wraz z prefiksem użytkownika głównego może mieć maksymalnie 32 znaki.'
        Case 'ERROR:1114'
            $sDescription = 'W nazwie podużytkownika pojawiły się niedozwolone znaki, dozwolone są litery [A – Z], cyfry [0 – 9] oraz znaki @, -, _ i .'
        Case 'ERROR:1115'
            $sDescription = 'Istnieje już podużytkownik o podanej nazwie.'
        Case 'ERROR:1120'
            $sDescription = 'Błąd hasła dla tworzonego konta podużytkownika.'
        Case 'ERROR:1121'
            $sDescription = 'Hasło dla tworzonego konta podużytkownika za krótkie.'
        Case 'ERROR:1122'
            $sDescription = 'Hasło dla tworzonego konta podużytkownika za długie.'
        Case 'ERROR:1123'
            $sDescription = 'Hasło powinno być zakodowane w MD5.'
        Case 'ERROR:1130'
            $sDescription = 'Błąd limitu punktów przydzielanego podużytkownikowi.'
        Case 'ERROR:1131'
            $sDescription = 'Parametr limit powinno zawierać wartość numeryczną.'
        Case 'ERROR:1140'
            $sDescription = 'Błąd limitu miesięcznego punktów przydzielanego podużytkownikowi.'
        Case 'ERROR:1141'
            $sDescription = 'Parametr month_limit powinno zawierać wartość numeryczną.'
        Case 'ERROR:1150'
            $sDescription = 'Błędna wartość parametru senders, dopuszczalne wartości dla tego parametru to 0 lub 1.'
        Case 'ERROR:1160'
            $sDescription = 'Błędna wartość parametru phonebook, dopuszczalne wartości dla tego parametru to 0 lub 1.'
        Case 'ERROR:1170'
            $sDescription = 'Błędna wartość parametru active, dopuszczalne wartości dla tego parametru to 0 lub 1.'
        Case 'ERROR:1180'
            $sDescription = 'Błąd parametru info.'
        Case 'ERROR:1183'
            $sDescription = 'Zawartość parametru info jest za długa.'
        Case 'ERROR:1190'
            $sDescription = 'Błąd hasła do interfejsu API dla konta podużytkownika.'
        Case 'ERROR:1192'
            $sDescription = 'Błędna długość hasła do interfejsu API dla konta podużytkownika (hasło zakodowane w md5 powinno mieć 32 znaki).'
        Case 'ERROR:1193'
            $sDescription = 'Hasło do interfejsu powinno zostać podane w formie zakodowanej w md5.'
        Case 'ERROR:2001'
            $sDescription = 'Nieprawidłowa akcja (oczekiwane jedna z add, status, delete, list).'
        Case 'ERROR:2010'
            $sDescription = 'Błąd dodawania pola nadawcy.'
        Case 'ERROR:2030'
            $sDescription = 'Błąd sprawdzania statusu pola nadawcy.'
        Case 'ERROR:2031'
            $sDescription = 'Nie istnieje pole nadawcy o podanej nazwie.'
        Case 'ERROR:2060'
            $sDescription = 'Błąd dodawania domyślnego pola nadawcy.'
        Case 'ERROR:2061'
            $sDescription = 'Pole nadawcy musi być aktywne, żeby ustawić je jako domyślne.'
        Case 'ERROR:2062'
            $sDescription = 'Pole nadawcy już jest ustawione jako domyślne.'
        Case 'ERROR:2100'
            $sDescription = 'Błąd przesyłanych danych.'
        Case 'ERROR:2110'
            $sDescription = 'Błąd nazwy pola nadawcy.'
        Case 'ERROR:2111'
            $sDescription = 'Brak nazwy dodawanego pola nadawcy (parametr &add jest pusty).'
        Case 'ERROR:2112'
            $sDescription = 'Niepoprawna nazwa pola nadawcy (np. numer telefonu, zawierająca polskie i/lub specjalne znaki lub za długie), pole nadawcy może mieć maksymalnie 11 znaków, dopuszczalne znaki: a-z A-Z 0-9 - . [spacja].'
        Case 'ERROR:2115'
            $sDescription = 'Pole o podanej nazwie już istnieje.'
        Case 'ERROR:4000'
            $sDescription = 'Ogólny błąd operacji na bazie numerów.'
        Case 'ERROR:4001'
            $sDescription = 'Usługa nie jest dostępna na danym koncie.'
        Case 'ERROR:4002'
            $sDescription = 'Nieprawidłowa operacja.'
        Case 'ERROR:4003'
            $sDescription = 'Nieprawidłowe użycie parametru.'
        Case 'ERROR:4004'
            $sDescription = 'Za duża wartość parametru limit (np. dla operacji list_contacts maksymalna wartość wyświetlanych rekordów to 200).'
        Case 'ERROR:4100'
            $sDescription = 'Ogólny błąd operacji na grupach bazy numerów.'
        Case 'ERROR:4101'
            $sDescription = 'Grupa o podanej nazwie nie została znaleziona.'
        Case 'ERROR:4110'
            $sDescription = 'Ogólny błąd nazwy grupy bazy numerów.'
        Case 'ERROR:4111'
            $sDescription = 'Nieprawidłowa nazwa grupy.'
        Case 'ERROR:4112'
            $sDescription = 'Nazwa grupy nie może być pusta.'
        Case 'ERROR:4113'
            $sDescription = 'Nazwa grupy za krótka (minimalnie 2 znaki).'
        Case 'ERROR:4114'
            $sDescription = 'Nazwa grupy za długa (maksymalnie 32 znaki).'
        Case 'ERROR:4115'
            $sDescription = 'W nazwie grupy pojawiły się niedozwolone znaki.'
        Case 'ERROR:4116'
            $sDescription = 'Grupa o podanej nazwie już istnieje.'
        Case 'ERROR:4121'
            $sDescription = 'Nieprawidłowa wartość parametru Info dla grupy.'
        Case 'ERROR:4122'
            $sDescription = 'Za długa wartość pola Info dla grupy (maksymalnie 200 znaków).'
        Case 'ERROR:4200'
            $sDescription = 'Ogólny błąd kontaktu bazy numerów.'
        Case 'ERROR:4201'
            $sDescription = 'Kontakt o podanej nazwie nie został odnaleziony.'
        Case 'ERROR:4210'
            $sDescription = 'Ogólny błąd numeru telefonu przydzielonego do kontaktu.'
        Case 'ERROR:4211'
            $sDescription = 'Nieprawidłowy numer.'
        Case 'ERROR:4212'
            $sDescription = 'Kontakt musi zawierać numer telefonu.'
        Case 'ERROR:4213'
            $sDescription = 'Numer jest za krótki.'
        Case 'ERROR:4214'
            $sDescription = 'Numer jest za długi.'
        Case 'ERROR:4220'
            $sDescription = 'Błąd Imienia kontaktu.'
        Case 'ERROR:4221'
            $sDescription = 'Imię za krótkie (minimum 2 znaki).'
        Case 'ERROR:4222'
            $sDescription = 'Imię za długie (maksymalnie 100 znaków).'
        Case 'ERROR:4230'
            $sDescription = 'Błąd Nazwiska kontaktu.'
        Case 'ERROR:4231'
            $sDescription = 'Nazwisko za krótkie (minimum 2 znaki).'
        Case 'ERROR:4232'
            $sDescription = 'Nazwisko za długie (maksymalnie 100 znaków).'
        Case 'ERROR:4240'
            $sDescription = 'Błąd pola Info dla kontaktu.'
        Case 'ERROR:4241'
            $sDescription = 'Za długa wartość pola Info dla kontaktu (maksymalnie 200 znaków).'
        Case 'ERROR:4250'
            $sDescription = 'Błąd adresu e-mail dla kontaktu.'
        Case 'ERROR:4260'
            $sDescription = 'Błąd daty urodzenia kontaktu.'
        Case 'ERROR:4270'
            $sDescription = 'Błąd grupy dla danego kontaktu.'
        Case 'ERROR:4271'
            $sDescription = 'Grupa o podanej nazwie nie została znaleziona.'
        Case 'ERROR:4272'
            $sDescription = 'Przy operacji na kontaktach wymagana jest nazwa grupy.'
        Case 'ERROR:4280'
            $sDescription = 'Błąd płci kontaktu.'
    EndSwitch
    Return 'SMSAPI: ' & $sError & ': ' & $sDescription
EndFunc   ;==>_SMSApi_Error

Unfortunately statuses are in Polish, but can be easily adjusted through the list from this link: https://www.smsapi.com/resp

btw. I never used 

_SMSApi_Status()

so for now, there is no example .

 

mLipok

 

EDIT: UDF changed - added _SMSApi_URL()

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites
;http://developer.bulksms.com/eapi/libraries/supported/

Private Sub cmdSendTextMessage_Click()

    Dim oHttp As Object
    Dim strUrl, strUsername, strPassword, strMessage, strMobileNumber  As String
    Set oHttp = CreateObject("Microsoft.XMLHTTP")
    strUsername = "your username"
    strPassword = "your password"
    strMessage = "your message text goes here…"
    strMobileNumber = "your mobile number in the format 44your_number_with_the_zero_removed"
    
    strUrl = "http://www.bulksms.co.uk:5567/eapi/submission/send_sms/2/2.0?username=" + strUsername + "&password=" + strPassword + "&message=" + strMessage + "&msisdn=" + strMobileNumber
    
    oHttp.Open "GET", strUrl, False
    oHttp.send
    
    MsgBox (oHttp.responseText)
    
End Sub

Found this on the BulkSMS site. Looks very similar to Trancexx first post. :)

Obviously there is more than one way to do this.

Thx mLipok.  


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

<?php
    /*Send SMS using PHP*/    
    
    //Your authentication key
    $authKey = "YourAuthKey";
    
    //Multiple mobiles numbers separated by comma
    $mobileNumber = "9999999";
    
    //Sender ID,While using route4 sender id should be 6 characters long.
    $senderId = "102234";
    
    //Your message to send, Add URL encoding here.
    $message = urlencode("Test message");
    
    //Define route
    $route = "default";
    //Prepare you post parameters
    $postData = array(
        'authkey' => $authKey,
        'mobiles' => $mobileNumber,
        'message' => $message,
        'sender' => $senderId,
        'route' => $route
    );
    
    //API URL
    $url="https://control.msg91.com/api/sendhttp.php";
    
    // init the resource
    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $postData
        //,CURLOPT_FOLLOWLOCATION => true
    ));
    

    //Ignore SSL certificate verification
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    
    //get response
    $output = curl_exec($ch);
    
    //Print error if any
    if(curl_errno($ch))
    {
        echo 'error:' . curl_error($ch);
    }
    
    curl_close($ch);
    
    echo $output;
?>


I found this PHP SMS API code on renowned bulk SMS service provider company MSG91 . I hope this help you to in to get solution.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

thanks for sharing this .

<snip>

Edited by JLogan3o13
Removed advertising link

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

  • Similar Content

    • BigDaddyO
      By BigDaddyO
      Hello,
       
      I'm trying to figure out how to add attributes to a Credentials Store.  I have been using it to store Creds and I was using the Comments to store some limited data but I'd really like to start using the 64 possible Attributes so I don't need to use the Registry to store misc information my script needs.
       
      I have been trying to figure this our for a few days now and I'm able to create the structure, but it fails with Invalid Parameter when trying to add the item to the store.
       
      Any ideas or pointers to where to get some further information on this?
      Thanks,
      Mike
      #include <Crypt.au3> #include <Array.au3> #include <WinAPI.au3> $sEncryptionKey = @ScriptName & 'MyS3cur!tyK3y' & @UserName $sCredName = "AttributeTest" $sUserID = "MyUserID" $sPassword = "SecretP@ssw0rd" $sDatabase = "StoredCommentHere" $sAttribute1 = "ALM.NoReply" $sAttribute2 = "Defect #?BG_BUG_ID in ?PROJECT, Status = ?BG_STATUS, Severity = ?BG_SEVERITY" $sAttribute3 = "C:\Users\MyProfile\Documents\ALM_Reports" $sAttribute4 = "UserName1,QA_Analyst|UserName2,Business_Analyst|UserName3,QA_Analyst|UserName4,QA_Analyst|UserName5,Business_Analyst|UserName6,QA_Analyst" Global $aAttribute[4, 2] = [["eMailFrom", $sAttribute1], ["eMailSubject", $sAttribute2], ["reportFldr", $sAttribute3], ["DefaultUsers", $sAttribute4]] ;Add something to the Credential Store $aAdd = _Cred_Add_WithAttributes($sCredName, $sUserID, StringEncrypt(True, $sPassword, $sEncryptionKey), $sDatabase, 1, $aAttribute) If @error Then MsgBox(0, "Error", "Failed to add credentials to " & $sCredName) Exit EndIf Func _Cred_Add_WithAttributes($sTarget, $sUser, $sPassword, $sComm = "", $iType = 2, $aAttribute = "") ;Type: 2=Domain, 1=Local Local $structTarget = DllStructCreate("wchar[100]") ; Create a structure to hold the Target object name DllStructSetData($structTarget, 1, $sTarget) ; Insert the target name into that Structure Local $structUser = DllStructCreate("wchar[100]") ; Create a structure to hold the UserName to use DllStructSetData($structUser, 1, $sUser) ; Insert the user name into the structure Local $structPwd = DllStructCreate("wchar[100]") ; Create a structure to hold the password to use DllStructSetData($structPwd, 1, $sPassword) ; Insert the password into the structure Local $structComment = DllStructCreate("wchar[100]") ; Comments seem to only work where Type = 1 legacy DllStructSetData($structComment, 1, $sComm) ;-------------------------------------------------------------------------------------------------------------------- ;-- CREDENTIAL_ATTRIBUTE structure https://msdn.microsoft.com/en-us/library/windows/desktop/aa374790(v=vs.85).aspx ;-------------------------------------------------------------------------------------------------------------------- Local $aAttrirb[UBound($aAttribute)] Local $tagCREDENTIAL_ATTRIBUTE = "" & _ "wchar Keyword;" & _ "DWORD Flags;" & _ "DWORD ValueSize;" & _ "wchar Value" For $i = 0 to UBound($aAttribute) - 1 $aAttrirb[$i] = DllStructCreate($tagCREDENTIAL_ATTRIBUTE) If @error Then ConsoleWrite("Error on $aAttrib[" & $i & "] = " & @error & @CRLF) Exit EndIf DllStructSetData($aAttrirb[$i],"Keyword",StringRight($aAttribute[$i][0], 256)) ;Name for the Attribute to use, 256 characters max If @error Then ConsoleWrite("Error adding Keyword to $aAttrib[" & $i & "] = " & @error & @CRLF) DllStructSetData($aAttrirb[$i],"Flags",0) ;Should always be 0 If @error Then ConsoleWrite("Error adding Flags to $aAttrib[" & $i & "] = " & @error & @CRLF) DllStructSetData($aAttrirb[$i],"ValueSize",256) ;Max = 256 If @error Then ConsoleWrite("Error adding ValueSize to $aAttrib[" & $i & "] = " & @error & @CRLF) DllStructSetData($aAttrirb[$i],"Value",StringRight($aAttribute[$i][1], 256)) ;Take the right most 256 characters if they put in to many If @error Then ConsoleWrite("Error adding Value to $aAttrib[" & $i & "] = " & @error & @CRLF) Next ;-------------------------------------------------------------------------------------------------------------------- Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $NewCred = DllStructCreate($structCREDENTIAL) If @error Then MsgBox(0, "NewCred", "Error in DllStructCreate " & @error); Exit EndIf DllStructSetData($NewCred,"Flags",0) DllStructSetData($NewCred,"Type",$iType) ;2 = Domain, 1 = Generic DllStructSetData($NewCred,"TargetName",DllStructGetPtr($structTarget)) DllStructSetData($NewCred,"Persist",3) ;save to roaming profile = 3 ;Problem with this section, as if I comment out, it adds but I need Attributes. DllStructSetData($NewCred,"AttributeCount",UBound($aAttrib)) ;max = 64 If @error Then ConsoleWrite("Error adding AttributeCount (1) = " & @error & @CRLF) For $i = 0 to UBound($aAttrirb) - 1 DllStructSetData($NewCred,"Attributes", DllStructGetPtr($aAttrirb[$i])) If @error Then ConsoleWrite("Error adding Attributes (" & $i + 1 & ") = " & @error & @CRLF) Next DllStructSetData($NewCred,"UserName",DllStructGetPtr($structUser)) DllStructSetData($NewCred,"CredentialBlob",DllStructGetPtr($structPwd)) DllStructSetData($NewCred,"CredintialBlobSize",StringLen($sPassword)*2) DllStructSetData($NewCred,"Comment",DllStructGetPtr($structComment)) Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif $aRet = DllCall($hAdvapi32, 'bool', 'CredWriteW', 'ptr', DllStructGetPtr($NewCred), 'dword', 0) If @error Then ConsoleWrite("DllCall Error: " & @error & @CRLF) $NewCred = 0 ConsoleWrite("GetLastError = (" & _WinAPI_GetLastError() & ")" & @CRLF) ;87 = ERROR_INVALID_PARAMETER If IsArray($aRet) Then ConsoleWrite("Successfully performed the CredWriteW DLL call, Return = " & $aRet[0] & @CRLF) if UBound($aRet) > 1 Then _ArrayDisplay($aRet, "DllCall Returned") Return $aRet Else ConsoleWrite("Failed to perform the CredWriteW DLL call" & @CRLF) Return SetError(1) EndIf EndFunc Func _Cred_Get($sTarget, $iType = 2) ;Type: 2=Domain, 1=Local. CAN'T DECRYPT DOMAIN PASSWORDS!!! Local $FuncRet[3] Local $structTarget = DllStructCreate("wchar[100]") DllStructSetData($structTarget,1,$sTarget) Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif Local $Ret = DllCall($hAdvapi32, 'bool', 'CredReadW', 'ptr', DllStructGetPtr($structTarget), 'dword', $iType, 'dword', 0, 'ptr*', 0) if $ret[0]=0 then Return SetError(1,0,$FuncRet) Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $tdata=DllStructCreate($structCREDENTIAL, $Ret[4]) Local $userName = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Username')) Local $User = DllStructGetData($userName, 1) Local $CredentialBlobSize = DllStructGetData($tdata, 'CredintialBlobSize') Local $credentialBlob = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'CredentialBlob')) Local $Password = StringLeft(DllStructGetData($credentialBlob, 1), $CredentialBlobSize/2) ;Once the Add Attributes is working, I need to figure out how to retrieve the Attributes that I want, below is un-tested. ; Local $eMailFrom = DllStructCreate("wchar[256]", DllStructGetData($tdata, 'eMailFrom')) ; Local $eMail = DllStructGetData($eMailFrom, 4) ; Consolewrite("eMailFrom Attribute = (" & $eMail & ")" & @crlf ) Local $Comment = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Comment')) Local $Comm = DllStructGetData($Comment, 1) Dim $FuncRet[] = [$User, $Password, $Comm] If IsArray($FuncRet) Then Return $FuncRet Else Return SetError(1) EndIf EndFunc  
    • BigDaddyO
      By BigDaddyO
      I've been working with the Windows Credentials store to store credentials for lots of RDP connections.  I'm also using this code in other scripts to store and retrieve "legacy" credentials for my scripts that have a Save Password checkbox.
      All goes well, until someone requests a button to display a list of all saved credentials.  I found the CredEnumerate call and it looks like it's working but the Target and UserName field that I want is stored inside an array of pointers and I can't figure out how to get data from inside that.  I found a post from 2009 that talks about this, but there was never a solution.
       
      Below are my functions put into an example script.  the _Credentials_Enumerate() is where i'm having problems.   Anybody have some ideas?
      Thanks,
      Mike
       
      ;Credentials Manager #include <array.au3> #include <WinAPI.au3> ;Needed for the _WinAPI_GetLastError() ;------------------------------------------------------------------------ ;----- Add items into the Credentials Store ---------------------------- ;------------------------------------------------------------------------ ;~ _Cred_Add("MyCredStored", "ItsMe", "Secret1", "", 1) ;Add a Local Credentials so we can test the retrieval of a password ;~ $aAddCred = _Cred_Add("MyServer", "Domain\adminAccount", "MyS3cr3+P@ssw0rd") ;Add domain Credentials that can only be used with RDP and other such items ;~ _ArrayDisplay($aAddCred, "AddCred") ;------------------------------------------------------------------------ ;------------------------------------------------------------------------ ;----- Retrieve Credentials from the Credentials Store ----------------- ;------------------------------------------------------------------------ ;~ $aCreds = _Cred_Get("MyServer", 2) ;Retrieve Domain Cred's, won't have password in it ;~ _ArrayDisplay($aCreds, "Credentials") $aCreds = _Credentials_Enumerate() ;Get a list of all credentials currently stored on the system **(DOES NOT WORK)** ;------------------------------------------------------------------------ ;------------------------------------------------------------------------ ;----- Delete a Credential from the Credentials Store ------------------ ;------------------------------------------------------------------------ ;~ _Cred_Delete("MyServer") ;Delete the specified item from the Credential Store ;~ For $d = 1 to UBound($aCreds) - 1 ;~ _Cred_Delete($aCreds[$d][0]) ;Loop to delete all items found. **(DOES NOT WORK)** ;~ Next ;------------------------------------------------------------------------ ;================================================================================================ ;===== Add a Credential into the Credentials Store ============================================= ;================================================================================================ Func _Cred_Add($sTarget, $sUser, $sPassword, $sComm = "", $iType = 2) ;Type: 2=Domain, 1=Local Local $structTarget = DllStructCreate("wchar[100]") ; Create a structure to hold the Target object name DllStructSetData($structTarget, 1, $sTarget) ; Insert the target name into that Structure Local $structUser = DllStructCreate("wchar[100]") ; Create a structure to hold the UserName to use DllStructSetData($structUser, 1, $sUser) ; Insert the user name into the structure Local $structPwd = DllStructCreate("wchar[100]") ; Create a structure to hole the password to use DllStructSetData($structPwd, 1, $sPassword) ; Insert the password into the structure Local $structComment = DllStructCreate("wchar[100]") ; I don't see where this is used, but was in all the examples DllStructSetData($structComment, 1, $sComm) Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $NewCred = DllStructCreate($structCREDENTIAL) If @error Then MsgBox(0, "NewCred", "Error in DllStructCreate " & @error); Exit EndIf DllStructSetData($NewCred,"Flags",0) DllStructSetData($NewCred,"Type",$iType) ;2 = Domain, 1 = Generic DllStructSetData($NewCred,"TargetName",DllStructGetPtr($structTarget)) DllStructSetData($NewCred,"Persist",3) DllStructSetData($NewCred,"AttributeCount",0) DllStructSetData($NewCred,"UserName",DllStructGetPtr($structUser)) DllStructSetData($NewCred,"CredentialBlob",DllStructGetPtr($structPwd)) DllStructSetData($NewCred,"CredintialBlobSize",StringLen($sPassword)*2) DllStructSetData($NewCred,"Comment",DllStructGetPtr($structComment)) Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif $Ret = DllCall($hAdvapi32, 'bool', 'CredWriteW', 'ptr', DllStructGetPtr($NewCred), 'dword', 0) $NewCred = 0 If IsArray($Ret) Then Return $Ret Else Return SetError(1) EndIf EndFunc ;_Cred_Add ;================================================================================================ ;===== Retrieve the Credentials for the specified item ========================================= ;================================================================================================ Func _Cred_Get($sTarget, $iType = 1) ;Type: 2=Domain, 1=Local. CAN'T RETURN DOMAIN PASSWORDS!!! Local $FuncRet[3] Local $structTarget = DllStructCreate("wchar[100]") DllStructSetData($structTarget,1,$sTarget) Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif Local $Ret = DllCall($hAdvapi32, 'bool', 'CredReadW', 'ptr', DllStructGetPtr($structTarget), 'dword', $iType, 'dword', 0, 'ptr*', 0) if $ret[0]=0 then Return SetError(1,0,$FuncRet) Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $tdata=DllStructCreate($structCREDENTIAL, $Ret[4]) Local $userName = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Username')) Local $User = DllStructGetData($userName, 1) Local $CredentialBlobSize = DllStructGetData($tdata, 'CredintialBlobSize') Local $credentialBlob = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'CredentialBlob')) Local $Password = StringLeft(DllStructGetData($credentialBlob, 1), $CredentialBlobSize/2) Local $Comment = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Comment')) Local $Comm = DllStructGetData($Comment, 1) Dim $FuncRet[] = [$User, $Password, $Comm] Return $FuncRet EndFunc ;_Cred_Get ;================================================================================================ ;===== Delete a specified item from the Credentials Store ====================================== ;================================================================================================ Func _Cred_Delete($sTarget, $iType = 2) ;Type: 2=Domain, 1=Local Local $structTarget = DllStructCreate("wchar[100]") ;Create a structure to hold the object name we want to delete DllStructSetData($structTarget, 1, $sTarget) ;Insert the Object Name into the Structure Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif ;Now send all the info into the DLL to delete the item $Ret = DllCall($hAdvapi32, 'bool', 'CredDeleteW', 'ptr', DllStructGetPtr($structTarget), 'dword', $iType, 'dword', 0) ;$iType 2 = Domain, 1 = Local EndFunc ;_Cred_Delete ;================================================================================================ ;===== Return a 2D array with the Target, UserName, Password for every item ==================== ;===== in the Credentials Store ==================== ;================================================================================================ Func _Credentials_Enumerate() ;https://msdn.microsoft.com/en-us/library/windows/desktop/aa374794(v=vs.85).aspx ;https://www.autoitscript.com/forum/topic/99705-credenumerate-function-call/?do=findComment&comment=715159 Local $aResult Local $structCREDENTIAL = "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" $aResult = DllCall('advapi32.dll', 'int', 'CredEnumerateW', _ ;Call the Unicode version of CredEnumerate 'wstr', Null, _ ;Don't use any filter since I want everything returned 'uint', 1, _ ;1 = CRED_ENUMERATE_ALL_CREDENTIALS 'uint*', '', _ ;Return the Count of all stored credentials 'ptr*', '') ;Returns a pointer to an Array of pointers? If @error Or ($aResult[0] = 0) Then ConsoleWrite('Error: ' & @error & @TAB & 'Extended: ' & @extended & @CRLF) ConsoleWrite(_WinAPI_GetLastError() & @CRLF) ;1168 = Nothing matches the filter, 1312 = no credential set for this user, 1004 = Flag/Filter options are wrong Return SetError(1) EndIf ConsoleWrite("DllCall Returned = " & $aResult[0] & @CRLF & "Credential Count = " & $aResult[3] & @CRLF & "Pointer to Creds Array = " & $aResult[4] & @CRLF) For $c = 2 to $aResult[3] ;Create enough struct for each item in each credential found $structCREDENTIAL &= "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Next Local $tdata = DllStructCreate($structCREDENTIAL, $aResult[4]) ;Insert all the data from the array of pointers into this struct Local $FullTarget = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'TargetName')) ;Create and Get the array storing TargetName Local $userName = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Username')) ;Create and Get the array storing Username Local $CredentialBlobSize = DllStructGetData($tdata, 'CredintialBlobSize') ;Get the password blob Local $credentialBlob = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'CredentialBlob')) ;Create and get the password text Local $Comment = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Comment')) ;Don't see a need for comments ;Retrieve the data For $c = 1 to $aResult[3] Local $Target = DllStructGetData($FullTarget, $c) ;Retrieve the Target Name from the item # Local $User = DllStructGetData($userName, $c) ;Retrieve the User Name from the item # Local $Password = StringLeft(DllStructGetData($credentialBlob, $c), $CredentialBlobSize/2) ;Retrieve the password, Only works for 1, legacy. domain creds will not return passwords Local $Comm = DllStructGetData($Comment, $c) ;Don't need comments but getting it since it's in all the examples ConsoleWrite("Loop = " & $c & ": Target = " & $Target & ": UserName = " & $User & ": Comment = " & $Comm & @CRLF) Next If $aResult[3] > 0 Then $aCreds = DllCall('advapi32.dll', 'none', 'CredFree', 'ptr', $aResult[4]) ;This is just used to release the pointer. Call when done EndIf EndFunc ;_Credentials_Enumerate  
    • luckyluke
      By luckyluke
      Hello,
      Im trying to read the output from CMD using Dllcall, here is my code:
      #include <WinAPI.au3> #include <array.au3> Global Const $STD_OUTPUT_HANDLE = -11 Global Const $_CONSOLE_SCREEN_BUFFER_INFO = _ "struct;int dwSizeX;" & _ "short dwSizeY;" & _ "short dwCursorPositionX;" & _ "short dwCursorPositionY;" & _ "short wAttributes;" & _ "short Left;" & _ "short Top;" & _ "short Right;" & _ "short Bottom;" & _ "short dwMaximumWindowSizeX;" & _ "short dwMaximumWindowSizeY;endstruct" $pCmd = Run( "cmd.exe" ) Sleep(1000) $hCmd = WinGetHandle("") ConsoleWrite('handle:' & $hCmd & @CRLF) $aRet = DllCall("kernel32.dll", "int", "AttachConsole", "dword", $pCmd) ;_ArrayDisplay($aRet) If $aRet[0] <> 0 Then $vHandle_data='' $vHandle='' $vHandle_data = DllStructCreate($_CONSOLE_SCREEN_BUFFER_INFO) ; Screen Buffer structure $aRet1 = DllCall("kernel32.dll", "hwnd", "GetStdHandle", "dword", $STD_OUTPUT_HANDLE) if not @error Then $vHandle = $aRet1[0] $aRet = DllCall("kernel32.dll", "int", "GetConsoleScreenBufferInfo", "hwnd", $vHandle, _ "ptr", $vHandle_data) MsgBox(0, '1',DllStructGetData($vHandle_data, 'dwSizeX') & _WinAPI_GetLastErrorMessage()) EndIf It did not work, i got the message 'The handle is invalid'. Please help?
      Thank you in advance!
    • MazeM
      By MazeM
      Hi
      here's another UDF for the serial port. It is very similar to CommAPI using kernel32.dll, but all code is packed into a single file without any dependencies, not even using WinAPI.au3. It differs from existing UDF that it doesn't allow a timeout when reading, instead it always returns immediately, either with the requested amount ob bytes read or with a failure status. And of course there is a function provided to query the amount of available bytes in the receive buffer. The reason behind this design decision: You can do 1000 other things in the main loop while checking from time to time if enough data bytes arrived. There's no point to block the program waiting for the serial port.
      It is currently a work-in-progress, as I didn't test all functions yet. The code was developed and tested on Windows 7 64 bit.  The ComUDF-Tests.au3 shows some tests and basic usage of the UDF. Maybe there's no reason to use this UDF, given the existence of the others UDFs, but I did it to get to know DllCall better - I use structs no only to pass but also to get data back (I don't use the array returned by DllCall to read that data, unless required). You're welcome to test it on older and newer Windows versions.
      Here's a list of the implemented functions:
      ; _ComListPorts ; _ComOpenPort ; _ComSetTimeouts ; _ComClosePort ; ; _ComSetBreak ; _ComClearBreak ; _ComGetInputcount ; _ComGetOutputcount ; _ComClearOutputBuffer ; _ComClearInputBuffer ; ; _ComSendByte ; _ComReadByte ; _ComSendBinary ; _ComReadBinary ; ; _ComSendChar ; _ComReadChar ; _ComSendCharArray ; _ComReadCharArray ; _ComSendString ; _ComReadString ; ; __ComClearCommError ; __PurgeComm Maze
       
      ComUDF.au3
      ComUDF-Tests.au3
    • astrionn
      By astrionn
      So I had this Idea of creating a tooltip which shows me my ping.
      That itself was made quickly and I thought too add a couple features.
      I want the tooltip background to be a different color depending on the ping. (good ping is green, medium ping is yellow,...)
      So how do I color in a tooltip? google brought me to this: 
       
      where in the comments I found this:
      $s = "LOW" ToolTip($s, 0, 0, "Battery Information");, $icon) $H_TOOLTIP1 = WinGetHandle($s) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $H_TOOLTIP1, "wstr", "", "wstr", "") DllCall("user32.dll", "int", "SendMessage", "hwnd", $H_TOOLTIP1, "int", 1043, "int", 2552550, "int", 0) Sleep(1000) Which I then used in my code with different color codes... Trial and Error brought me these that I wanted to use:
       
      The Problem is if I loop through my code it only sets the color for the 1st loop and then sticks to it.
      The real problem is tho that I don't exactly understand the dllcalls... And I guess that's why it isn't working
      So if someone would be so awesome to explain to me how they work, or at least can give me a list of these parameters then I would really appreciate that and learn something new
      Obviously a solution to my problem is awesome aswell ^^
      I run this under Windows 8.1
      There is my code in a paste.
      https://pastebin.com/q525f7mS