Jump to content

C structures and AutoIt [MT DLL]


Recommended Posts

So some time ago I created a project, a DLL to create background requests in separate threads using WinHTTP and pass around data using C structures. It all worked out wonderfully with the exception of a crash every now and then, but it got the job done.

Now I have need to make my dll return data in binary instead of doing the conversions internally, I want to be able to receive any kind of data, from text, binary all the way to gzip data. 

I basically make a copy of the structure in my dll on the AutoIt side.

Global $INT_BUFFERSIZE = 1048576
Global $tagTHREAD_PARAMETERS = _
        "WCHAR UserAgent[1024];" & _                            ;   user agent
        "WCHAR HTTPVerb[1024];" & _                             ;   POST/GET/HEAD etc
        "WCHAR Host[1024];" & _                                 ;   ex: google.com
        "WCHAR Resource[1024];" & _                             ;   ex: /somescript.php
        "int Port;" & _                                         ;   80/443
        "WCHAR Referer[1024];" & _                              ;   optional referer
        "WCHAR Headers[1024];" & _                              ;   null terminated request headers
        "ptr ExtraData;" & _                                    ;   pointer to structure with arguments ex: a=1&b=2&page=45
        "DWORD Length;" & _                                     ;   lenght of the arguents
        "DWORD TotalLength;" & _                                ;   same as above
        "int dwResolveTimeout;" & _                             ;   Resolve timout
        "int dwConnectTimeout;" & _                             ;   Connection timout
        "int dwSendTimeout;" & _                                ;   Send timeout
        "int dwReceiveTimeout;" & _                             ;   Recieve timeout
        "WCHAR Proxy[1024];" & _                                ;   proxy string
        "DWORD ProxyFlags;" & _                                 ;   WinHTTP open flags
        "DWORD SendFlags;" & _                                  ;   WinHttpOpenRequest flags
        "BYTE ResponceHTML[" & $INT_BUFFERSIZE & "];" & _       ;   HTML returned
        "WCHAR ResponceHeaders[" & $INT_BUFFERSIZE & "];" & _   ;   Responce Headers
        "DOUBLE Latency;" & _                                   ;   Responce Latency
        "int RetryTimes;" & _                                   ;   Times to retry request with server
        "int MaxTestTime;" & _                                  ;   max amount of time the request can run for
        "ptr httpSession;" & _
        "ptr httpConnect;" & _
        "ptr httpRequest"

And I have this copy in my dll which I later initialize with my AutoIt copy so I can use all the info in it and subsequently return data as well.

// AutoIt thread parameters
static const int INT_BUFFERSIZE = 1048576;    // Had to increase to 1MB because I was getting very big pages with some tests and it wouldn't work

// AutoIt thread parameters, AutoIt will create a version of this and pass it as a thread paramater
struct THREAD_PARAM_COMPONENTS {
    WCHAR UserAgent[1024];                      // user agent
    WCHAR HTTPVerb[1024];                       // POST/GET/HEAD etc
    WCHAR Host[1024];                           // Domain name for target request
    WCHAR Resource[1024];                       // resource at target
    int Port;                                   // port on target
    WCHAR Referer[1024];                        // referer
    WCHAR Headers[1024];                        // headers string
    LPVOID ExtraData;                           // additional data/paramaters to send
    DWORD Length;                               // lenght of additional data
    DWORD TotalLenght;                          // same as above for some reason
    int dwResolveTimeout;                       // max time for resolving
    int dwConnectTimeout;                       // max time for connection
    int dwSendTimeout;                          // max time to wait while sending
    int dwReceiveTimeout;                       // max time to wait for recieving responce
    WCHAR Proxy[1024];                          // proxy for request
    DWORD ProxyFlags;                           // flags for proxy
    DWORD SendFlags;                            // send flags
    BYTE ResponceHTML[INT_BUFFERSIZE];          // HTML from responce
    WCHAR ResponceHeaders[INT_BUFFERSIZE];      // headers from responce
    double Latency;                             // return indicating total time spent in request
    int RetryTimes;                             // maximum times to retry request if failures happen
    int MaxTestTime;                            // maximum time to spend in request
    LPVOID httpSession;                         // Session handles returned to AutoIt
    LPVOID httpConnect;                         // Session handles returned to AutoIt
    LPVOID httpRequest;                         // Session handles returned to AutoIt
};

