Welcome, Guest. Please login or register.

Author Topic: Opening libraries in c++  (Read 3451 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline DeslerTopic starter

  • Full Member
  • ***
  • Join Date: Apr 2002
  • Posts: 242
    • Show only replies by Desler
Opening libraries in c++
« on: May 02, 2003, 12:23:46 PM »
Recently I have thrown myself at the mercy of programming c++ on the amiga.
However lately I have come across this problem that I simply cannot open and use ANY library  and I cannot find any examples on the net how to do it.

Is there anyone outthere able to do this that would be so kind to give an example in c++. It would be much appreciated :-)

Im using gcc and my main purpose is to open intuition and use for opening a window.
(Uhh I hope this is not a real dumb question  :-) )
The horse is a fierce predatory animal!!!
 

Offline pjhutch

  • Sr. Member
  • ****
  • Join Date: Mar 2002
  • Posts: 452
  • Country: england
  • Gender: Male
  • Amiga user and developer
    • Show only replies by pjhutch
    • http://www.pjhutchison.org
Re: Opening libraries in c++
« Reply #1 on: May 02, 2003, 01:36:38 PM »
You need to have the Amiga Include files for exec, dos, intuition, graphics, gadtools etc to use Amiga Libraries
e.g.
#include
#include
.....
struct DosBase *DosBase;

DosBase = (struct DosBase*)OpenLibrary("dos.library, 39)
......
if (DosBase) CloseLibrary(DosBase);
....
 

Offline DeslerTopic starter

  • Full Member
  • ***
  • Join Date: Apr 2002
  • Posts: 242
    • Show only replies by Desler
Re: Opening libraries in c++
« Reply #2 on: May 02, 2003, 08:03:24 PM »
No if only it was that easy. This is my problem excactly. It works fine under c but when changing to c++ you get different error messages.
I tried this piece of code:

#include

struct intuitionBase *IntuitionBase;
IntuitionBase = (struct IntuitionBase*)OpenLibrary("intuition.library", 39);

if (IntuitionBase) CloseLibrary(IntuitionBase);

void main()
{
}


and I got

ANSI C++ forbids declaration `IntuitionBase' with no type
4: conflicting types for `int IntuitionBase'
3: previous declaration as `struct intuitionBase * IntuitionBase'
4: implicit declaration of function `int OpenLibrary(...)'
4: initialization to `int' from `IntuitionBase *' lacks a cast
6: parse error before `if'

 :-?
Is there anyone who can tell me how to make this work
The horse is a fierce predatory animal!!!
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Opening libraries in c++
« Reply #3 on: May 02, 2003, 08:54:37 PM »
You didn't include .

// example

#include
#include
#include

#include
#include

struct IntuitionBase *IntuitionBase;

int main(void)
{
  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  if (IntuitionBase)
  {
    // ...
    CloseLibrary((struct Library *) IntuitionBase);
  }
  return 0;
}
 

Offline DeslerTopic starter

  • Full Member
  • ***
  • Join Date: Apr 2002
  • Posts: 242
    • Show only replies by Desler
Re: Opening libraries in c++
« Reply #4 on: May 02, 2003, 10:42:16 PM »
Thanks guys. I really appreciate your help. But its still not there. When I run the code I got from Piru Ill get this errorcode
10: initialization to `UBYTE *' from `const char *' discards qualifiers    

I know this is really rookie problems, but I really would like to know what I do wrong  :-(
The horse is a fierce predatory animal!!!
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Opening libraries in c++
« Reply #5 on: May 02, 2003, 10:50:08 PM »
It built just fine with gcc 2.95.3. Anyhow try:

IntuitionBase = (struct IntuitionBase *) OpenLibrary((CONST_STRPTR) "intuition.library", 37);
 

Offline Shadow

  • Newbie
  • *
  • Join Date: Feb 2002
  • Posts: 7
    • Show only replies by Shadow
Re: Opening libraries in c++
« Reply #6 on: May 03, 2003, 01:15:30 AM »
From what I can see of your code I can see you spelled IntuitionBase with at small "i" and not at capital "I".

The other error you get:
Quote
10: initialization to 'UBYTE *' from 'const char *' discards qualifiers

can be fixed with something like this:
UBYTE *p = reinterpret_cast(const_cast(o));

where "o" has been defined as: const char *o somewhere.

This first removes the const qualifier from "o" and then casts it to a UBYTE pointer

And it looks like you are missing some includes.

Try this:

#include
#include
#include

#include
using namespace std;

struct IntutionBase *intuibase = NULL;

int main()
{
  intuibase = static_cast(OpenLibrary("intuition.library", 0));

  if(intuibase != NULL)
  {
    cout << "Yeah" << endl;
    CloseLibrary(static_cast(intuibase));
  }
  else
  {
    cout << "darn it" << endl;
  }
}

This should compile with g++ or StormC4 + stlport

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Opening libraries in c++
« Reply #7 on: May 03, 2003, 01:26:48 AM »
Quote
#include

Wrong. Never ever include clib directly. Always use , in this case .

Quote
struct IntutionBase *intuibase = NULL;

That's IntuitionBase, or else he can't call any intuition functions (that's usually the reason for opening the library right?)
 

Offline Shadow

  • Newbie
  • *
  • Join Date: Feb 2002
  • Posts: 7
    • Show only replies by Shadow
Re: Opening libraries in c++
« Reply #8 on: May 03, 2003, 09:31:00 AM »
Quote

Wrong. Never ever include clib directly. Always use , in this case .


Really?? I never heard that before. I am possitive I read somewhere allways to use clib/. But I could be wrong.

Quote

Quote
struct IntutionBase *intuibase = NULL;

That's IntuitionBase, or else he can't call any intuition functions (that's usually the reason for opening the library right?)


Ahh, I was actually very carefull not to make any mistakes, guess I missed that one.  sorry.