Re: Compiling under Windows using MSCV




Many thanks for all the advices. I wanted to say that I compile perflectly my GTK applications
using MinGW, but I am now triying to do the same using MS-VC++.
None worked.
I changed my target to "Win32 Console Application" and it compiles smootly bu when I try to run it it simply open a console
(i do no know why this does not surprise me...:)...) and produces an error.
If I define the WinMain function as you recommended, the compiler still produces an error at link time:
_WinMain 16 already defined.
I am doing something really stupid probably, but I could not find any clue nor any tutorial and/or documentation
on compiling GTk Applications using MS-VC++
My code is attached to this msg.
Any idea will be welcome.
Thanks
Oscar
 

 
2008/4/30, Tor Lillqvist <tml iki fi>:
>   char *argv[1];
>    argv[0] = "foo";
>   int argc = 0;
>
>   return main(argc, argv);

Or even:

#include <stdlib.h>
...
return main (__argc, __argv);

__argc and __argv are set up by the C runtime at startup based on the
command line used to start the process even for WinMain programs.

--tml
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list

/*
GPCS.H
*/

//THESE FIVE ARE COMMON
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

//#include <unistd.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkwindow.h>
#include <windows.h>

#define WIN_LEN 800
#define WIN_HEI 400 

#define NBUF  tbuf[0]
#define TBUF  tbuf[1]
#define PBUF  tbuf[2]
#define IBUF  tbuf[3]
#define CBUF  tbuf[4]

#define PCSL		24
#define EOP			-1
#define EOC			-2
#define NEXTC		9	  		//incremento de elementos por posicion
#define MAXELEM		90
#define MAXROWS		11
#define SPAC		-4
#define INVERT		20

#define NPCS		208 //Number of PCS of 3,4,5,6,7,8, and 9 elements
#define PCS_STRLEN	64	//Number of chars for each string for each PCS 

int main (int argc, char *argv[]);

int __stdcall WinMain(      
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
);
	int __stdcall WinMain(      
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
)
{
  char *argv[1];
  int argc = 0;
  argv[0] = "foo";

  return main(__argc, __argv);
}

//DATA TYPES
typedef struct {
	char Icv[12]; 
	char FormaPrima[24]; 
	char Status[12]; 
	char Nombre[12];
   	char In[24]; 
   	char Compname[12]; 
   	char ParZ[12];
	int find[PCSL]; 
	int fprima[PCSL];
	int icvmat[7];
   	int *tableptr;
	} PCS;


typedef struct {
	int mat[MAXELEM + 1][MAXROWS + 1];
   	int NroFilas;
   	int NroCols;
   	int MaxElemxPos;
} CM;


typedef struct {     //struct for string Table only
	char nam[12];
   	char itn[12];
	char fpr[24]; 
   	char icv[12]; 
	char com[12];   	
} TSPCS;

//int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);


//GLOBAL VARIABLES

//FROM MAIN
GtkWidget     *mainw;
GtkTooltips   *tooltips;
GtkAccelGroup *accel_group;
GtkWidget     *toolbar;
//FROM DISPLAY_PCS_TABLE
char **tbuf;
TSPCS *tspcs;
//MAIN PROGRAM FUNCTIONS
void CreateMainWindow (char *cmdl_filename);
gint EndProgram ();
int Initialize();
int  leer_tabla (int *tableptr, TSPCS *pointer);
//DISPLAY PCS TABLE
void clist_update(GtkWidget *list);
void delete_window (GtkWidget *widget, gpointer data);
void init_str();
void selection_made(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data );
void unselection_made(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data );
int  table_view();
//MENU FUNCTIONS
void DeSelectMenu (GtkWidget *widget, gpointer data);
GtkWidget *CreateMenuItem (GtkWidget *menu, char *szName, char *szAccel, char *szTip, GtkSignalFunc func,gpointer data);
GtkWidget *CreateMenuCheck (GtkWidget *menu, char *szName, GtkSignalFunc func,gpointer data);
void CreateToolbar (GtkWidget *vbox_main);
void Create_menu (GtkWidget *menubar);
/*
GPCS_MAIN.C
 */

#ifdef HAVE_CONFIG_H    //WE NEED THIS TO MAKE UNDER WINDOWS 
#  include <config.h>
#endif

#include "gpcs.h"
/*
 * EndProgram
 *
 * Exit from the program
 */
gint EndProgram ()
{

	free(tspcs);
	
/* --- End gtk event loop processing --- */
    gtk_main_quit ();
    /* --- Ok to close the app. --- */
    return (FALSE);
}

/*
 * main
 * 
 * --- Program begins here
 */

int main (int argc, char *argv[])
{
     

  	/* --- Initialize GTK --- */
    gtk_init (&argc, &argv);
    
    /* --- Initialize tooltips. --- */
    tooltips = gtk_tooltips_new();
    /* --- allocate memory for global data --- */
	if(Initialize()==1) {
		gtk_main_quit ();
		return (FALSE);
	}
    /* --- Create the window with menus/toolbars. --- */
    if(argc ==2) {   //see if we have any filename delivered by command line
	CreateMainWindow (argv[1]); //pass the filename to main function
    }
    else {
	CreateMainWindow (NULL); //no filename delivered by command line
    }
    gtk_main();
    return 0;
}



/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/*
 * CreateMainWindow
 *
 * Create the main window and the menu associated with it
 */
void CreateMainWindow (char *cmdl_filename)
{
    GtkWidget *menubar;
	GtkWidget *table;
	
    /* --- Create the top window and size it. --- */
    mainw = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_usize(mainw, WIN_LEN, WIN_HEI);
    gtk_window_set_title (GTK_WINDOW (mainw), "GPCS - Pablo Di Liscia / Pablo Cetta");
    gtk_container_border_width (GTK_CONTAINER (mainw),0);
    gtk_window_set_position(GTK_WINDOW(mainw),GTK_WIN_POS_CENTER);
    //the user can shrink the window, and/or enlarge it...
    gtk_window_set_policy (GTK_WINDOW (mainw), FALSE, FALSE, FALSE);
   
    /* --- Top level window should listen for the delete_event --- */
    gtk_signal_connect (GTK_OBJECT (mainw), "delete_event",GTK_SIGNAL_FUNC (EndProgram), NULL);
    
    /* --- CREATE CONTAINER(TABLE) --- */
	table = gtk_table_new (3, 1, FALSE);
	gtk_widget_ref (table);
	gtk_object_set_data_full (GTK_OBJECT (mainw), "table", table,
		                     (GtkDestroyNotify) gtk_widget_unref);

	gtk_table_set_row_spacings (GTK_TABLE (table), 2);	
	gtk_widget_show (table);
	gtk_container_add (GTK_CONTAINER (mainw), table);

	

	/////////////////////////////////

    /* --- Menu Bar --- */

    menubar = gtk_menu_bar_new ();
    Create_menu(GTK_WIDGET(menubar));
    gtk_widget_set_usize(menubar, WIN_LEN, 30);
	gtk_table_attach (GTK_TABLE (table), menubar, 0, 1, 0, 1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);
	gtk_widget_show (menubar);

	//////////////////////////////////
	
	/*SHOW MAIN WINDOW*/
	gtk_widget_show (mainw);
   	
	/*

	 if(cmdl_filename) { //DO WE HAVE ANY ATS FILE NAME REQUESTED BY COMMAND LINE...???
		atsin(cmdl_filename);
     }
	*/
    
return;
}
///////////////////////////////////////////////////////////
int Initialize()
{
int *tableptr;
PCS pcs;

tableptr=NULL;
tspcs=NULL;

pcs.tableptr = tableptr;


	if ((tableptr = (int *) g_malloc(4160 * sizeof(int))) == NULL){
	       g_print("\n> Not enough Memory ");
	       return(1);
          }
	
	if ((tspcs = (TSPCS *) g_malloc(NPCS * sizeof(TSPCS))) == NULL){
	       g_print("\n> Not enough Memory ");
	       return(1);
          }	
	
	if(leer_tabla (tableptr, tspcs)){
		g_print("\n> GPCS: ERROR! Data Files not found ");
		return(1);
		}
	
			
return(0);
}
// -------------------------------------------------------------------
//	Read and allocate PCS Table
// -------------------------------------------------------------------

