Jump to content
Sign in to follow this  
Dragonfighter

DllCall doesn't work has expected (Solved)

Recommended Posts

Autoit version: 3.3.14.5

System: Windows 10 Home x64

C++ IDE: Code::Blocks 17.12

When I call the Dll that I wrote it give me how return value -1073741819 and exit value 3221225477, I tried changing variables type but it didn't work.

This is the Autoit code:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
$dll = DllOpen(@ScriptDir & "\Test.dll")

DllCall($dll, "NONE", "TestFunction", "STR", "1 string", "STR", "2 string", "STR", "3 string", "INT", 1)
;Here crash and doesn't show the MsgBox
MsgBox(0, "", @error)
DllClose($dll)

This is the main.cpp code:

#include <iostream>
#include <Windows.h>
#include "main.h"
using namespace std;

extern "C"
{
   DECLDIR void TestFunction(std::string string1, std::string string2, std::string string3, int number1)
   {
      std::cout << string1 << std::endl;
      std::cout << string2 << std::endl;
      std::cout << string3 << std::endl;
      std::cout << number1 << std::endl;
    }

}

And that is the main.h:

#ifndef _DLLTEST_H_
#define _DLLTEST_H_

#define DLL_EXPORT
#if defined DLL_EXPORT
  #define DECLDIR __declspec(dllexport)
#else
  #define DECLDIR __declspec(dllimport)
#endif

extern "C"
{
    DECLDIR void TestFunction(std::string string1, std::string string2, std::string string3, int number1);

}
#endif

 

And the values of the variables that write to the SciTe console ae completely different.

Here I attach the console output of the SciTe editor:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\DragonFighter\Desktop\Dll test.au3" /UserParams    
+>10:30:08 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0   Keyboard:00000410  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0410)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\DragonFighter\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\DragonFighter\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\DragonFighter\Desktop\Dll test.au3
+>10:30:08 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\DragonFighter\Desktop\Dll test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
�Á+���Uø‰q�‰A�‹O`ÆEÿ�èèÖÿÿƒÄ €}ÿ!>10:30:10 AutoIt3.exe ended.rc:-1073741819
+>10:30:10 AutoIt3Wrapper Finished.
>Exit code: 3221225477    Time: 3.414

 

Thanks in advance for every reply.

Edited by Dragonfighter

Share this post


Link to post
Share on other sites

The calling convention is cdecl, not stdcall. So replace "none" with ""none:cdecl"

Share this post


Link to post
Share on other sites

Because if I use a code that I found here:

,that you wrote, it works. Maybe I wrong someting in string passing. I tried also to change STR to WSTR but it didn't work

Share this post


Link to post
Share on other sites

Thought that code looked familiar.^_^ Your string parameter definitions in the cpp are wrong, use LPSTR/LPTSTR/LPCSTR; see an example here. Conversion list is here (and in DllCall Help).

Edited by RTFC

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
Sign in to follow this  

  • Similar Content

    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.20 contains 197 functions divided into these topics:
      window, desktop and monitor mouse and GUI GUI controls including graphical buttons (jpg, png) logics and mathematics include constants string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info Change log and files section  on the PAL website (SourceForge).
      A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By topgundcp
      Hi, 
      This is my very first post in this forum and am also new with Autoit programming so be easy on me.
      Below is the code that I am trying to get the index of the item selected. No problem getting the text.
      Case $listEdition   ; handle of the list             local $index=0             $item=GUICTRLRead($listEdition)    ; This will return the text in the list             ; ==============   The loop below always fails  ==================             ; Meaning _GUICtrlListView_GetItemSelected($listEdition, $i) always return FALSE. WHY ???????              For $i = 0 To $editionArray[0] - 1   ; The content of the list in an array where editionArray[0] contains total count of items                 If _GUICtrlListView_GetItemSelected($listEdition, $i) Then                     $index = $i                     exitloop                 EndIf              Next              ;===================================================             ConsoleWrite( "Select Edition:     " & $item & "  index: " & $index & @CR) ....... Please look at the comments in the code & the pix attached.
      _GUICtrlListView_GetItemSelected($listEdition, $i) always returns FALSE.
      Another problem is on the list. It also populate  the total count of items from the Array. How can I skip this item from populating to the list ?.
      Please advise and thanks

    • By n0ktar
      is it possible to make a wall chams in rainbow six siege using autoit scripts? tell me please and how . 
    • By Rskm
      Hi, I am using excel as input media for my program. The excel file (i tried with .xls, .xlsx and .xlsm format) has inputs which the autoit script reads during the run and performs few calculations. Some times (not always), after the run, when i try to open the excel file manually, the file doesnt open at all in excel. see the screenshot attached. However, if the execute the autoit script, the scripts still reads the existing data from that excel and performs the calcs. I copied the excel file to another computer and there too, it doesnt open.  So, after this, i cannot edit the excel forever (if i need to change any inputs). It is only this particular file that got affected. other excel files works normal.  What could be the problem here.  please help as this is a new challenge for me during my program development. 

    • By TheAutomator
      Hi everyone!

      I'm using AutoIt for several years now and I really get the hang of it!
      I'm quite the curious OCD perfectionist kind of guy, so I can't help wondering..
      what would be the best way to program stuff for the compiler / interpreter / scripting engine?
      We're talking about the inner workings of the AutoIt's core here, and how to give it as less friction as possible but also take care of the machine running the script.
      For example,
      Imagine a script where we would constantly have to assign a Boolean value to a variable:
      ; A: local $bool = false $bool = true $bool = true $bool = false ; B: local $bool = false check(true) check(true) check(false) func check($b) if $bool = $b then return $bool = $b endfunc In this case, would it be better to just overwrite (A) the variable or first check if we really need to (B)?
      What would be best for the computers memory if it had to do this for a year non stop?
      Another example, imagine you're writing a function with an if statement.
      If you would look under the hood of AutoIt, what would be the best way to give your computer as less work / code nesting stack filling as possible:
      ; A: func decide($b_Input) if $b_Input then ;do something else ;do something else endif endfunc ; B: func decide($b_Input) if $b_Input then ;do something return endif ;do something else endfunc Last one for now:
      ; A: while 1 ; do stuff wend ; B: while true ; do stuff wend Isn't AutoIt taking an extra step in converting 1 to a Boolean in example (A)?
      Or is it the other way around and does the (B) way make AutoIt first convert a keyword (true or false) to a numerical value (0 or 1).
      I think this kinda detail stuff is quite interesting, makes me wonder how AutoIt converts and runs our code.
      What are your opinions on this topic?
      Any coders who know more about the inner workings of AutoIt?
      Any people like me who ask themselves similar questions (with examples)?

      Let me know! 😉
×
×
  • Create New...