Jump to content

Recommended Posts

Posted (edited)

ive been trying to create a ConsoleDll for a calculator.. but if i just use this (the Template for a Console App in Dev-C++)

#include <windows.h>
#include <cstdlib>
#include <iostream>

using namespace std;

extern "C" declspec(dllexport) int main(int argc, char *argv[])
{
    system("PAUSE");
    return EXIT_SUCCESS;
}

i think thats how it goes, just sort of off the top of my head, but you get the point.. that will work if i do a

DllCall ("CalcQ.dll", "int", "Main")

then i get the console window... but when i use this:

/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
#include <cstdlib>
#include <iostream>

DllClass::DllClass()
{

}


DllClass::~DllClass ()
{

}


BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
    switch (reason)
    {
      case DLL_PROCESS_ATTACH:
        break;

      case DLL_PROCESS_DETACH:
        break;

      case DLL_THREAD_ATTACH:
        break;

      case DLL_THREAD_DETACH:
        break;
    }

    /* Returns TRUE on success, FALSE on failure */
    return TRUE;
}

using namespace std;
extern "C"__declspec(dllexport) int main ()
{
       char buffer [100];
       int a;
       int b;
       cout << "Enter a number: ";
       cin.getline (buffer,100);
       a= atof (buffer);
       cout << "Enter another number: ";
       cin.getline (buffer,100);
       b= atoi (buffer);
       cout << "Sum of both numbers: " << a+b;
       cout << " \n";
       system("pause");
       return 0;
}

then i get no window, when i use

DllCall ("CalcQ.dll", "int", "Main")

i dont even get the console to pop up for a milisecond, just the tray icon for autoit really fast and then it dissapears.. any ideas why? :">

thanks! o:)

EDIT: fixed some coding.. :lmao:

Edited by layer
FootbaG
Posted

doh, what ever, is what i mean is calling that Dll will create a Console Window, now will you help me?!?!?! :lmao:

FootbaG
Posted (edited)

argh... it works fine as an EXE... but i still can't get it to work inside a DllCall! o:) (i know your probably saying why not just stick with the .EXE created and forget about the DllCall, well it's because i want to see if i can have a Console in autoit) :) i attached the .EXE of the program below, and source.. :lmao:

EDIT: grr, why can't i post a .CPP file.. ill do a zip, hang on :) there we go, its in a ZIP now.. :)

Edited by layer
FootbaG
Posted

Its probably pretty easy to create a console window in AutoIt but you're barking up the wrong tree with your code. Go to MSDN and have a look at AllocConsole and it's related functions.

Posted (edited)

hmmm... i see where ur going

DllCall ("kernel32.dll", "int", "AllocConsole")
DllCall ("kernel32.dll", "int", "AttacchConsole", "int", "AutoIt3.exe")
While 1
Sleep (100)
WEnd

thanks a bunch Valik! o:)

EDIT: for anyone whos interested..

AllocConsole: http://msdn.microsoft.com/library/default....llocconsole.asp

AttachConsole: http://msdn.microsoft.com/library/default....tachconsole.asp

and theres a whole bunch of other Console commands there too, just look around... :lmao:

Edited by layer
FootbaG

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
×
×
  • Create New...