- Online Community Forums » Allegro Development » C++/CLI wrapper

This thread is locked; no one can reply to it. rss feed Print
C++/CLI wrapper
Member #12,426
December 2010

Hi all,

I'm trying to create a CLI wrapper for allegro 5.2 using the latest nuget package so I can use allegro in c#. When I try to run my test console app, my app crashes on al_init(). When I say crash I mean the application just dies immediately with no exception or anything. Any Ideas?


namespace AllegroSharp
  public ref class Allegro

    bool UseImageAddon;

    bool Initialize();


#include "Allegro.h"
#include "allegro5\allegro.h"
#include "allegro5\allegro_image.h"

bool AllegroSharp::Allegro::Initialize()
  bool allegroOk = al_init(); // crashes here
  bool imageAddonOk = UseImageAddon ? al_init_image_addon() : true;

  return allegroOk && imageAddonOk;


1namespace AllegroSharpTest 2{ 3 class Program 4 { 5 static void Main(string[] args) 6 { 7 Allegro allegro = new Allegro(); 8 Display display = new Display(1200, 800); 9 10 var statusOk = allegro.Initialize(); //crashes here 11 var displayOk = display.Initialize(); 12 13 Console.WriteLine($"Allegro ok: {statusOk} Display ok: {displayOk}"); 14 15 Console.ReadKey(); 16 17 } 18 } 19}

EDIT: I'm starting to the think it has something to do with the entry point. I put the no entry point flag for my dll so i could link it. I figured allegro would provide the entry point when the user of the dll calls allegro init. I'm trying to compile it with a dllmain function in my dll but the linker can't seem to find it.

Software Engineer by day, hacker by night.

Member #7,827
October 2006

You generally never want to call al_init from a library (see its documentation), so at the very least you should try calling al_install_system instead.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Member #12,426
December 2010

I was trying that but it seemed to crash as well. I think I supplied nullptr for the second parameter. Is that correct or should I use something else?

EDIT: It worked, thanks.

Software Engineer by day, hacker by night.

Mark Oates
Member #1,146
March 2001

Note: It is typically wrong to call al_init anywhere except the final game binary. In particular, do not call it inside a shared library unless you know what you're doing. In those cases, it is better to call al_install_system either with a NULL atexit_ptr, or with a pointer to atexit provided by the user of this shared library.

New news to me! :)

Go to: