Sign in to follow this  
Followers 0
kmeleon

Example DLL in C++ Visual Studio

8 posts in this topic

Hello

Example DLL in Visual Studio

File->New Project->Other language->Visual C++ ->Win32->Win32 Project->Name= "ExampleDLL"->OK->Next->Dll->Finish

In Solution Explorer

Source Code->ExampleDLL.cpp

//ExampleDll.cpp

#include "stdafx.h"

        int _stdcall Add( int a, int b )
        {
            return a + b;
        }

In Solution Explorer "Source Code"->Right mouse->Add->New Item->Code->Module-Definition File (.def)->Name "ExampleDLL"->Add

//ExampleDLL.def
LIBRARY "ExampleDLL"

EXPORTS
Add @1

In Solution Explorer Header Files->Right mouse->Ad->New Item->Code->Header File (.h)->Name ExampleDLL->Add

//ExampleDLL.h
int Add(int a, int b);

Menu->Build->Build ExampleDLL

;example AutoIT
$h = ""&@ScriptDir &"\ExampleDLL.dll"

$Add = DllCall(""&$h, "int", "Add", "int", 10 ,"int", 9)

    If @error <> 0 Then
        MsgBox(0,""&$Add,"error: "&@error)
    Else
         MsgBox(0,"",""&$Add[0])
     EndIf

Feed Polish children: pajacyk - just go to this page and close it. Thanks. World website: free rice.

Share this post


Link to post
Share on other sites



this example not working... I did exactly what you wrote ... Any ideas why ?

$Add = DllCall(@ScriptDir &"ExampleDLL.dll", "int", "Add", "int", 10 ,"int", 9)

MsgBox(0,"",""&$Add[0])


[RU] Zone

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

A simpler way is using DllExport, no need to def.

Edited by D4RKON3

Share this post


Link to post
Share on other sites

Can you post an working example please ? :]


[RU] Zone

Share this post


Link to post
Share on other sites

OK, here we go. I have attached a C++ source code, I suggest you using VS (2010) to compile it.

You can find the compiled Dll from the Release folder within the attached zip package.

The AutoIt part should be like this:

Global $sum = DllCall('DllExport.dll', 'int:cdecl', 'Sum', 'int', 5, 'int', 5)
MsgBox(0, '', $sum[0])

Share this post


Link to post
Share on other sites

Thanks A lot :) It Works !!!


[RU] Zone

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  
Followers 0