Jump to content

making a dll for autoit


FuryCell
 Share

Recommended Posts

I have the following dll I compile with the codeblocks C++ ide.

#include "main.h"

// a sample exported function
void DLL_EXPORT Hello()
{
    MessageBoxA(0, "Hello", "DLL Message", MB_OK | MB_ICONINFORMATION);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}

However the dll does not seem to work. If I try to open the dll with autoit it returns -1 which means an error has occured. What am I doing wrong?

$Handle=DllOpen(@ScriptDir&"\Listview.dll")
MsgBox(0,@Error,$Handle)
DllCall($Handle,"none","hello")

Listview.dll

Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

What is DLL_EXPORT?

However the main reason is probably because the exported name is messed up, add extern "C" before the decleration to fix.

You can check what name the function got exported as with for example the export viewer in my sig or trancexx's Resource viewer and compiler.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

#ifndef __MAIN_H__
#define __MAIN_H__

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus
extern "C"
{
#endif

void DLL_EXPORT SomeFunction(const LPCSTR sometext);

#ifdef __cplusplus
}
#endif

#endif // __MAIN_H__

I'm not sure if its a problem with the function name because the dll fails to even open regardless of weather I call a function. I will however take a look at the exports. Also where do I put the C to prevent the function from being renamed.

Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Yeah, your header is a little goofy. As monoceres suggested, and based on the plugin SDK:

#ifndef __MAIN_H__
#define __MAIN_H__

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef __cplusplus
    #define DLL_EXPORT extern "C" __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllexport)
#endif

#endif

And make sure you call your functions as 'cdecl'.

Edited by wraithdu
Link to comment
Share on other sites

Maybe someone can post an example codeblocks project of a dll for autoit. It would be much appreciated.

Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Yeah, your header is a little goofy. As monoceres suggested, and based on the plugin SDK:

#ifndef __MAIN_H__
#define __MAIN_H__

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef __cplusplus
    #define DLL_EXPORT extern "C" __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllexport)
#endif

#endif

And make sure you call your functions as 'cdecl'.

I'll take a look at that fix. Thanks.
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

I'll take a look at that fix. Thanks.

After using that header I get this error.
C:\Users\Michael\Desktop\work\testdll\main.cpp|4|error: expected unqualified-id before string constant|

Here is my main.cpp

#include "main.h"

// a sample exported function
void DLL_EXPORT hello()
{
    MessageBoxA(0,"Hello", "DLL Message", MB_OK | MB_ICONINFORMATION);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

DLL_EXPORT void hello()

That got it to compile but after compiling and looking at the dll it looks like hello has the proper function name. However dllopen still fails with -1 which would indicate something is wrong with my dll. Anyone here have codeblocks and wanna take a look at my project file?
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Hmm, that is interesting. I compiled the exact project in Visual Studio 2008 and it opens and I can call the function just fine. Are you compiling it as a debug release or something maybe? I'm not even sure that would matter though...

Odd. I'm compiling it as a release. I'll try it in visual studio though.

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

I'm really interested in a dll for listview sort. I'd be eternally grateful if someone could make such a thing. I also think it would be a great addition for autoit since sorting listviews with a lot of items can be slow. :)

Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

What was the DllOpen() error returned?

Are you sure your project settings are correct? You're not compiling for x64 or something weird? Have all required redistributables installed?

I figured out what the problem was. I have a 64bit os so AutoIt runs scripts as 64 bit by default. This caused it not to be able to load my 32 bit dll.

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
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...