My Own API

How do you make a custom API?

Page 1 of 1

9 Replies - 1253 Views - Last Post: 04 December 2008 - 05:49 PM Rate Topic: -----

#1 athlon32  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 116
  • View blog
  • Posts: 363
  • Joined: 20-August 08

My Own API

Posted 01 December 2008 - 05:16 PM

Hello Everyone,

I'm a newbie in C++ whose entering the intermediate stage.

Now, I have experience in Win32, GTK, QT, and a few other APIs or toolkits.

I'm making a program, but I want to be cross-platform and have a custom look and feel(API).
Example: Safari for Windows

Now, I want to write a GUI library so I can do this.

Does anyone have any idea where to start?

I'll give more detail if needed.

Thanks in advance. ;)

Is This A Good Question/Topic? 0
  • +

Replies To: My Own API

#2 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: My Own API

Posted 01 December 2008 - 05:44 PM

A couple of pointers :P

1. I would start out basing it off of SDL, wxWidgets, or some other GUI toolkit or making it depend on these toolkits.

2. Otherwise, try to use preprocessor directives like:
#ifdef WIN32
...
#ifdef LINUX
...
#ifdef UNIX
...


------Note these are nonstandard, but all major compilers i know of have these flags set one way or another. That's the one thing C++ is missing. Since it isn't semi-compiled like Java, the standards committee should make these kinds of things standard to help people, and make defined platform constants. And they should kill all the non-standard crap that gets so many people confused (getch, etc). But that's another debate.

I know there's a flag for GCC to output all of the defined constants, but it escapes me at the moment.

ALso, i really hate to say it (see sig) but your best bet may be to use the Java SWING API. But if you want the challenge, I'm all for you. A nice, easy-to-use crossplatform graphics toolkit might be nice. WxWidgets has a lot of functionality, but it's kind of confusing. I wish they made Allegro for Linux... All this event-based stuff gets procedural people messed up :)
Was This Post Helpful? 0
  • +
  • -

#3 athlon32  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 116
  • View blog
  • Posts: 363
  • Joined: 20-August 08

Re: My Own API

Posted 01 December 2008 - 07:57 PM

1. I'm looking into those open source toolkits. I'll probably end up modifying one for Linux to make it multiplatform

2. Ok. I think I have an idea on what that code does, but could you clarify for me?

3. I sorta know Java, but I'm better off using C++

4. Do you or someone else have a good tutorial that describes how these APIs and toolkits work? I know how to use them, but I want to understand how they actually work(example: how to create buttons, textboxes, etc.).

Like always, thanks.
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3106
  • View blog
  • Posts: 19,145
  • Joined: 14-September 07

Re: My Own API

Posted 01 December 2008 - 08:12 PM

Essentially what you are thinking of doing is making a library [API]. If in C/C++ you will probably make it a .dll and this allows other programs to access all your features and such.

Brief intro to the WinAPI

Unfortunately you're going to have to go dumpster diving in MSDN or the Java API to find specific details on which to base your project. Case in point, my above WinAPI intro just talks about coding in it, not emulating it. Most people use a product without needing to know its inner functions. Just like white/black box testing.
Was This Post Helpful? 0
  • +
  • -

#5 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: My Own API

Posted 01 December 2008 - 08:32 PM

View Postiphoneorange, on 1 Dec, 2008 - 07:57 PM, said:

1. I'm looking into those open source toolkits. I'll probably end up modifying one for Linux to make it multiplatform

Gtk+ and Qt both run on Linux, Windows and Mac OS X without modifications. Your program might require some, but the libraries are all cross-platform. To build on what polymath said about basing it on SDL, wxWidgets or the like... Both of those have native Windows, Linux, and Mac OS X ports. :)

View Postiphoneorange, on 1 Dec, 2008 - 07:57 PM, said:

2. Ok. I think I have an idea on what that code does, but could you clarify for me?

http://www.cplusplus...eprocessor.html might be a good place to start for a brief overview of preprocessor commands. The "WIN32", "LINUX", "UNIX" parts all contain the platform specific code for the parts of your program that require it. You would set it up so that your configure script (assuming you use one) would change a line that looks like #define WIN32 to #define LINUX. Then the compiler knows which bits to ignore and which bits to compile.

View Postpolymath, on 1 Dec, 2008 - 05:44 PM, said:

I wish they made Allegro for Linux... All this event-based stuff gets procedural people messed up :)

Er... They do make Allegro for Linux. Says it right on the front page of the Allegro website.

This post has been edited by MorphiusFaydal: 01 December 2008 - 08:40 PM

Was This Post Helpful? 0
  • +
  • -

#6 athlon32  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 116
  • View blog
  • Posts: 363
  • Joined: 20-August 08

Re: My Own API

Posted 02 December 2008 - 05:43 PM

First of all, thank you all for your relpies.

I decided to modify one of those open source projects to my liking. But I want your opinion. Which is the best open source cross-platform toolkit, based upon the internals(e.g. source code). Also, it should be C, or C++, no Java please.

Also, this project also requires my own file extension(e.g. .html, .txt, etc.). How do you make your own? Do I name any file with that extension, but write a program to understand that specific extension?

Thank you all :D

Merry Christmas
~iPhoneOrange
Was This Post Helpful? 0
  • +
  • -

#7 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: My Own API

Posted 02 December 2008 - 09:57 PM

I personally have a preference for Gtk+, which is written in C, but has C++ bindings available (gtkmm is what it's called). Qt is written in C++, and the "stock" bindings are C++. And be sure you know what you're getting into. Neither Gtk+ or Qt are small. There's a *lot* of code to look at.

And for the second part of your question, you need to look up creating your own file format. The most I've ever done is just create a plain-text file and put a custom extension on it. It's still, technically, a txt file, but it has a custom file extension just for my own purposes.
Was This Post Helpful? 0
  • +
  • -

#8 athlon32  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 116
  • View blog
  • Posts: 363
  • Joined: 20-August 08

Re: My Own API

Posted 02 December 2008 - 10:11 PM

Thanks. Then I'll use GTK.

I need to create a file extension similar to .EXE
I'll look into that

~iPhoneOrange
Was This Post Helpful? 0
  • +
  • -

#9 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: My Own API

Posted 02 December 2008 - 11:20 PM

An executable file? AFAICT, if you need an executable, it's going to have to be a .EXE. Windows can't run anything else.
Was This Post Helpful? 0
  • +
  • -

#10 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: My Own API

Posted 04 December 2008 - 05:49 PM

The easiest way to create a file extension is to either make a text file with a custom extension or a binary file with a custom extension. The easiest way for each of these would be fstream, though i guess you could use c-style file pointers.

GTK is HUGE, i'm pretty sure even SDL is smaller...

Also, with Linux, you may want to look up custom MIME-type registration, and with windows, file associations are good to look into. Not sure about how mac does it but it's probably like any other unix.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1