2

I want to combine two programs into a single executable. One is an open source program that has a rather complex project file, the other is one of mine with a much simpler structure. Because of the relative complexities of the project files I feel it would make most sense to start with the open source project and modify it to include my source files.

My intention is that my program should be in control and treat the other as a collection of utility functions.

I noticed that the open source program has a function called "main()" whereas mine has a "WinMain()". Presumably I have to tell the compiler to call my WinMain() first. How do I do that?

Is there anything else that I should be aware of in the merging process?

EDIT: Both programs are C++, not C.

EDIT: The open source program does very little io.

EDIT: The key thing I want to know is do I have to modify something in the project settings to say "this is a windows program using WinMain() as opposed to a console(?) program using main()" or will the compiler somehow work this out for itself.

UPDATE: The joint program is now up and running.

Mick
  • 8,284
  • 22
  • 81
  • 173

3 Answers3

2

If your program has WinMain(), it is presumably a Windows program, while the other is a command-line app. Depending on what the original apps actually do, this may make it difficult to merge them. E.g. if the other app uses standard input/output extensively, it is challenging to transform it into a Windows app. However, if it is simply a bunch of utility methods without side effects, you may simply add the code to your project and start using it.

You have to set up your project to generate a Windows executable, the call to your WinMain() function will then be arranged automatically by the linker.

Péter Török
  • 114,404
  • 31
  • 268
  • 329
  • The other program does very little io. I can modify the few cases where its trying to print. – Mick Oct 07 '10 at 14:04
1

If the command-line program's main function does required initialization, you'll want to rename it and call it from WinMain. If not, you can just remove it entirely. #if...#else...#endif would be good in either case.

The important thing is that there's no longer a function called main to be found by the linker.

Peter's answer addresses some other problems you might run into during the porting process that aren't directly related to main vs WinMain.

Community
  • 1
  • 1
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
0

main means you have a C or C++ program, WinMain means you have a Windows program, and the two can't be joined easily.

I would advice you start with your windows program in visual studio and add the methods/classes/functions that you need and that are in the other source files.

vulkanino
  • 9,074
  • 7
  • 44
  • 71
  • It's not more difficult than say merging two command-line programs, both of which expect to control I/O, command-line arguments, etc. – Ben Voigt Oct 07 '10 at 14:16