I then pass the structure I created AutoIt side to the dll and it creates a thread and initializes the structure.

THREAD_PARAM_COMPONENTS* tData = (THREAD_PARAM_COMPONENTS*)threadData; // threadData is passed as an LPVOID to the thread

And then I start accessing the stuff I sent from my AutoIt script from inside the DLL...

...
    hSession = ::WinHttpOpen(tData->UserAgent,
                            tData->ProxyFlags,
                            tData->Proxy,
                            WINHTTP_NO_PROXY_BYPASS,
                            0);
...

So far all that stuff works, requests are made and data was returned, up until I attempted to change my program from returning WCHAR data to a BYTE array. And now I get nothing but a ridiculous amount of zeros like "0x0000.... to infinity".

so far this is the problem var in both sides.

BYTE ResponceHTML[INT_BUFFERSIZE];          // HTML from responce

This is my DLL codebase, unicode.

//////////////////////////////////////////////////////////////////////////////////////////
// DLL to create multiple background WinHTTP requests.
// Why? since AutoIt is single threaded, I need a nonblocking function to make requests.
// Project is Unicode
//////////////////////////////////////////////////////////////////////////////////////////

#include <Windows.h>
#include <WinHTTP.h>
#include <string>
#include <time.h>

#pragma comment(lib, "winhttp.lib") // need to link to lib

using namespace std;

// AutoIt thread parameters
static const int INT_BUFFERSIZE = 1048576;    // Had to increase to 1MB because I was getting very big pages with some tests and it wouldn't work

// AutoIt thread parameters, AutoIt will create a version of this and pass it as a thread paramater
struct THREAD_PARAM_COMPONENTS {
    WCHAR UserAgent[1024];                      // user agent
    WCHAR HTTPVerb[1024];                       // POST/GET/HEAD etc
    WCHAR Host[1024];                           // Domain name for target request
    WCHAR Resource[1024];                       // resource at target
    int Port;                                   // port on target
    WCHAR Referer[1024];                        // referer
    WCHAR Headers[1024];                        // headers string
    LPVOID ExtraData;                           // additional data/paramaters to send
    DWORD Length;                               // lenght of additional data
    DWORD TotalLenght;                          // same as above for some reason
    int dwResolveTimeout;                       // max time for resolving
    int dwConnectTimeout;                       // max time for connection
    int dwSendTimeout;                          // max time to wait while sending
    int dwReceiveTimeout;                       // max time to wait for recieving responce
    WCHAR Proxy[1024];                          // proxy for request
    DWORD ProxyFlags;                           // flags for proxy
    DWORD SendFlags;                            // send flags
    BYTE ResponceHTML[INT_BUFFERSIZE];          // HTML from responce
    WCHAR ResponceHeaders[INT_BUFFERSIZE];      // headers from responce
    double Latency;                             // return indicating total time spent in request
    int RetryTimes;                             // maximum times to retry request if failures happen
    int MaxTestTime;                            // maximum time to spend in request
    LPVOID httpSession;                         // Session handles returned to AutoIt
    LPVOID httpConnect;                         // Session handles returned to AutoIt
    LPVOID httpRequest;                         // Session handles returned to AutoIt
};

DWORD WINAPI _WinHTTP_Process(LPVOID threadData);

//////////////////////////////////////////////////////////////////////////////////////////
// Dll entry point
//////////////////////////////////////////////////////////////////////////////////////////
BOOLEAN APIENTRY DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
    switch ( fdwReason )
    {
    case DLL_PROCESS_ATTACH:

        DisableThreadLibraryCalls( hinstDLL );// disable callbacks on new threads, we don't need them.

        break;

    case DLL_PROCESS_DETACH:

        break;
    }

    return TRUE;
} // End of DllMain

//////////////////////////////////////////////////////////////////////////////////////////
// The exported function of our DLL
//////////////////////////////////////////////////////////////////////////////////////////
HANDLE WINAPI WinHTTP_Action(LPVOID threadData)
{
    return CreateThread(NULL,
                        0,              // SIZE_T dwStackSize
                        &_WinHTTP_Process,
                        threadData,     // LPVOID threadData
                        0,              // DWORD dwCreationFlag
                        NULL);          // LPDWORD lpThreadId

} // End of WinHTTP_Action

//////////////////////////////////////////////////////////////////////////////////////////
// "The Thread"
//////////////////////////////////////////////////////////////////////////////////////////
DWORD WINAPI _WinHTTP_Process(LPVOID threadData)
{
    // Initialize the structure that AutoIt sent us, threadData with internal equivalent THREAD_PARAM_COMPONENTS
    THREAD_PARAM_COMPONENTS* tData = (THREAD_PARAM_COMPONENTS*)threadData;

    // Timer
    clock_t init, final;

    wstring m_charset;
    //DWORD dError;

    const unsigned int INT_RETRYTIMES = tData->RetryTimes;

    bool bRetVal = true;

    HINTERNET hSession = NULL;

    hSession = ::WinHttpOpen(tData->UserAgent,
                            tData->ProxyFlags,
                            tData->Proxy,
                            WINHTTP_NO_PROXY_BYPASS,
                            0); //Note: do not use async...

    if (!hSession)
        return false;

    tData->httpSession = hSession;

    WinHttpSetTimeouts(hSession,
                        tData->dwResolveTimeout,
                        tData->dwConnectTimeout,
                        tData->dwSendTimeout,
                        tData->dwReceiveTimeout);

    HINTERNET hConnect = NULL;
    hConnect = ::WinHttpConnect(hSession,
                                tData->Host,
                                tData->Port,
                                0 );

    if (hConnect != NULL)
    {

        tData->httpConnect = hConnect;

        HINTERNET hRequest = NULL;
        hRequest = ::WinHttpOpenRequest(hConnect,
                                        tData->HTTPVerb,
                                        tData->Resource,
                                        L"HTTP/1.1",
                                        tData->Referer,
                                        WINHTTP_DEFAULT_ACCEPT_TYPES,
                                        tData->SendFlags);

        if (hRequest != NULL)
        {
            tData->httpRequest = hRequest;

            bool bGetReponseSucceed = false;

            init = clock(); // start timer
            double TotalTime;

            if (!::WinHttpSendRequest(hRequest,
                                    tData->Headers,
                                    -1L, //<-- using wcslen()+1 seems to cause an invalid param error here so will stick with -1L
                                    tData->ExtraData,
                                    (DWORD) tData->Length,
                                    (DWORD) tData->TotalLenght,
                                    (DWORD) 0))
            {

                // This is just here in case I need to refrence back to how to get and view the last error of a function

                //dError = GetLastError();
                //WCHAR temp[100];
                //swprintf_s(temp, 100, L"Error: %d" , dError);
                //MessageBox(0 , temp, L"Error!", 0);
            }
            else
            {
                // Call was successfull, continue accepting whatever
                if (::WinHttpReceiveResponse(hRequest, NULL))
                {
                    DWORD dwSize = 0;

                    // Get the buffer size of the HTTP response header.
                    BOOL bResult = ::WinHttpQueryHeaders(hRequest,
                                                        WINHTTP_QUERY_RAW_HEADERS_CRLF,
                                                        WINHTTP_HEADER_NAME_BY_INDEX,
                                                        NULL,
                                                        &dwSize,
                                                        WINHTTP_NO_HEADER_INDEX);

                    if (bResult || (!bResult && (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)))
                    {
                        wchar_t *szHeader = new wchar_t[dwSize];
                        if (szHeader != NULL)
                        {
                            memset(szHeader, 0, dwSize* sizeof(wchar_t));

                            // Get HTTP response header.
                            if (::WinHttpQueryHeaders(hRequest,
                                WINHTTP_QUERY_RAW_HEADERS_CRLF,
                                WINHTTP_HEADER_NAME_BY_INDEX,
                                szHeader,
                                &dwSize,
                                WINHTTP_NO_HEADER_INDEX))
                            {
                                _wcslwr_s(szHeader, wcslen(szHeader)+1);
                                wstring lwrHeader = szHeader;
                                // get headers to our structure later

                                unsigned int iMaxBufferSize = INT_BUFFERSIZE; // Should proabbly be setting buffer size autoit side somehow
                                unsigned int iCurrentBufferSize = 0;
                                BYTE* m_pResponse = NULL;
                                m_pResponse = new BYTE[iMaxBufferSize];
                                memset(m_pResponse, 0, iMaxBufferSize);

                                do
                                {
                                    dwSize = 0;
                                    if (::WinHttpQueryDataAvailable(hRequest, &dwSize))
                                    {
                                        BYTE *pResponse = new BYTE[dwSize + 1];
                                        if (pResponse != NULL)
                                        {
                                            memset(pResponse, 0, dwSize);
                                            DWORD dwRead = 0;
                                            if (::WinHttpReadData(hRequest,
                                                pResponse,
                                                dwSize,
                                                &dwRead))
                                            {
                                                if (dwRead + iCurrentBufferSize > iMaxBufferSize)
                                                {
                                                    BYTE *pOldBuffer = m_pResponse;
                                                    m_pResponse = new BYTE[iMaxBufferSize * 2];
                                                    if (m_pResponse == NULL)
                                                    {
                                                        m_pResponse = pOldBuffer;
                                                        bRetVal = false;
                                                        break;
                                                    }
                                                    iMaxBufferSize *= 2;
                                                    memset(m_pResponse, 0, iMaxBufferSize);
                                                    memcpy(m_pResponse, pOldBuffer, iCurrentBufferSize);
                                                    delete[] pOldBuffer;
                                                }
                                                memcpy(m_pResponse + iCurrentBufferSize, pResponse, dwRead);
                                                iCurrentBufferSize += dwRead;
                                            }
                                            delete[] pResponse;
                                        }
                                    }
                                }
                                while (dwSize > 0);

                                final=clock()-init;
                                TotalTime = (double)final / ((double)CLOCKS_PER_SEC);

                                // Return anything regardless, unless it took too long
                                if (TotalTime < tData->MaxTestTime)
                                {

                                    bGetReponseSucceed = true;
                                    int p=0;

                                    while (p < sizeof(m_pResponse)) {
                                        if(m_pResponse[p] != NULL)
                                            tData->ResponceHTML[p]=m_pResponse[p]; // write chars to our autoit char array so we can process it over at scriptside
                                        p++;
                                    }

                                    swprintf(tData->ResponceHeaders, INT_BUFFERSIZE, L"%s" ,lwrHeader);
                                    tData->Latency = TotalTime;

                                }
                            }
                        }
                    }
                }
            }
            ::WinHttpCloseHandle(hRequest);
        }
        ::WinHttpCloseHandle(hConnect);
    }

    ::WinHttpCloseHandle(hSession);

    return 1;
} // End of _WinHTTP_Process

