Jump to content

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

×
×
  • Create New...