Jump to content

AutoIt3.exe ended.rc:-1073741819 with my Own Dll


NoNameCode
 Share

Go to solution Solved by Werty,

Recommended Posts

Hi there,

 

im working right now on my DLL for my W32 AutoIt GUIDarkTheme UDF Project.

Sadly i dont get why there ist that Error when using DLLCall

 

AutoIt Test Code:
 

; Pointer for Hooked Functions
Global $PTR_OPENNCTHEMEDATA_ORIG

;*******************************************************************************
; ERROR HANDLER
;*******************************************************************************
Local $oMyError = ObjEvent("AutoIt.Error", "ErrFunc")

; This is a custom error handler
Func ErrFunc($oError)
    Local $bHexNumber = Hex($oError.number, 8)
    ConsoleWrite(@CRLF & @CRLF & "We intercepted a Error ! " & _
            " Number: 0x " & Hex($oError.number, 8) & @CRLF & _
            "Description: " & $oError.windescription & _
            "At line: " & $oError.scriptline & @CRLF & @CRLF & _
            "@AutoItVersion = " & @AutoItVersion & @CRLF & _
            "@AutoItX64 = " & @AutoItX64 & @CRLF & _
            "@Compiled = " & @Compiled & @CRLF & _
            "@OSArch = " & @OSArch & @CRLF & _
            "@OSVersion = " & @OSVersion & @CRLF & _
            "Scriptline = " & $oError.scriptline & @CRLF & _
            "NumberHex = " & $bHexNumber & @CRLF & _
            "Number = " & $oError.number & @CRLF & _
            "WinDescription = " & StringStripWS($oError.WinDescription, 2) & @CRLF & _
            "Description = " & StringStripWS($oError.Description, 2) & @CRLF & _
            "Source = " & $oError.Source & @CRLF & _
            "HelpFile = " & $oError.HelpFile & @CRLF & _
            "HelpContext = " & $oError.HelpContext & @CRLF & _
            "LastDllError = " & $oError.LastDllError & @CRLF)

EndFunc   ;==>ErrFunc


Global $hUxHookOpenTheme_DLL =  DllOpen("UxHookOpenTheme.dll")              ;Opens UxHookOpenTheme.dll

If $hUxHookOpenTheme_DLL = -1 Then MsgBox(0, 'DllOpen', $hUxHookOpenTheme_DLL)
$pHookOpenNcThemeData = DllCallbackRegister('__HookedOpenNcData', 'HANDLE', 'hwnd;wstr')
If @error Then MsgBox(0, 'DllCallbackRegister', @error)
;<================================================================================================================================= Error happens right here
$aResult = DllCall($hUxHookOpenTheme_DLL, 'ptr', 'HookOpenNcThemeData', 'ptr', DllCallbackGetPtr($pHookOpenNcThemeData))
;<================================================================================================================================= 
$PTR_OPENNCTHEMEDATA_ORIG = $aResult[0]
MsgBox(0, 'DllCall', @error & @CRLF & $hUxHookOpenTheme_DLL)
OnAutoItExitRegister("__DLLClose_UxHookOpenTheme_DLL")
Func __DLLClose_UxHookOpenTheme_DLL()
    DllClose($hUxHookOpenTheme_DLL)
EndFunc

;....

Func __HookedOpenNcData($hWnd, $pszClass)
    If StringInStr($pszClass, 'ScrollBar') Then $pszClass = 'Explorer::Scrollbar'
    ConsoleWrite(@CRLF & '__HookedOpenNcData > $hWnd: ' & $hWnd & ' > $pszClass: ' & $pszClass)
;~  Return DllCallAddress('handle', $PTR_OPENNCTHEMEDATA_ORIG, 'hwnd', $hWnd, 'wstr', $pszClass)
EndFunc



C++ DllCode: (DllMain.cpp)
 

#include "pch.h"        //Must allways be the First Include!!!
#include <windows.h>
#include <detours.h>
#include <Uxtheme.h>



#define EXPORT comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)       //Macro for Export Function https://stackoverflow.com/questions/538134/exporting-functions-from-a-dll-with-dllexport


// Definition des Funktionszeigers für die originale OpenNcThemeData-Funktion
typedef HTHEME(WINAPI* OpenNcThemeDataPtr)(HWND hwnd, LPCWSTR pszClass);