int leer_tabla(int *tableptr, TSPCS* pointer)
{
int i, x;
FILE *fp;
char car;
short valor;

///////////////////////////////////////
if((fp = fopen("PCS_1.dat","rb")) != NULL){
		for(i = 1; i <= 4160; i++){
			fread(&valor, 2, 1, fp);
			*tableptr++ = valor;
			}
		fclose(fp);
		}
	else    {
		free(tableptr);
      return 1;
		}
///////////////////////////////////////  
if((fp = fopen("PCS_1_STRINGS.dat","rb")) != NULL){
	
for(x = 0; x < NPCS; x++){
		
		for(i = 0; i < 12; i++){
			fread(&car, 1, 1, fp);
			if(car == ' ') break;
			pointer[x].nam[i]=car;
		}
					
		for(i = 0; i < 12; i++){
			fread(&car, 1, 1, fp);
			if(car == ' ') break; 
			pointer[x].itn[i]=car;						
		}
				
		for(i = 0; i < 24; i++){
			fread(&car, 1, 1, fp);
			if(car == ' ') break;
			pointer[x].fpr[i]=car;
		}
		
		for(i = 0; i < 12; i++){
			fread(&car, 1, 1, fp);
			if(car == ' ') break;
			pointer[x].icv[i]=car;
		}
		
		for(i = 0; i < 12; i++){
			fread(&car, 1, 1, fp);
			if(car == ' ' ) break;
			pointer[x].com[i]=car;
		}
		fread(&car, 1, 1, fp);
		fread(&car, 1, 1, fp);
}	
	
fclose(fp);

}
else {
	free(pointer);
    	return 1;
}

return 0;
}
// ------------------------------------------------------------------
/*
GPCS_MENUS.C
 */

#include "gpcs.h"

extern GtkWidget           *mainw;
extern GtkAccelGroup       *accel_group;
extern GtkTooltips         *tooltips;




/*
 * CreateMenuItem
 *
 * Creates an item and puts it in the menu and returns the item.

 */
GtkWidget *CreateMenuItem (GtkWidget *menu, 
                           char *szName, 
                           char *szAccel,
                           char *szTip, 
                           GtkSignalFunc func,
                           gpointer data)
{
    GtkWidget *menuitem;

    /* --- If there's a name, create the item and put a
     *     Signal handler on it.
     */
    if (szName && strlen (szName)) {
        menuitem = gtk_menu_item_new_with_label (szName);
        gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
                    GTK_SIGNAL_FUNC(func), data);
    } else {
        /* --- Create a separator --- */
        menuitem = gtk_menu_item_new ();
    }

    /* --- Add menu item to the menu and show it. --- */
    gtk_menu_append (GTK_MENU (menu), menuitem);
    gtk_widget_show (menuitem);
	/*
    if (accel_group == NULL) {
        accel_group = gtk_accel_group_new ();
        gtk_accel_group_attach (accel_group, GTK_OBJECT (mainw));
    }
	*/
    /* --- If there was an accelerator --- */
    /*
	if (szAccel && szAccel[0] == '^') {
        gtk_widget_add_accelerator (menuitem, 
                                    "activate", 
                                    accel_group,
                                    szAccel[1], 
                                    GDK_CONTROL_MASK,
                                    GTK_ACCEL_VISIBLE);
    }
	*/
    /* --- If there was a tool tip --- */
    if (szTip && strlen (szTip)) {
        gtk_tooltips_set_tip (tooltips, menuitem, szTip, NULL);
    }

    return (menuitem);
}




