Jump to content

DllOpen returens -1 dllcall fail


Recommended Posts

Hello guys!

I am trying to call a dll file I have created in cpp. I followed this tutorial : https://www.autoitscript.com/forum/topic/123827-create-basic-dll-file-and-use-it-with-autoit/

and did everything exactly the same. I ended up with a basicdll.dll file, which I copied to my script folder. I then proceeded and and tried to open the dll file with OpenDll as mentiond in the tutorial.

 

$dll1 = DllOpen("basicdll.dll")
$dll2 = DllOpen("user32.dll")
   SetLog("dll2 " & $dll2)
   SetLog("dll1 " & $dll1)

I also copied user32.dll to my script folder in order to check if the dllopen function is working. 

this is the result of the log

[9:00:43 PM] dll1 -1
[9:00:44 PM] dll2 4
[9:00:44 PM] dll1 -1
[9:00:46 PM] dll2 5
[9:00:46 PM] dll1 -1
[9:00:47 PM] dll2 6

as you can see for some reason the basicdll.dll wont open and returns -1 to indicate failure. But dll2 is opening just fine. I also tried to run the script as x86 by using the following command in the script:

#RequireAdmin
#AutoIt3Wrapper_UseX64=n

I also ensured that the dll was compiled as x86 in the properties menu in visual studio.

this is really weird and I haven't seen anything like this anywhere on the internet.  

I am running win 7 sp1 64 bit with autoit x64 installed.

Link to comment
Share on other sites

that was quick :) 

header:

#ifndef _DLL_TUTORIAL_H_
#define _DLL_TUTORIAL_H_  // This is basically to tell compiler that we want to include this code only once(incase duplication occurs), you include it in .cpp file(which we will soon do)
#include <iostream>       // Inlcude basic c++ standard library output header(this is used for output text on the screen in our code)

#define DECLDIR __declspec(dllexport)

// We #define __declspec(dllexport) as DECLDIR macro so when compiler sees DECLDIR it will just take it as __declspec(dllexport)(say that DECLDIR is for readability)
// Note that there is also __declspec(dllimport) for internal linking with others programs but since we just need to export our functions so we can use them with Autoit, thats all we need!


extern "C"  // this extern just wraps things up to make sure things work with C and not only C++
{

// Here we declare our functions(as we do with normal functions in c header files, our cpp file will define them(later). Remember that DECLDIR is just a shortcut for __declspec(dllexport)

   DECLDIR int Add( int a, int b ); 
   DECLDIR void Function( void );
}

#endif // closing #ifndef _DLL_TUTORIAL_H_

cpp:

#include <iostream>
#include <Windows.h> // this is where MessageBox function resides(Autoit also uses this function)

#include "basicdll.h" // We include our header file which contains function declarations and other instructions


extern "C" // Again this extern just solves c/c++ compatability [b]Make sure to use it because Autoit wont open dll for usage without it![/b]
{
   DECLDIR int Add( int a, int b )
   {
      return( a + b ); // Finally we define our basic function that just is a sum of 2 ints and hence returns int(c/c++ type)
   }

   DECLDIR void Function( void )
   {
      std::cout << "DLL Called! Hello AutoIt!" << std::endl; // This silly function will just output in our Autoit script "Dll Called!"
      MessageBox(0, TEXT("DLL from Autoit"), TEXT("Simple Dll..."),0);  // Use good old Message Box inside Windows Api Functions but this time with your own dll }
   }
}

 

Edited by TheShaps
Link to comment
Share on other sites

<snipped on my own> saw at beginnign something wrong^^

 

Edited by RaiNote
  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Link to comment
Share on other sites

Yes I am using .NET v 4.0.30319 with visual studio 2010 sp1.

Also do you mean something like main function with Entry Point? could you please show an example of how to use it, or better, implement it to my code.

Thanks!

Link to comment
Share on other sites

May that work for you Code credits standardly goes to(Link)

Project Visual Studio 2013(DLink(10Mb)compiled .dll avaible)

And what is the Function SetLog ? °-°

  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Link to comment
Share on other sites

Just a Little Question The "TEXT" isn't any normal Thing within C++ so may it compiled the dll wrong :o

 

  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Link to comment
Share on other sites

@JohnOne you mean me? but while we are here With a DLL question would it be possible to Load from a DLL Images etc( Resources )?

Edited by RaiNote
  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Link to comment
Share on other sites

The SetLog is like console thing but it outputs to my program that has gui. Also I am aware that there are some other tut out there, I tried this one earlier but failed, this tut running aroud sevral sites, with slight variations. And what is the second link you provided with?

Also what do you mean by "TEXT" ? 

 

Link to comment
Share on other sites

MessageBox(0, TEXT("DLL from Autoit"), TEXT("Simple Dll..."),0);  This

and a Little Tip look here

Edited by RaiNote
  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Link to comment
Share on other sites

Parameters

hWnd [in, optional]

Type: HWND

A handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.

lpText [in, optional]

Type: LPCTSTR

The message to be displayed. If the string consists of more than one line, you can separate the lines using a carriage return and/or linefeed character between each line.

lpCaption [in, optional]

Type: LPCTSTR

The dialog box title. If this parameter is NULL, the default title is Error.

uType [in]

Type: UINT

The contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags.

You can only do These Things within the MessageBox Function. 

  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Link to comment
Share on other sites

I have marked dll option when creating the project, just like in the tutorial. Also I downloaded the DllBasics.zip RaiNote 

 provided with, and copied the BasicDll.dll file to my script folder, and then executed OpenDll like before and surprisingly enough it didn't work. I don't think the fault here is within the dll files, there is something else, since the dll files came from the tutorial. Also mine basically came form a tutorial as well. The thing that throws me off here, is that the user32.dll file actually works, so why isnt the other dll files work? I also manged to use other dll files successfully before, but the dll files weren't mine.

sorry for the hassle 

Edited by TheShaps
Link to comment
Share on other sites

Is the Dll next to the AutoIt Script? and is the DLL Name within the Script same as the DLL ?

  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Link to comment
Share on other sites

The MsgBox within the cpp will not show up, because it fails to load -.- , this is the problem. And there are no errors within the visual studio. Visual studio manged to successfully compile the file into dll.

Edit:

yes the dll file and the script file are in the same folder. I have checked and the file names match there is no typo. I know this is kinda of a big favor to ask but could you please try and run the files on your pc. The one you provided with the Basicdll.zip, see if you can call it and it wont return -1.  

Thanks

Edited by TheShaps
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...