Everything looked like it should work right but obviously something is not going over as planned...

I create the thread like so~

Local $ContentType = _
        "Connection: keep-alive" & @CRLF & _
        "Cache-Control: no-cache" & @CRLF & _
        "Pragma: no-cache" & @CRLF & _
        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & @CRLF & _
        "Accept-Language: en-US,en;q=0.8" & @CRLF & _
        "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3" & @CRLF

    $tURL_COMPONENTS = DllStructCreate($tagTHREAD_PARAMETERS)

    DllStructSetData($tURL_COMPONENTS, "UserAgent", "(COMPATABLE; AutoIt/v3)")
    DllStructSetData($tURL_COMPONENTS, "HTTPVerb", "GET")
    DllStructSetData($tURL_COMPONENTS, "Host", "www.google.com")
    DllStructSetData($tURL_COMPONENTS, "Resource", "test")
    DllStructSetData($tURL_COMPONENTS, "Port", $INTERNET_DEFAULT_HTTPS_PORT)

    DllStructSetData($tURL_COMPONENTS, "Referer", "")
    DllStructSetData($tURL_COMPONENTS, "Headers", $ContentType)

    DllStructSetData($tURL_COMPONENTS, "ExtraData", 0)
    DllStructSetData($tURL_COMPONENTS, "Length", 0)
    DllStructSetData($tURL_COMPONENTS, "TotalLength", 0)

    DllStructSetData($tURL_COMPONENTS, "dwResolveTimeout", 30000)
    DllStructSetData($tURL_COMPONENTS, "dwConnectTimeout", 30000)
    DllStructSetData($tURL_COMPONENTS, "dwSendTimeout", 30000) ; 15 seconds
    DllStructSetData($tURL_COMPONENTS, "dwReceiveTimeout", 30000)

    If $Proxy Then
        DllStructSetData($tURL_COMPONENTS, "Proxy", $Proxy)
        DllStructSetData($tURL_COMPONENTS, "ProxyFlags", $WINHTTP_ACCESS_TYPE_NAMED_PROXY)
    Else
        DllStructSetData($tURL_COMPONENTS, "ProxyFlags", $WINHTTP_ACCESS_TYPE_NO_PROXY)
    EndIf

    DllStructSetData($tURL_COMPONENTS, "SendFlags", BitOR($WINHTTP_FLAG_SECURE, $WINHTTP_FLAG_ESCAPE_DISABLE))

    ;DllStructSetData($tURL_COMPONENTS, "RetryTimes", 2); unused now
    DllStructSetData($tURL_COMPONENTS, "MaxTestTime", 60)

    $hThread = CreateThread(DllStructGetPtr($tURL_COMPONENTS)); dllcall() that will pass the structure pointer to the dll as "ptr"

