Find the answer to your Linux question:
Results 1 to 4 of 4
I have a VC++ source code which was implemented as plain C and I want to port in linux. Though Wine and WineLib worked, my program was pretty much dependent ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2003
    Location
    Philippines
    Posts
    2

    Porting VC++ codes to Linux C


    I have a VC++ source code which was implemented as plain C and I want to port in linux. Though Wine and WineLib worked, my program was pretty much dependent on this programs (either my program run on top of Wine or WineLib made my program a library and linked it to wine). I wanted my program to be a stand-alone binary. My program does not use any GUI but has lots of windows API with it. What's the best way to do this asside from re-coding the entire program in linux? What points do I have to change especially on the Windows API side. Thanks a lot

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    There are two options:
    1. Link WineLib statically. Usually, I guess it uses a shared object (similar to windows DLLs). If you link it with the static library, it becomes part of your program. You just need it at compile time.
    2. Replace every API call with the UNIX counterpart. Most windows API calls have an almost exact counterpart in UNIX.

  3. #3
    Just Joined!
    Join Date
    Jan 2003
    Location
    Philippines
    Posts
    2
    I'm trying option 2 now from Dolda2000's post. (Tnx). Do i have to convert WinMain() to main()? how?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    What is the prototype for WinMain again? Isn't it int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)?
    Anyway, yes: you have to replace the WinMain function with a function named main, since that's what libc links against. If you don't use any of the arguments, just replace the declaration line with int main(int argc, char **argv).
    Just so that you know: In Windows, it's left up to the application to decode the command line (hence the lpCmdLine argument to WinMain), while in unix, the shell (or whatever the program was started from), decodes the command line, and the arguments are passed in the argv argument, with argv[0] being the program name. argc specifies the number of parameters passed to the program, including argv[0].
    Therefore, if you have any command line parsing code in your WinMain, you can remove it and just use the argv array instead.
    The other parameters (h*Instance and iCmdShow) aren't available in UNIX, so if you use them anywhere, you have to eliminate that usage anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •