Pelles C forum

C language => Beginner questions => Topic started by: Jean-Pierre Leroy on June 24, 2014, 10:52:44 AM

Title: Using Pelles C with IUP toolkit
Post by: Jean-Pierre Leroy on June 24, 2014, 10:52:44 AM
Dear all,

I would like to use Pelles C with the IUP toolkit (http://www.tecgraf.puc-rio.br/iup/)

Is there any tutorial explaining how to set up Pelles C in order to use it with the IUP tookit.

By the way do you think it could be possible in a future version of Pelles C to add in the list of "Template projects" or "Empty projects" new options for IUP tookit like :

"32 bits IUP project"
"64 bits IUP project"

Thanks for your help.

Regards,
Jean-Pierre Leroy
Title: Re: Using Pelles C with IUP toolkit
Post by: jcfuller on June 24, 2014, 11:49:09 AM
Why would you want to use a Gui toolkit, primarily used for cross platform development, with a windows only compiler?

James
Title: Re: Using Pelles C with IUP toolkit
Post by: frankie on June 24, 2014, 12:04:08 PM
As general rule you can use PellesC to compile C only project with prebuild iup libraries compiled with VC++10 (see (http://)).
I don't think that a dedicated template for iup will never added, but you can do it yourself creating the wizard.
You'll find the documentation for wizards in the compiler help, and also some examples on PellesC site (http://www.smorgasbordet.com/pellesc/index.htm).
Title: Re: Using Pelles C with IUP toolkit
Post by: WRP on June 26, 2014, 02:25:42 AM
Why would you want to use a Gui toolkit, primarily used for cross platform development, with a windows only compiler?

Short answer: It is an easier way to build a Windows interface.

IUP is a GUI toolkit that on Windows uses the native widgets. You can code the interface with either LED, C, or Lua.

LED is a declarative language to specify just the layout of the GUI; the logic has to be done elsewhere in C. The advantage of LED is that it is very concise and can be modified live. It is a bit like coding a web page.

Lua with IUP is rather like Tcl/Tk, except that Lua is a nicer language than Tcl and IUP has much nicer looking (native) widgets, including some very powerful ones for data manipulation and visualization.

Developing with the C API, while more involved than with Lua, is much cleaner than using the Win32 API directly. For comparison, I find C projects with IUP are a bit simpler than with GTK+.

Of course, since IUP is cross-platform, there is the added benefit that you can move your project to Unix/Linux mostly unchanged.

As I indicated above, I think Lua/IUP is a significant improvement over Tcl/Tk, but it has a major drawback. There is currently a terrible lack of tutorial material.
Title: Re: Using Pelles C with IUP toolkit
Post by: WRP on June 26, 2014, 03:18:02 AM
Is there any tutorial explaining how to set up Pelles C in order to use it with the IUP tookit.

Building IUP projects with Pelles C works well, but I found a few gotchas in setting up. There is no need for a specialized IUP template in the Wizard.

Here is to get you started quickly.

Step 1: Download and install Pelles C (32 or 64-bit version).

Step 2: Download and unpack the most recent 32 or 64-bit static and dynamic IUP library packages for Windows. Be sure to choose the right ones for the version of Microsoft C Runtime that you have. Also get the Tools, Docs, and Examples packages.

Step 3: Read the Pelles C manual, at least the part about using the IDE.

Step 4: Get the appropriate version of libcmt.lib and msvcrt.lib from Microsoft. I got them out of Visual Studio Express. Put them in Pelles C\Libs.

OR

Replace the iupstub.lib with frankie's Pelles C native version (http://forum.pellesc.de/index.php?topic=6269.msg23204#msg23204).

Step 5: In the IDE, create a new project with the Wizard, choosing "Win32 Program (EXE)". Add to the project the IUP resource file, found in the static libs \etc directory. Add to the project one of the C examples from the Examples package. To build with dynamic linking, in project options add iup.lib and iupstub.lib to the linker options and add the IUP dynamic libs package and include directory to the folder path. Update dependencies and build.

Static linking is more involved. We had some discussion here (http://forum.pellesc.de/index.php?topic=6269.msg23211#msg23211).

Some of the example programs require DLLs from outside the IUP project. You can find them in the Tools package.
Title: Re: Using Pelles C with IUP toolkit
Post by: jcfuller on June 26, 2014, 12:59:22 PM

Quote
Short answer: It is an easier way to build a Windows interface.
Easier than using a WYSIWYG Dialog editor and direct api? I don't see it.

Quote
Of course, since IUP is cross-platform, there is the added benefit that you can move your project to Unix/Linux mostly unchanged.

I agree but why use Pelles in this situation? I am not a seasoned c coder but I would use gcc for cross platform coding with IUP.
I would assume fewer code gocha's (?)

James
Title: Re: Using Pelles C with IUP toolkit
Post by: Bitbeisser on June 26, 2014, 05:53:10 PM

Quote
Short answer: It is an easier way to build a Windows interface.
Easier than using a WYSIWYG Dialog editor and direct api? I don't see it.

Quote
Of course, since IUP is cross-platform, there is the added benefit that you can move your project to Unix/Linux mostly unchanged.

I agree but why use Pelles in this situation? I am not a seasoned c coder but I would use gcc for cross platform coding with IUP.
I would assume fewer code gocha's (?)

James
Sorry but GCC is a behemoth, and I would not use it for any cross-platform work.

The point is that you could use Pelle's C to produce a Windows version of a cross-platform application, regardless of what compiler someone else might be using for the same application on a different OS...

Ralf
Title: Re: Using Pelles C with IUP toolkit
Post by: jj2007 on June 27, 2014, 12:52:04 PM
IUP is a GUI toolkit that on Windows uses the native widgets.

Can you zip the executable of a Hello World example, with a few "widgets" (I assume you mean controls), just to see how it looks like?
Title: Re: Using Pelles C with IUP toolkit
Post by: jcfuller on June 27, 2014, 04:59:51 PM
IUP is a GUI toolkit that on Windows uses the native widgets.

Can you zip the executable of a Hello World example, with a few "widgets" (I assume you mean controls), just to see how it looks like?

It uses native controls so the example will look just like an Win api version.

James
Title: Re: Using Pelles C with IUP toolkit
Post by: frankie on June 27, 2014, 05:38:18 PM
The IUP real advantage is that it creates a sort of GUI abstraction language that when application is built links to the native GUI subsystem for the machine where it runs.
In plain words you define the graphical widgets you want and when running it will use windows controls on MS, GTK on Linux and so on...
I don't think that it is a real benefit if your program have to run only on MS platforms, but it is very efficient when it have to run on different platforms.
I forget to add that the libraries are compiled with __cdecl calling conventions, on systems where this make any sense, and user program starts with standard 'main' function to allow the compilation of GUI applications with any kind of standard C compiler without any graphic libraries apart from IUP.

I'm trying to natively compile IUP on PellesC, and I have compiled parts of it, but unfortunately many modules are in C++ ...
Title: Re: Using Pelles C with IUP toolkit
Post by: Bitbeisser on June 27, 2014, 07:14:58 PM
I'm trying to natively compile IUP on PellesC, and I have compiled parts of it, but unfortunately many modules are in C++ ...
I have downloaded but not played with the code myself, but according to the site, it should be plain C... ?!?!?!

Ralf
Title: Re: Using Pelles C with IUP toolkit
Post by: WRP on June 27, 2014, 08:25:27 PM
... but unfortunately many modules are in C++ ...

IUP was developed all in ANSI C, but recently they have incorporated some outside projects in C++. So far, there is MathGL (http://mathgl.sourceforge.net/doc_en/Main.html), PPlot (http://pplot.sourceforge.net/), Scintilla (http://www.scintilla.org/), TUIO (http://www.tuio.org/), and support for Haiku (http://en.wikipedia.org/wiki/Haiku_(operating_system)).

I noticed that the OLE and web browser controls are C++. I wonder if that was really necessary.
Title: Re: Using Pelles C with IUP toolkit
Post by: jj2007 on June 27, 2014, 08:51:21 PM
It uses native controls so the example will look just like an Win api version.

Can we see an example? There must be somebody around who has a simple GUI example... can't be so difficult to zip it and post it here.
Title: Re: Using Pelles C with IUP toolkit
Post by: jcfuller on June 27, 2014, 09:09:00 PM
This is a demo I created with my bc9Basic -> c/c++ translator and compiled with VS2013 Express.

James

Edit:
  This is the code produced by bc9Basic:
Code: [Select]

// *********************************************************************
//  Created with bc9Basic - BASIC To C/C++ Translator (V) 9.1.8.8 (2014/06/17)
//       The bc9Basic translator (bc9.exe) was compiled with
//                           g++ (tdm64-2) 4.8.1
// ----------------------------------------------------------------------
//                 BCX (c) 1999 - 2009 by Kevin Diggins
// *********************************************************************
//              Translated for compiling with a C Compiler
//                           On MS Windows
// *********************************************************************
#include <windows.h>    // Win32 Header File
#include <windowsx.h>   // Win32 Header File
#include <commctrl.h>   // Win32 Header File
#include <commdlg.h>    // Win32 Header File
#include <mmsystem.h>   // Win32 Header File
#include <shellapi.h>   // Win32 Header File
#include <shlobj.h>     // Win32 Header File
#include <richedit.h>   // Win32 Header File
#include <objbase.h>    // Win32 Header File
#include <ocidl.h>      // Win32 Header File
#include <winuser.h>    // Win32 Header File
#include <olectl.h>     // Win32 Header File
#include <oaidl.h>      // Win32 Header File
#include <ole2.h>       // Win32 Header File
#include <oleauto.h>    // Win32 Header File
#include <winsock.h>    // Win32 Header File
#include <process.h>    // dos
#include <direct.h>     // dos
#include <io.h>         // dos
#include <conio.h>      // dos
#include <wchar.h>      // dos/linux
#include <ctype.h>      // dos/linux
#include <fcntl.h>      // dos/linux
#include <math.h>       // dos/linux
#include <stdio.h>      // dos/linux
#include <string.h>     // dos/linux
#include <stddef.h>     // dos/linux
#include <stdlib.h>     // dos/linux
#include <setjmp.h>     // dos/linux
#include <time.h>       // dos/linux
#include <stdarg.h>     // dos/linux
#include <sys/types.h>
#include <sys/stat.h>


// ***************************************************
// Compiler Defines
// ***************************************************

// C++
#if defined( __cplusplus )
#define overloaded
#define C_EXPORT EXTERN_C __declspec(dllexport)
#define C_IMPORT EXTERN_C __declspec(dllimport)
#else
#define C_EXPORT __declspec(dllexport)
#define C_IMPORT __declspec(dllimport)
#endif


// Microsoft VC++
#ifndef DECLSPEC_UUID
#if (_MSC_VER >= 1100) && defined ( __cplusplus )
#define DECLSPEC_UUID(x)    __declspec(uuid(x))
#else
#define DECLSPEC_UUID(x)
#endif
#endif

// $HEADER BEGIN
#pragma comment(lib,"iup.lib")
#pragma comment(lib,"iupcontrols.lib")
#pragma comment(lib,"iupcd.lib")
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
// $HEADER END

#include "iup.h"

// *************************************************
// Instruct Linker to Search Object/Import Libraries
// *************************************************
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"comctl32.lib")
#pragma comment(lib,"advapi32.lib")
#pragma comment(lib,"winspool.lib")
#pragma comment(lib,"shell32.lib")
#pragma comment(lib,"ole32.lib")
#pragma comment(lib,"oleaut32.lib")
#pragma comment(lib,"uuid.lib")
#pragma comment(lib,"odbc32.lib")
#pragma comment(lib,"odbccp32.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"comdlg32.lib")
#pragma comment(lib,"imagehlp.lib")
#pragma comment(lib,"version.lib")
// *************************************************
// End of Object/Import Libraries To Search
// *************************************************

// *************************************************
//        User's GLOBAL ENUM blocks
// *************************************************

// *************************************************
//            System Defined Constants
// *************************************************

typedef const char* ccptr;
#define CCPTR const char*
#define cfree free
#define WAITKEY system("pause")
#define cSizeOfDefaultString 2048

// *************************************************
//            User Defined Constants
// *************************************************


// *************************************************
//               Standard Prototypes
// *************************************************

char*   BCX_TmpStr(size_t, size_t    , int    );
char*   join (int, ... );
char*   enc (const char*, int    , int    );
// *************************************************
//          User Defined Types And Unions
// *************************************************


// *************************************************
//                System Variables
// *************************************************


// *************************************************
//            User Global Variables
// *************************************************

static PCHAR   *g_argv;
static int     g_argc;


// *************************************************
//               User Prototypes
// *************************************************

int     main (int, PCHAR*);
long    quit_cb (void);
void    AddChild (Ihandle* , Ihandle*);
Ihandle* Create (char *, char *, Ihandle*);

// *************************************************
//            User Global Initialized Arrays
// *************************************************



// *************************************************
//                 Runtime Functions
// *************************************************

#ifndef BCXTmpStrSize
#define BCXTmpStrSize  2048
#endif
char *BCX_TmpStr (size_t Bites, size_t  iPad, int iAlloc)
{
    static int   StrCnt;
    static char *StrFunc[BCXTmpStrSize];
    StrCnt = (StrCnt + 1) & (BCXTmpStrSize - 1);
    if(StrFunc[StrCnt]) {
        free (StrFunc[StrCnt]);
        StrFunc[StrCnt] = NULL;
    }
#if defined BCX_MAX_VAR_SIZE
    if(Bites * sizeof(char) > BCX_MAX_VAR_SIZE)
    {
        printf("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\n", (int)(Bites * sizeof(char)), BCX_MAX_VAR_SIZE);
        abort();
    }
#endif
    if(iAlloc) StrFunc[StrCnt] = (char*)calloc(Bites + iPad + 1, sizeof(char));
    return StrFunc[StrCnt];
}


char *enc (const char *A, int L, int R)
{
    register int tmplen = strlen(A);
    register char *BCX_RetStr = BCX_TmpStr(tmplen + 3, 1, 1);
    memcpy(BCX_RetStr + 1, A, tmplen);
    *BCX_RetStr = (char)((L == 0) ? 34 : L);
    BCX_RetStr[++tmplen] = (char)((R == 0) ? *BCX_RetStr : R);
    BCX_RetStr[++tmplen] = 0;
    return BCX_RetStr;
}


char * join(int n, ...)
{
    register int i = n, tmplen = 0;
    register char *s_;
    register char *strtmp;
    va_list marker;
    va_start(marker, n); // Initialize variable arguments
    while(i-- > 0)
    {
        s_ = va_arg(marker, char *);
        if(s_) tmplen += strlen(s_);
    }
    strtmp = BCX_TmpStr(tmplen, 1, 1);
    va_end(marker); // Reset variable arguments
    i = n;
    va_start(marker, n); // Initialize variable arguments
    while(i-- > 0)
    {
        s_ = va_arg(marker, char *);
        if(s_) strcat(strtmp, s_);
    }
    va_end(marker); // Reset variable arguments
    return strtmp;
}



// ************************************
//       User Subs and Functions
// ************************************

int main (int argc, PCHAR* argv)
{
    g_argc = argc;
    g_argv = argv;
    Ihandle*  win;
    Ihandle*  vbox;
    Ihandle*  topBox;
    Ihandle*  serverFrame;
    Ihandle*  serverBox;
    Ihandle*  serverCombo;
    Ihandle*  btnFetch;
    Ihandle*  controlFrame;
    Ihandle*  controlBox;
    Ihandle*  btnAbout;
    Ihandle*  btnClear;
    Ihandle*  btnExit;
    Ihandle*  dictFrame;
    Ihandle*  serverList;
    Ihandle*  transFrame;
    Ihandle*  text;
    Ihandle*  bottomBox;
    Ihandle*  label;
    Ihandle*  entry;
    Ihandle*  btnSearch;
    Ihandle*  chkAll;
    Ihandle*  chkUTF;
    IupOpen(0, 0);
    win = Create("dialog", "TITLE=Thesaurus, SIZE=500x300", NULL);
    vbox = Create("vbox", "MARGIN=10x10", NULL);
    topBox = Create("hbox", " GAP=10", vbox);
    serverFrame = Create("frame", "TITLE=Servers, EXPAND=YES", topBox);
    serverBox = Create("hbox", "GAP=5", serverFrame);
    serverCombo = Create("list", "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1", serverBox);
    btnFetch = Create("button", "TITLE=Fetch, SIZE = 50x", serverBox);
    controlFrame = Create("frame", "TITLE=Controls", topBox);
    controlBox = Create("hbox", "Margin=6x6, GAP=5", controlFrame);
    btnAbout = Create("button", "TITLE=About, SIZE = 50x", controlBox);
    btnClear = Create("button", "TITLE=Clear, SIZE = 50x", controlBox);
    btnExit = Create("button", "TITLE=Exit, SIZE = 50x", controlBox);
    IupSetCallback(btnExit, "ACTION", (Icallback)quit_cb);
    dictFrame = Create("frame", "TITLE=Dictionaries", vbox);
    serverList = Create("list", "EXPAND=YES, VISIBLELINES=1", dictFrame);
    transFrame = Create("frame", "TITLE=Translation", vbox);
    text = Create("text", "MULTILINE=YES, EXPAND=YES", transFrame);
    bottomBox = Create("hbox", "GAP=10", vbox);
    label = Create("label", join( 3, "TITLE=", enc("Enter Word to Search For:", 34, 34), ", SIZE=x12"), bottomBox);
    entry = Create("text", " EXPAND=HORIZONTAL", bottomBox);
    btnSearch = Create("button", "TITLE=Search, SIZE=50x", bottomBox);
    chkAll = Create("toggle", "TITLE=ALL, VALUE=ON,SIZE=x12", bottomBox);
    chkUTF = Create("toggle", "TITLE=UTF-8, SIZE=x12", bottomBox);
    AddChild(win, vbox);
    IupShow(win);
    IupSetFocus(btnFetch);
    IupMainLoop();
    IupClose();
}


long quit_cb (void)
{
    return IUP_CLOSE;
}


void AddChild (Ihandle* parent, Ihandle* child)
{
    IupAppend(parent, child);
    IupRefresh(parent);
}


Ihandle* Create (char *Value, char *Attr, Ihandle* parent)
{
    Ihandle*  iHwnd = {0};
    iHwnd = IupCreate( Value);;
    if(iHwnd )
    {
        if(strlen(Attr))
        {
            IupSetAttributes(iHwnd, Attr);
        }
        if(parent )
        {
            AddChild(parent, iHwnd);
        }
        return iHwnd;
    }
    return NULL;
}


Title: Re: Using Pelles C with IUP toolkit
Post by: WRP on June 27, 2014, 11:38:41 PM
Can we see an example?

There are even some complete programs you can download.
http://www.tecgraf.puc-rio.br/iup/en/screenshots.html
http://www.tecgraf.puc-rio.br/iup/en/gallery_dlg.html
http://www.tecgraf.puc-rio.br/iup/en/gallery.html
Title: Re: Using Pelles C with IUP toolkit
Post by: jj2007 on June 28, 2014, 02:17:51 AM
This is a demo I created with my bc9Basic -> c/c++ translator and compiled with VS2013 Express.

James,
IUP_01.exe "is not a valid Win32 application" on WinXP... sorry.

@WRP: No complete programs there, just screenshots. What I meant was really a hello world proggie, see attached samples.

EDIT: After some searching, I found something here (http://www.tecgraf.puc-rio.br/iup/examples/bin/Win32/) - a bit bloated at 78k for what it does, in particular since you need >2MB of dlls to make it work. The look is OK, though. It crashes WJR's PEview (http://wjradburn.com/software/) for some reason.
Title: Re: Using Pelles C with IUP toolkit
Post by: jcfuller on June 28, 2014, 01:11:11 PM
This is a demo I created with my bc9Basic -> c/c++ translator and compiled with VS2013 Express.
James,
IUP_01.exe "is not a valid Win32 application" on WinXP... sorry.

That's right.
Microsoft dropped default XP support with the release of Visual Studio 2012 many years ago.
I do have a setup for compiling with VS2013 for XP but I do not have an XP machine anymore so I can't test it.
See if this works.

James

Title: Re: Using Pelles C with IUP toolkit
Post by: jj2007 on June 28, 2014, 02:39:16 PM
Microsoft dropped default XP support with the release of Visual Studio 2012 many years ago.
;-)

Quote
I do have a setup for compiling with VS2013 for XP but I do not have an XP machine anymore so I can't test it.
See if this works.
Same problem.
Title: Re: Using Pelles C with IUP toolkit
Post by: jcfuller on June 28, 2014, 04:07:58 PM
Ok one more time :)
BCX has long been a supporter of PellesC. Although my focus with the bc9Basic fork is primarily c++ it creates "c" source just fine.
Attached is bc9Basic source, c source,  exe, and my batch file for compiling with PellesC.
This one was compiled with PellesC 8 RC4 and using a dll that IUP no longer supplies ( I could not find it) That I believe has only MSVCRT dependencies.

James

Title: Re: Using Pelles C with IUP toolkit
Post by: jj2007 on June 28, 2014, 06:43:34 PM
Thanks, James - it works on XP SP3 ;)
Title: Re: Using Pelles C with IUP toolkit
Post by: frankie on June 29, 2014, 12:57:48 PM
I'm trying to natively compile IUP on PellesC, and I have compiled parts of it, but unfortunately many modules are in C++ ...
I have downloaded but not played with the code myself, but according to the site, it should be plain C... ?!?!?!

Ralf

The API are in plain C by design ...
But the library itself has a lot of C++  :-\, The im library is in C++  >:(
There should be also wrappers to use the API's in C++  ;D ;D ;D ;D ;D ridicolus...?!?!?!?

Anyway there should be no problem in using precompiled DLL's, but you can't use directly the precompiled libs, unless compile with no default libraries and link against msvcrt including the ms crt static library specified as first library in the linker list.
Title: Re: Using Pelles C with IUP toolkit
Post by: sven90 on August 04, 2014, 02:38:27 PM
Hello.
 It is there a Linux tutorial how to configure pells in ubuntu? I just find your website in google and trying to get some tutorials but its difficult to find
Title: Re: Using Pelles C with IUP toolkit
Post by: frankie on August 04, 2014, 07:02:02 PM
Hello.
 It is there a Linux tutorial how to configure pells in ubuntu? I just find your website in google and trying to get some tutorials but its difficult to find
PellesC is not available for linux, but can run under wine.
PellesC is just a 'C' compiler, not 'C++'.
Title: Re: Using Pelles C with IUP toolkit
Post by: coder_direct on September 04, 2015, 11:45:00 PM
Is there anybody that can provide a proper instruction how to instal iup on Pelles C v8

Thanks
John