then after creating the thread, the app idles around and waits for the thread to report it terminated.

Once the thread has finished doing its thing, it will write whatever it got my my BYTE array and return it.

The problem comes when I try to access it now...

DllStructGetData($tURL_COMPONENTS, "ResponceHTML")

DllStructGetData() will return the binary equivalent of "<!Doc" and then the rest will be zeros, garbage and totally not what I was expecting..

Any ideas?

I have included a ready to compile project with a script to test the DLL in the release directory.

Full Project.zip

Link to comment
Share on other sites

K, so I will be abandoning this.

Someone shot me shortly after this post so now my focus is set on recovery...

What did "they" point out was wrong?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

What did "they" point out was wrong?

 

No, unrelated to the code, I actually received a bullet to the fovea capitis on the femur, aka the ball joint of the Femur...

Some drunk idiot "shot" me while we were drinking. lol..

Link to comment
Share on other sites

No, unrelated to the code, I actually received a bullet to the fovea capitis on the femur, aka the ball joint of the Femur...

Some drunk idiot "shot" me while we were drinking. lol..

Oh my, sorry to hear that. Have a speedy recovery.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Oh my, sorry to hear that. Have a speedy recovery.

thanks

I hope you punched his stupid face in.

It was a good friend, one eyed guy who was shot in the eye some time ago.

He was drunk and trying to unload a Colt SAA.

he tried pulling on the pin to release the chamber and accidentally pulled back on the hammer which slipped and fired...

LOL, you are still alive.

yes, your work and existence makes me come back.


Anyway, I'm at my PC now and took this on again, managed to make it work after a few more tries..

memcpy(tData->ResponceHTML, m_pResponse, INT_BUFFERSIZE);

this time it's copying everything from the web resource, but now it's returning an ungodly amount of 0s after the resource..

"746D6C3E0000000000000"

How do I make it stop giving me all those null bytes? I'm not sure if this is a problem with DllStructGetData($tURL_COMPONENTS, "ResponceHTML") or that I might be messing up the struct I created in autoit..

Link to comment
Share on other sites

You can clean the array by counting backwards in a loop. Check to see if each element is zero until you get to nonzero. Write everything else out to a temp array and flip it. Something like this maybe:

for (int i = sizeof(m_pResponse), x = 0; i >= 0; --i)
{
    if (m_pResponse[i] == 0)
        continue;
    
    tData->ResponceHTML[x] = m_pResponse[i];
    ++x;
}

That would make it backwards so you'd have to flip it beforehand or on the AutoIt side. 

Link to comment
Share on other sites

Those ungoldy amount of seroes probably the 1048576 elements which weren't filled.  That's my best guess.

...

you're right....

I dunno why i didn't see that, I read on how the function I'm using works and it will return all the array, uncluding the null portions..

Now I guess I need to figure out how to spit out a byte array of variable size so as to avoid all those null bytes..

You can clean the array by counting backwards in a loop. Check to see if each element is zero until you get to nonzero. Write everything else out to a temp array and flip it. Something like this maybe:

for (int i = sizeof(m_pResponse), x = 0; i >= 0; --i)
{
    if (m_pResponse[i] == 0)
        continue;
    
    tData->ResponceHTML[x] = m_pResponse[i];
    ++x;
}

That would make it backwards so you'd have to flip it beforehand or on the AutoIt side. 

 

heh, thanks, but I guess it was actually a problem with my lack of understanding how AutoIts DllStructGetData works.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...