jasperhale

C++ DLL Examples Please

11 posts in this topic

#1 ·  Posted (edited)

Hello,

I want to learn how to write C++ Code.

Can anyone please show me some examples in C++ ? I want to make some dll by Visual C++ but i dont know C++ at all.

Just search in google and see something.
 

;Example.h
int Add(int a, int b);
; Example.cpp
#include "stdafx.h"

long _stdcall Add( int a, int b )
        {
            return a + b;
        }
; example.def
LIBRARY "example"

EXPORTS
Add @1

 

 

I want more examples please, just some basic function.

If anyone know VC++ DLL please help me some examples :

- AutoIT send some text to DLL, DLL process and return some text....

- AutoIT send EXE path to DLL and DLL open it.

 

Please show source so i can learn from it.

Thanks you verry much.

Edited by jasperhale

Share this post


Link to post
Share on other sites



2 hours ago, jasperhale said:

Can anyone please show me some examples in C++ ? I want to make some dll by Visual C++ but i dont know C++ at all.

Did you realized, where you are posting? "AutoIt General Help and Support"! I suggest ask in a C++ Forum.

Share this post


Link to post
Share on other sites
56 minutes ago, AutoBert said:

Did you realized, where you are posting? "AutoIt General Help and Support"! I suggest ask in a C++ Forum.

No, you dont understand.

If i post in C++ Forum, they never use AUTOIT, so they dont have right examples.

I want C++ examples to build DLL files that use in AutoIT.

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@moderators: Please move this thread to AutoIt's C++ forum (AutoBert is right that it doesn't belong in General Support, but it doesn't belong in C#/.NET either!).

@jasperhale:I think AutoBert meant moving your post to AutoIt's C++ sub forum.:) There you'll likely find simple dll implementation examples. For a more advanced example, see my Eigen4AutoIt wrapper library (link in my sig; includes source example for one of the dlls I wrote for that package).

Edited by RTFC

Share this post


Link to post
Share on other sites

Sorry, finger trouble for the first move.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

18 minutes ago, RTFC said:

@moderators: Please move this thread to AutoIt's C++ forum (AutoBert is right that it doesn't belong in General Support, but it doesn't belong in C#/.NET either!).

@jasperhale:I think AutoBert meant moving your post to AutoIt's C++ sub forum.:) There you'll likely find simple dll implementation examples. For a more advanced example, see my Eigen4AutoIt wrapper library (link in my sig; includes source example for one of the dlls I wrote for that package).

Ok i will download and see it, thanks you verry much. If you have any basic c++ examples, please give to me, i'm too bad in C++.

 

Edited : I cant download Eigen4AutoIT, when downloaded, and unrar, its come with error, can you please reupload it for me ???

Edited by jasperhale

Share this post


Link to post
Share on other sites

@Melba23: no worries, mate.

@jasperhale: I just tested that the Eigen4AutoIt archive contains no errors. You need to unzip it with 7-zip though, not unrar it.;) Re simpler examples, please search AutoIt's C++ forum, as I suggested earlier (I am not going to hold your hand every step of the way; show us what you've tried, and we may be able to solve specific issues you're having, or suggest why it might not be working as expected:)).

NB you may wish to consult monoceres's dll Tutorial as well.

Share this post


Link to post
Share on other sites

@jasperhale I'm not sure how to do what you're looking for specifically, but I've linked some posts that may help you on your search. Hopefully, these will give you a better understanding on how to use AutoIt with DLLs

This is a post I did that allowed me to Login as another user and Impersonate them using DLLs

 

Share this post


Link to post
Share on other sites
43 minutes ago, RTFC said:

@Melba23: no worries, mate.

@jasperhale: I just tested that the Eigen4AutoIt archive contains no errors. You need to unzip it with 7-zip though, not unrar it.;) Re simpler examples, please search AutoIt's C++ forum, as I suggested earlier (I am not going to hold your hand every step of the way; show us what you've tried, and we may be able to solve specific issues you're having, or suggest why it might not be working as expected:)).

NB you may wish to consult monoceres's dll Tutorial as well.

@RTFC Thanks You verry much, i have install 7-zip, and i can unzip good.

But maybe you and @Surf243 were wrong.

I dont want to learn how to use DLL in AutoIT, i want to learn how to write C++, and build to DLL.

I use DLL Call in AutoIt many times, so i think i can do good in AutoIT.

But i dont know how to write C++ code, and build to DLL. I dont know at all.

I just have some basic examples but i dont have more, if you have C++ Code Examples, please share with me, i will learn from it.

Thanks you verry much again.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I understand you quite well, jasperhale.:huh: If you were to examine subdir .\Eigen4AutoIt\source, you'll find EigenDense.cpp (the C++ source code I wrote) and EigenDense.h (the associated header file). These contain the C++ functions called in Eigen4AutoIt.au3 (the AutoIt wrapper library). But I realise this is probably a bit complicated if you've never written a dll before. So just this once I'll provide you with a really basic example.

dlltest.h (header file)

#ifndef _DLLTEST_H_
#define _DLLTEST_H_  // This is basically to tell compiler that we want to include this code only once(in case duplication occurs)

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

extern "C"
{
    // declare all functions here
   DECLDIR void Function( void );
   DECLDIR int Add( int a, int b ); 
   
}
#endif

 

dlltest.cpp (C++ source)

#include <iostream>
#include <Windows.h> // this is where MessageBox function resides(Autoit also uses this function)
#include "dlltest.h" // We include our header file which contains function declarations and other instructions

using namespace std;

extern "C"
{

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

   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 }
    }

}

Of course, you need to compile this as a dll, not as an executable! As you can tell from the code below, I'm using MSVC2010 here, but any decent C++ compiler will do.

Finally, the AutoIt script calling this dll:

$dll = DllOpen("<fill in your drive+directory structure here>\Visual Studio 2010\Projects\dlltest\Debug\dlltest.dll")

DllCall($dll, "none", "Function")

$test = DllCall($dll, "int:cdecl", "Add", "int", 2, "int", 3)
MsgBox(0,"Error: " & @error,$test[0])

DllClose($dll)

This script calls a C++ function called Function, which returns nothing (void), but calls a Windows Messagebox, and writes some text to Console. It then calls the C++ function Add with two parsed integers (2 and 3), returning their sum (also as an integer). Once everything works as expected, we can compile the Release version (without extra error handling and padding), and copy the dll to wherever we need it.

All clear now?

Edited by RTFC

Share this post


Link to post
Share on other sites
9 hours ago, RTFC said:

I understand you quite well, jasperhale.:huh: If you were to examine subdir .\Eigen4AutoIt\source, you'll find EigenDense.cpp (the C++ source code I wrote) and EigenDense.h (the associated header file). These contain the C++ functions called in Eigen4AutoIt.au3 (the AutoIt wrapper library).

All clear now?

 

Yes, thanks you verry much.

I can see the source cpp from EigenDense.cpp but as you said, i dont know C++ at all, that 's why i cant understand it.

This examples is good, i love it.

Thanks you verry much.

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