How can I use Allegro in AGS Engine Plugin Development?

Started by Raigen, Fri 10/10/2014 12:31:18

Previous topic - Next topic

Raigen

Hello Guys,

I'm working on a Engine Plugin and I want to send an Allegro BITMAP which I get using "engine->GetScreen()" via TCPIP to another program.

I want to do the following steps:

  • Convert Allegro BITMAP to HBITMAP using convert_bitmap_to_hbitmap (DDB)
  • Convert the result Bitmap to something like a base64 string and send it to the target program
  • Convert the base64 back to Bitmap or better directly to a QBitmap, QPixmap etc, because the target program uses Qt

I need help at the first point, but feel free to provide some suggestions or tipps for the others, too.
(Because I'm still learning C++)

Therefore I need to know how can I use allegro within an ags engine plugin using Visual C++ Express 2010 (on Win7 x86 OS running currently on a virtual machine)
I tried to include the allegro libraries as in many tutorials described, but when I used #include <allegro.h> it did not work and produced errors.
I think the main difference is that I dont want to use allegro to develope a game, but to get access to the mentioned function(s).

I have allegro-msvc10-4.2.3.7z used in my tries to get it work, but without success.

The code of the current method is shown below:
Code: agsp300speller.dll Plugin

const char * RequestSpellerMatrixResult(int matrixLeft, int matrixTop, int matrixWidth, int matrixHeight, int rows, int columns, int resolutionWidth, int resolutionHeight)
{
	// Get the Screen
	BITMAP* screen = engine->GetScreen();

	// creating the parameter string
	sprintf_s(spellerParams, "%d;%d;%d;%d;%d;%d;%d;%d\0", matrixLeft, matrixTop, matrixWidth, matrixHeight, rows, columns, resolutionWidth, resolutionHeight);

	// sending the parameters
	send(sock, spellerParams, strlen(spellerParams), 0);	

	// sending screen bitmap
	// TODO	
		
	// receive requested SpellerMatrixResult
	long end = recv(sock, spellerResult, 20, 0);
	spellerResult[end] = '\0';

	return engine->CreateScriptString(spellerResult);
}



----------
If someone is wondering why I send the current game screen to the target program,
this is because the target program does critical work in realtime on this screen, before continuing the game progress.

the result would be a switching between the programs active/idle states.




Thanks in advance
Raigen


Crimson Wizard

Quote from: Raigen on Fri 10/10/2014 12:31:18
I tried to include the allegro libraries as in many tutorials described, but when I used #include <allegro.h> it did not work and produced errors.
I think the main difference is that I dont want to use allegro to develope a game, but to get access to the mentioned function(s).
Library in a nutshell is just a bunch of functions; it does not really make a difference what are you using it for.
Can you tell which errors exactly have you received?

Raigen

Hi,

here are the listed errors after I've build the project

Code: ags

#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <string>

#include "allegro.h"

#define THIS_IS_THE_PLUGIN
#include "agsplugin.h"

...

The include itself does not produce any error, but when building the solution the following errors occur:

in english:
Quote
Error   1   error C2371: 'BITMAP' : redefinition; different basic types   d:\allegro\include\allegro\system.h   31
Error   2   error C2731: 'WinMain' : function cannot be overloaded   d:\allegro\include\allegro\platform\alwin.h   49
Error   3   error C2733: second C linkage of overloaded function 'WinMain' not allowed   d:\allegro\include\allegro\platform\alwin.h   49
   5   IntelliSense: cannot open source file "base.h"   d:\allegro\include\allegro\system.h   22
   7   IntelliSense: cannot open source file "config.h"   d:\allegro\include\allegro\system.h   24
   6   IntelliSense: cannot open source file "unicode.h"   d:\allegro\include\allegro\system.h   23
   4   IntelliSense: more than one instance of overloaded function "WinMain" has 'C' linkage   d:\allegro\include\allegro\platform\alwin.h   49


in german:
Quote
Fehler   1   error C2371: 'BITMAP': Neudefinition; unterschiedliche Basistypen   d:\allegro\include\allegro\system.h   31
Fehler   2   error C2731: 'WinMain': Ãœberladen der Funktion nicht möglich   d:\allegro\include\allegro\platform\alwin.h   49
Fehler   3   error C2733: Zweite C-Bindung für überladene Funktion 'WinMain' nicht zulässig   d:\allegro\include\allegro\platform\alwin.h   49
   5   IntelliSense: Die Datei "Quelle" kann nicht geöffnet werden: "base.h".   d:\allegro\include\allegro\system.h   22
   7   IntelliSense: Die Datei "Quelle" kann nicht geöffnet werden: "config.h".   d:\allegro\include\allegro\system.h   24
   6   IntelliSense: Die Datei "Quelle" kann nicht geöffnet werden: "unicode.h".   d:\allegro\include\allegro\system.h   23
   4   IntelliSense: Mindestens eine Instanz der überladenen Funktion ""WinMain"" weist eine "C"-Verknüpfung auf.   d:\allegro\include\allegro\platform\alwin.h   49

Crimson Wizard

#3
EDIT:
Try to use this instead:
Code: cpp

#define WIN32_LEAN_AND_MEAN
#include <winalleg.h>
#include <winsock2.h>
#include <string>

#define THIS_IS_THE_PLUGIN
#include "agsplugin.h"

Raigen

Thanks this helped :)

Code: ags

#define WIN32_LEAN_AND_MEAN
#include <allegro.h>
#include <winalleg.h>
#include <winsock2.h>
#include <string>

#define THIS_IS_THE_PLUGIN
#include "agsplugin.h"



But if I only took <winalleg.h>
then the errors says add <allegro.h> before <winalleg.h> :)

Code: ags
#include <allegro.h>
#include <winalleg.h>


Thank you very much
Raigen

SMF spam blocked by CleanTalk