/*
 * CreateSubMenu
 *
 * Create a submenu off the menubar.
 *
 * menubar - obviously, the menu bar.
 * szName - Label given to the new submenu
 *
 * returns new menu widget
 */
GtkWidget *CreateSubMenu (GtkWidget *menubar, char *szName)
{
    GtkWidget *menuitem;
    GtkWidget *menu;
 
    /* --- Create menu --- */
    menuitem = gtk_menu_item_new_with_label (szName);

    /* --- Add it to the menubar --- */
    gtk_widget_show (menuitem);
    gtk_menu_append (GTK_MENU (menubar), menuitem);

    /* --- Get a menu and attach to the menuitem --- */
    menu = gtk_menu_new ();
    gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);

    return (menu);
}


/*
 * CreateBarSubMenu
 *
 * Create a submenu within an existing submenu.  (In other words, it's not
 * the menubar.)
 *
 * menu - existing submenu
 * szName - label to be given to the new submenu off of this submenu
 *
 * returns new menu widget 
 */ 
GtkWidget *CreateBarSubMenu (GtkWidget *menu, char *szName)
{
    GtkWidget *menuitem;
    GtkWidget *submenu;
 
    /* --- Create menu --- */
    menuitem = gtk_menu_item_new_with_label (szName);

    /* --- Add it to the menubar --- */
    gtk_menu_bar_append (GTK_MENU_BAR (menu), menuitem);
    gtk_widget_show (menuitem);

    /* --- Get a menu and attach to the menuitem --- */
    submenu = gtk_menu_new ();
    gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);

    /* ---  --- */
    return (submenu);
}



////////////////////////////////////////////////////////////////////////////
void Create_menu (GtkWidget *menubar)
{   
  GtkWidget *menu;
  GtkWidget *menuitem;  

  /* -----------------
     --- File menu ---
     ----------------- */
    menu =(GtkWidget *)( CreateBarSubMenu (menubar, "File"));

    menuitem = CreateMenuItem (menu, "Load PCS file", "^L", 
                     "Load File", 
                     GTK_SIGNAL_FUNC (NULL),NULL);
    
    menuitem = CreateMenuItem (menu, "Save PCS file", "^S", 
                     "Save PCS File", 
                     GTK_SIGNAL_FUNC (NULL),"NULL");

    menuitem = CreateMenuItem (menu, NULL, NULL, //SEPARADOR
   
                  NULL, NULL, NULL);
    
    menuitem = CreateMenuItem (menu, "New PCS File", "^N", 
                     "Create New PCS File from scratch", 
                     GTK_SIGNAL_FUNC (NULL),NULL);

    menuitem = CreateMenuItem (menu, "Quit", "^Q", 
                     "Go fuck you", 
                     GTK_SIGNAL_FUNC (EndProgram),NULL);

    

	/* -----------------
    --- Edit menu ---
    ----------------- */
    menu = (GtkWidget *)CreateBarSubMenu (menubar, "Edit");
    /* -----------------
    --- View menu ---
    ----------------- */
    menu = (GtkWidget *)CreateBarSubMenu (menubar, "View");
    menuitem = CreateMenuItem (menu, "View PCS Table", "^T", 
                     "Explore the PCS General table", 
                     GTK_SIGNAL_FUNC(table_view),NULL);
    
    /* -----------------
    --- Transform menu ---
    ----------------- */
    menu = (GtkWidget *)CreateBarSubMenu (menubar, "Transform");
    
    /* -----------------
    --- Window  menu ---
    ----------------- */
    menu = (GtkWidget *)CreateBarSubMenu (menubar, "Window");
    
    
    /* -----------------
    --- Help ---
    ----------------- */
    menu = (GtkWidget *)CreateBarSubMenu (menubar, "Help");
    
    menuitem = CreateMenuItem (menu, "Help", "^H", 
                     "View help file(HTML format)", 
                     GTK_SIGNAL_FUNC (NULL), NULL);
    menuitem = CreateMenuItem (menu, "About", "^A", 
                     "About this program", 
                     GTK_SIGNAL_FUNC (NULL), NULL);
    
return;

}
/*
TABLE_VIEW.C
*/

