Jump to content

Search the Community

Showing results for tags 'DLLCALL cdecl stdcall'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. Here's my situation: I've dinked around with trying to create a C++ object in AutoIt by matching the object declaration as a struct, and failed miserably. No doubt it's because while I understand in principal what "BEGIN_INTERFACE" and "END_INTERFACE" do, I don't really know what they do in actual fact, and consequently I can't replicate that when designing an AutoIt struct. So - I figured I'd write a C DLL that fronts and/or wrappers my C++ objects that will allow me to basically steer them from AutoIt. To validate that I know WTF I'm doing, I figured I'd write a dead simple C++ object and wrapper functions that allow me to communicate back and forth. I can get it all to work if I declare my wrappers as __cdecl, but I can't get it to work if they're declared __stdcall. I'm compiling from mingw. Keep in mind that the code below is only intended to validate my thoughts. So I took some fairly obvious and glaring shortcuts with safety and etcetera because I'm simply validating that I can instantiate a C++ object, and then have it call back to my AutoIt code. We're not necessarily interested in style. What I'm interested in is why AutoIt can't see the functions if they're declared __stdcall. I must be blind, or too close to the problem, because I just can't see why it doesn't work. If I alter everything to use __cdecl it all works swimmingly. With it as is, I get the error printout below. All my code: // File: test.h #ifndef _TEST_H_ #define _TEST_H_ #ifdef BUILDING_TEST_DLL #define TEST_DLL __declspec(dllexport) #else #define TEST_DLL __declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif void __stdcall TEST_DLL init(void); void __stdcall TEST_DLL uninit(void); void __stdcall TEST_DLL add_callback(const void * callback); void __stdcall TEST_DLL do_callback(void); #ifdef __cplusplus } #endif #endif // _TEST_H_ // File: test.cpp #include <stdlib.h> #include <vector> #include "test.h" #define test_callback size_t class TestObject { public: void __stdcall AddCallback(const void * pCallback); void __stdcall DoCallback(void); TestObject(); ~TestObject(); private: std::vector<const void *> m_pCallbacks; size_t m_uiLastIndex; }; TestObject::TestObject() { m_pCallbacks.reserve(10); m_uiLastIndex = 0; } TestObject::~TestObject() { // No action needed since vector cleans up } void __stdcall TestObject::AddCallback(const void * pCallback) { if(pCallback) m_pCallbacks.push_back(pCallback); } void __stdcall TestObject::DoCallback(void) { size_t (*callback) (size_t); callback = (size_t(*)(size_t)) m_pCallbacks[m_uiLastIndex]; callback(m_uiLastIndex); m_uiLastIndex++; if(m_uiLastIndex > (m_pCallbacks.size() -1)) { m_uiLastIndex = 0; } } // C Wrapper functions TestObject * test_object; void __stdcall init() { test_object = new TestObject(); } void __stdcall TEST_DLL uninit(void) { delete test_object; } void __stdcall TEST_DLL add_callback(const void * callback) { test_object->AddCallback(callback); } void __stdcall TEST_DLL do_callback(void) { test_object->DoCallback(); } OnAutoItExitRegister("TestDone") Local $func_template = "CallBack%d" Local $handles[4] Local $pointers[4] Local $dll = DllOpen("test.dll") DllCall($dll, "NONE", "init") If @error Then TranslateDllCallError(@error, "init") EndIf For $i = 0 To UBound($handles) - 1 Local $name = StringFormat($func_template, ($i + 1)) $handles[$i] = DllCallbackRegister($name, "ULONG_PTR", "ULONG_PTR") $pointers[$i] = DllCallbackGetPtr($handles[$i]) DllCall($dll, "NONE", "add_callback", "PTR", $pointers[$i]) If @error Then TranslateDllCallError(@error, "add_callback") Else ConsoleWrite("Added pointer " & $i & @LF) EndIf Next For $i = 1 To 10 DllCall($dll, "NONE", "do_callback") Next Func TranslateDllCallError($err, $func) Switch $err Case 1 ConsoleWriteError("Unable to use DLL file" & @LF) Case 2 ConsoleWriteError("Unknown 'return type'" & @LF) Case 3 ConsoleWriteError("'" & $func & "' not found in the DLL file" & @LF) Case 4 ConsoleWriteError("Bad number of parameters" & @LF) Case 5 ConsoleWriteError("Bad parameter" & @LF) Case Else ConsoleWriteError("Unknown error value" & @LF) EndSwitch EndFunc Func CallBack1($param) ConsoleWrite("CallBack1(" & $param & ")" & @LF) Return $param EndFunc Func CallBack2($param) ConsoleWrite("CallBack2(" & $param & ")" & @LF) Return $param EndFunc Func CallBack3($param) ConsoleWrite("CallBack3(" & $param & ")" & @LF) Return $param EndFunc Func CallBack4($param) ConsoleWrite("CallBack4(" & $param & ")" & @LF) Return $param EndFunc Func TestDone() For $i = 0 To UBound($handles) - 1 DllCallbackFree($handles[$i]) Next DllCall($dll, "NONE", "uninit") If @error Then TranslateDllCallError(@error, "uninit") EndIf DllClose($dll) EndFunc :: build.bat @echo off IF EXIST *.dll DEL *.dll IF EXIST *.o DEL *.o IF EXIST *.a DEL *.a g++ -Wall -c -DBUILDING_TEST_DLL test.cpp g++ -shared -o test.dll -static-libgcc -static-libstdc++ test.o -Wl,--out-implib,libtest_dll.a
×
×
  • Create New...