NO

Author Topic: #if defined & <windows.h> problem  (Read 9102 times)

vedro-compota

  • Guest
#if defined & <windows.h> problem
« on: October 15, 2011, 12:48:12 PM »
  Hi there)
 i'm gald to join this forum )
I have some problem with choosing  type of project . I need to write simple code which can be compiled in both of linux and windows os ......something like this =
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#if defined(_WIN32) || defined (_WIN64)
#include <windows.h>
#define WINDOWSS 1
#endif



 #if defined WINDOWSS
int WINAPI WinMain2(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss)
{
char* mtext = "  it's WinMain() code \n" ;
  printf("\n%s",mtext );
return TRUE;
}
#else
int main()
{
char* mtext = " it's main() code \n" ;
  printf("\n%s",mtext );
        return TRUE;
}
#endif
so i'm going to use console interface  - but compiler (Pelles C as you guessed it ))) don't allow this code (in "win32 console project") - it  wants main() instead of WinMain . Is there any way to use WinMain as entry point for windows in win32 console project?
answer please )

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: #if defined & <windows.h> problem
« Reply #1 on: October 15, 2011, 01:20:39 PM »
Windows console programs use the same entry point as Linux console programs.

Code: [Select]
int main(int argc, char *argv[])
// or
int main(void)
---
Stefan

Proud member of the UltraDefrag Development Team

vedro-compota

  • Guest
Re: #if defined & <windows.h> problem
« Reply #2 on: October 15, 2011, 02:22:18 PM »
hm...but why did i get nothing (console isn't showed)
during compiling such code as win32 program (not as win32 console program)=
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#if defined(_WIN32) || defined (_WIN64)
#include <windows.h>
#define WINDOWSS 1
#endif
 #if defined WINDOWSS
int WINAPI WinMain2(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss)
{
char* mtext = "  it's WinMain() code \n" ;
  printf("\n%s",mtext );
return TRUE;
}
#else
int main()
{
char* mtext = " it's main() code \n" ;
  printf("\n%s",mtext );
        return TRUE;
}
#endif
« Last Edit: October 15, 2011, 02:29:48 PM by vedro-compota »

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: #if defined & <windows.h> problem
« Reply #3 on: October 15, 2011, 02:35:54 PM »
Because you did not open a window.

To see the differences use the wizards, which create some bare-bones code for you to look at, compile and run.
---
Stefan

Proud member of the UltraDefrag Development Team

vedro-compota

  • Guest
Re: #if defined & <windows.h> problem
« Reply #4 on: October 15, 2011, 02:38:23 PM »
thank you , Stefan )

Offline DMac

  • Member
  • *
  • Posts: 272
Re: #if defined & <windows.h> problem
« Reply #5 on: October 17, 2011, 07:00:22 PM »
If you want to do console and offer menu choices perhaps this project might help: http://forum.pellesc.de/index.php?topic=3841.0.  It should be easy to adapt to Linux as well as Windows.
« Last Edit: October 18, 2011, 04:13:53 PM by DMac »
No one cares how much you know,
until they know how much you care.

vedro-compota

  • Guest
Re: #if defined & <windows.h> problem
« Reply #6 on: October 17, 2011, 07:28:42 PM »
thank you , DMac )

vedro-compota

  • Guest
Re: #if defined & <windows.h> problem
« Reply #7 on: October 17, 2011, 07:31:44 PM »
  DMacwhat's the meaning of your signature?   tell me please)
« Last Edit: October 17, 2011, 07:33:34 PM by vedro-compota »

CommonTater

  • Guest
Re: #if defined & <windows.h> problem
« Reply #8 on: October 18, 2011, 12:25:28 AM »
hm...but why did i get nothing (console isn't showed)
during compiling such code as win32 program (not as win32 console program)=

In all due respect, it strikes me that you are trying to do something simply isn't going to work. 

You are not going to write a program in Pelles C that will run on Linux.  The executable files are different enough that it ain't gonna happen and you ain't gonna force it to happen.  Windows and Linux cannot exchange executables... and yes that is by design.

Now you do have a few options... none of which involve your screwball #defines and #ifdefs...

1) Write console code on windows, sticking to the C-99 standard function calls.  You can then take your source code over to a Linux machine and recompile it there.  (Look in the Pelles C help file, all non-standard functions are clearly identified.  Don't use any Windows API calls.)

2) You can install a Windows Emulator --like Wine-- on the Linux machine.  This will allow you to run *some* (meaning "not all") windows programs on the linux machine.

No matter what you do Pelles C is a compiler for the Windows Platform *only*.

As we discussed in your other thread... you are not going to write a program that runs in both Windows Console and Windows Gui modes... They are different for a whole lot of reasons, not the least of which is that printf(), scanf() and similar function calls write to console windows and the GUI mode uses graphic controls for input and output... these are so different as to be totally incompatible with each other. 

For the problem of nothing showing up... Windows GUI programs do not open a console window.  If you don't make your own windows you see nothing.

My best advice to you at this point is to get a good book on C Programming... start on page 1, read the text, type up and try the examples... play with the code, break it, fix it, change it, until you know what does and does not work... Now turn to page 2 ... repeat until you hit the end of the book.  At least then you wil have some decent understanding of how C programming works.

It is a terrible mistake to think you can just mess about as you are... the end result is usually nothing better than a whole lot of wasted time and effort.





« Last Edit: October 18, 2011, 12:34:31 AM by CommonTater »

Offline DMac

  • Member
  • *
  • Posts: 272
Meaning of Signature
« Reply #9 on: October 18, 2011, 04:57:14 PM »
  DMac what's the meaning of your signature?   tell me please)
It is attributed to Theodore Roosevelt, the 26th President of the United States, however, it was commonly published throughout the Bell telephone system as a motto for customer service.
Years ago I worked in a telecommunications related industry with a (now retired) transmission engineer who had come up through the ranks of that organization, he had some brass plates with that slogan that he acquired somewhere.  He's a great guy who cares.  He helped me get a job after a layoff once.
The principle is this, we live and work with a lot of knowledgeable people, people with experience or understanding that we ourselves do not have.  We on the other hand have knowledge and experience that someone else might not have.  It is easier to receive instruction or correction from a mentor who cares than it is from a know-it-all who doesn't.  Likewise if you are in a position to teach, correct, or give advice; it is much more effectively received if you have laid a foundation of genuine care for the well being of those over whom you have been given charge.
« Last Edit: October 18, 2011, 06:49:21 PM by DMac »
No one cares how much you know,
until they know how much you care.

CommonTater

  • Guest
Re: #if defined & <windows.h> problem
« Reply #10 on: October 18, 2011, 08:27:40 PM »
@dmac ... good slogan... I like that.

vedro-compota

  • Guest
Re: #if defined & <windows.h> problem
« Reply #11 on: October 19, 2011, 06:26:49 PM »
yes/ it's really good)

vedro-compota

  • Guest
Re: #if defined & <windows.h> problem
« Reply #12 on: October 19, 2011, 06:54:29 PM »
DMac , not all moments is clear in your masterpiece ))
« Last Edit: October 19, 2011, 06:56:57 PM by vedro-compota »