// Funktionszeiger für die originale OpenNcThemeData-Funktion und die umgeleitete Funktion
OpenNcThemeDataPtr TrueOpenNcThemeData = NULL;

// Custom-Dateiname für die gespeicherten Klassennamen
const char* pszFileName = "OpenNcThemeData.txt";

// Benutzerdefinierte umgeleitete Funktion für OpenNcThemeData
HTHEME WINAPI MyOpenNcThemeData(HWND hwnd, LPCWSTR pszClass)
{

    // Ändern aller ScrollBar in Explorer::ScrollBar
    if (wcscmp(pszClass, L"ScrollBar") == 0)
    {
        hwnd = nullptr;
        pszClass = L"Explorer::ScrollBar";
    }

    // Weiterleitung des Aufrufs an die ursprüngliche Funktion
    return TrueOpenNcThemeData(hwnd, pszClass);
}


PVOID HookOpenNcThemeData(PVOID ptrMyOpenNcThemeData)
{
    // Exportiere die Function in der DLL!
#pragma EXPORT

// Laden der uxtheme.dll
    HMODULE hModule = LoadLibraryW(L"uxtheme.dll");
    if (hModule == NULL) {
        // Fehlerbehandlung, wenn die Bibliothek nicht geladen werden kann
        return FALSE;
    }

    // Abrufen des Funktionszeigers für die echte OpenNcThemeData-Funktion über ihren Ordinalwert 49
    TrueOpenNcThemeData = (OpenNcThemeDataPtr)GetProcAddress(hModule, MAKEINTRESOURCEA(49));
    if (TrueOpenNcThemeData == NULL) {
        // Fehlerbehandlung, wenn die Funktion nicht gefunden werden kann
        FreeLibrary(hModule);
        return FALSE;
    }

    // Beginn der Detours-Transaktion
    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());

    // Umleitung von OpenNcThemeData auf unsere benutzerdefinierte Funktion
    DetourAttach((PVOID*)&TrueOpenNcThemeData, ptrMyOpenNcThemeData);

    // Abschluss der Detours-Transaktion
    DetourTransactionCommit();
    return TrueOpenNcThemeData;
}

BOOL UnHookOpenNcThemeData(PVOID ptrMyOpenNcThemeData)
{
    // Exportiere die Function in der DLL!
#pragma EXPORT

// Beginn der Detours-Transaktion
    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());

    // Entfernen der Umleitung von OpenNcThemeData
    DetourDetach((PVOID*)&TrueOpenNcThemeData, MyOpenNcThemeData);

    // Abschluss der Detours-Transaktion
    DetourTransactionCommit();

    return true;
}

// ######################################################################################################################

// DllMain-Funktion
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
    if (DetourIsHelperProcess()) {
        return TRUE;
    }

    if (dwReason == DLL_PROCESS_ATTACH) {
        
        // HookOpenNcThemeData((PVOID*)MyOpenNcThemeData);   //<<<<<<<< IF Called with Test Fuction in C++ and no DllCall in Autoit it works as Expected
        // Bibliothek hinzufügen        
    }
    else if (dwReason == DLL_PROCESS_DETACH) {
        
        // Bibliothek wieder entfernen
    }
    return TRUE;
}


I have honestly no clue if i do something wrong when it comes to the DLL Export, or how i Call the DLL Function.

1) When i Call the C++ Hook Fuction of it, then everything is fine, so i guess the function works as intended
2) When i try to Call it via Autoit .... : AutoIt3.exe ended.rc:-1073741819, as soon as i call "DllCall($hUxHookOpenTheme_DLL, 'ptr', 'HookOpenNcThemeData' ..."
3) Even with a Error Func "ObjEvent("AutoIt.Error", "ErrFunc")" i dont get any error output :(

Thank you and kind regards
NoNameCode

UxHookOpenTheme.zip

Edited by NoNameCode
Added DLL
Link to comment
Share on other sites

Indeed it's about calling convention. Seeing the dependencies I suppose you compiled with VS. If you want to create a UDF don't forget to mention to users to install the dependencies.

When the words fail... music speaks.

Link to comment
Share on other sites

20 hours ago, Andreik said:

Indeed it's about calling convention. Seeing the dependencies I suppose you compiled with VS. If you want to create a UDF don't forget to mention to users to install the dependencies.

ill test on a fresh Win10 if extra installations ar needed. Thanks for the advice :)

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...