#include "gpcs.h"
/////////////////////////////////////////////////////////////////////////////
void clist_update(GtkWidget *list)
{  


int indx,  x;
 
 gtk_clist_clear ((GtkCList*)list);
 gtk_clist_freeze((GtkCList*)list); 
    
 for ( indx=0 ; indx < NPCS ; indx++ ) {
          
      
      	for(x=0; x<5; ++x)	{
   	  		*tbuf[x]=0;
   		}    

		strcat(NBUF,tspcs[indx].nam);
	   	strcat(TBUF,tspcs[indx].itn);
		strcat(PBUF,tspcs[indx].fpr);
		strcat(IBUF,tspcs[indx].icv);
		strcat(CBUF,tspcs[indx].com);
		
		
      gtk_clist_append( (GtkCList *) list,tbuf);
          
 }
    
 gtk_clist_thaw((GtkCList*)list);

return;
}
/////////////////////////////////////////////////////////////////////////////

void delete_window (GtkWidget *widget, gpointer data)
{

	gtk_widget_destroy (GTK_WIDGET (data));
  

}

/////////////////////////////////////////////////////////////////////////////
void init_str()
{
int i;

  	tbuf = (char**)g_malloc(5 * sizeof(char*));
  
  		for(i=0; i<5; ++i)	{
  
  			tbuf[i]=(char*)g_malloc(32*sizeof(char));
  			*tbuf[i]=0;
   		}
   		 
return;
}

//////////////////////////////////////////////////////////////////////////////
/* If we come here, then the user has selected a row in the list. */
void selection_made(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data )
{
  return;
}
////////////////////////////////////////////
void unselection_made(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data )
{
  return;
}
//////////////////////////////////////////////////////////////////////////////
int table_view()
{                                  
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *scrolled_window;
    GtkWidget *clist;
    gchar *titles[5] = { " NAME", " T/I"," PRIME FORM", " ICV", " COMPLEMENT" };
    int i, maxval;
   
    
    init_str();
    
    maxval=20;
    window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_usize(GTK_WIDGET(window),600,22 * maxval);
    gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, FALSE);
    gtk_window_set_title(GTK_WINDOW(window), "PCS TABLE");
    gtk_signal_connect(GTK_OBJECT(window),
		       "destroy",
		       GTK_SIGNAL_FUNC(delete_window),
		       GTK_WIDGET(window));
    
    vbox=gtk_vbox_new(FALSE, 5);
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
    gtk_container_add(GTK_CONTAINER(window), vbox);
    gtk_widget_show(vbox);
   
    
    
    /////////////////////////////////////////
     /* Create the CList*/
    clist = gtk_clist_new_with_titles( 5, titles);

    /* selection made */
    gtk_clist_set_selection_mode(GTK_CLIST(clist),GTK_SELECTION_EXTENDED);
    gtk_signal_connect(GTK_OBJECT(clist), "select_row",
		       GTK_SIGNAL_FUNC(selection_made),
		       NULL);
    gtk_signal_connect(GTK_OBJECT(clist), "unselect_row",
		       GTK_SIGNAL_FUNC(unselection_made),
		       NULL);
    gtk_clist_set_shadow_type (GTK_CLIST(clist), GTK_SHADOW_OUT);
    for(i=0; i<5; ++i) {
      gtk_clist_set_column_width (GTK_CLIST(clist), i, 100 );
    }
    
    /* Create a scrolled window to pack the CList widget into */
    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
    gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
    gtk_widget_show (scrolled_window);
    gtk_container_add(GTK_CONTAINER(scrolled_window), clist);

    /* Add the CList widget to the vertical box and show it. */
    gtk_widget_show(clist);
    clist_update(clist);
    gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
    //gtk_grab_add (window);
    gtk_widget_show(window);
    
    return(0);
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]