PDA

View Full Version : Windows program in Mac




WofInside
Mar 16, 2009, 10:19 AM
(Excuse my bad english)

Hello,

First of all, let me introduce myself (this is my first post), i am a programming student, currently doing some technical works for a group with many users.

Our problem is that we have an executable file that was developed for Windows, and we needed to run it in Mac too. The issue is that we don't know too much about Mac programming (in fact we don't even have an mac either, so we must use some virtual machine on windows)

The program is mostly developed in C++, it use standard libraries and windows libraries and APIs, we need to modify this to make it work in Mac exactly in the same way.

We use the winsock libraries and the apis for get the mac adress of the computer running the program, in order to communicate the computer, using sockets, with an external server (the program is the client). We must change the use of the winsock libraries and apis in order to use the Mac sock libraries and apis, to do exactly the same thing that in windows.

Of course that we considered to offer our users to use an alternative program for execute the windows file in Mac, like Wine or the use of VMware Fusion for Mac (virtual machine thats install windows on mac), however we like to offer an most friendly solution, such as offer an mac version of the program.

Well if you can help me with this, you would have my mostly gratitude. If you need more information about the problem (or if you can't understand very well what i am saying because of my bad english) just tell me.

Regards.



lee1210
Mar 16, 2009, 10:42 AM
You have some initial hurdles to overcome. The first is that you can't, according the license, run OS X in a virtual machine (except for OS X Server, in a VM, on a Mac). This means that if you don't have a Mac, you can't run OS X without violating the license. I guess if you don't mind violating the license, this point is moot, but thought it was worth mentioning.

Do you want to write code that runs on both systems, or port the code to OS X and maintain both versions? Do you intend to abstract away the system specific code, or do you just need a mac version?

Is this a GUI application, or CLI based? Do you ever intend to run this code on UNIX or UNIX-like systems other than OS X? This might guide the direction you take (UNIX socket programming vs. dependence on Carbon/Cocoa libraries/frameworks).

Clarify your goals, and we can try to help point you in the right direction.

-Lee

WofInside
Mar 16, 2009, 10:57 AM
Hello,

Thanks for tell us about the license of OS X, will be have it on consideration in order to not have any legal issue in the future.

Now, what we need mostly is a Mac version of the code. It would be great to write a code that runs in both systems, but i don't think that this would be possible because we use the windows socket libraries and apis, that i think doenst exists in mac (correct me if i am wrong). So we just like to take the original code for Windows and modify it in order to run it in Mac too.

I don't think that the code would be used in other UNIX-Like systems other than OS X. It would be used only in Mac and Windows (each one with their version of the code).

Thanks for your fast answer, if you need more information just ask.

Regards.

Consultant
Mar 16, 2009, 11:27 AM
Get a mac, see if your code runs in CrossOver.

WofInside
Mar 16, 2009, 12:30 PM
Get a mac, see if your code runs in CrossOver.

CrossOver supports windows libraries and apis?

A little bit more of information:

The program it uses win32 api in order to use some functions to do the net hook, and for do memory selection (reserve memory for the program).

The program gets the Mac Adress of the computer to do some verifications in the server.

The program is GUI based.

So what we need is to do the hook, reserve memory, get the mac adress and stablish communication with the server using sockets in a Mac enviroment, in the same way that we do it in Windows.

I hope that you people can assist us with this problem.

regards

gnasher729
Mar 16, 2009, 05:53 PM
Now, what we need mostly is a Mac version of the code. It would be great to write a code that runs in both systems, but i don't think that this would be possible because we use the windows socket libraries and apis, that i think doenst exists in mac (correct me if i am wrong). So we just like to take the original code for Windows and modify it in order to run it in Mac too.

The winsock library is roughly compatible with standard Posix sockets as they are used in MacOS X, so you shouldn't really have any problems porting this. Do yourself a favor and invest a few hundred dollars in a MacMini instead of using a hacked together version of MacOS X in a VM. Software development and copyright infringement really doesn't go well together.

And developer.apple.com is a better source of information about Macintosh programming than www.macrumors.com.

WofInside
Mar 17, 2009, 07:55 AM
The legal issue is not a problem, we will not gonna do any kind of copyright infringement in order to get our objective, so don't worry about that and lets back to the topic.

The Posix sockets it seems like a solution for the use of winsocks libraries, however we still need to know how to get the Mac Adress, and what apis exists in Mac with the same functionality that the win32 api in windows.

Thanks to all for the help given so far.

Regards.

lee1210
Mar 17, 2009, 08:26 AM
Apple has an example of getting the primary MAC address:
http://developer.apple.com/samplecode/GetPrimaryMACAddress/listing1.html

It is pretty verbose, you may be able to simplify it a bit.

Win32 is a huge API. It covers all sorts of things. The closest equivalent in OS X is Cocoa. The main page for Cocoa is here:
http://developer.apple.com/referencelibrary/Cocoa/

Depending on your needs, you may need some "lower level" things that Cocoa doesn't provide, in which case you will have to do it the POSIX way, which is just a google away for most things, or using Carbon if it has the functions you need:
http://developer.apple.com/referencelibrary/Carbon/

-Lee

WofInside
Mar 17, 2009, 08:45 AM
Thanks a lot for the information given, it would be very useful in our investigation of how to apply the program in Mac.

We use the Win32 api for do some memory selection and reservation for the program, we hope that we can do the same thing using Cocoa.

Regards

lee1210
Mar 17, 2009, 08:59 AM
I don't know what selection/reservation means in relation to memory, but if you just need to allocate some space, you can do so with malloc/free as in any other C. If you're talking about some sort of shared memory segments, you'd probably want to use the POSIX functions to handle this (shmget, etc.).

-Lee

Cromulent
Mar 17, 2009, 09:03 AM
Thanks a lot for the information given, it would be very useful in our investigation of how to apply the program in Mac.

We use the Win32 api for do some memory selection and reservation for the program, we hope that we can do the same thing using Cocoa.

Regards

If you really need to use the Win32 API you can link against winelib. Information here (http://www.winehq.org/).

Edit : Having read the information myself it may just be easier to follow the advice that Lee provided above. While Wine does work, it also has quite a few problems.

lee1210
Mar 17, 2009, 10:55 AM
I can't argue against wine based on personal experience, or even anecdotal evidence. However, the OP stated they are a student, and if this is a project for a class, and the idea is to learn to port from one API/platform/etc. to another, it seems like using wine is "cheating"(not in the sense of academic dishonesty, but in the sense of circumventing the spirit of the project).

If the course is about software engineering, then learning to find an alternative to arduous porting may be as valuable as taking the time to port it by hand, as it's certainly a valid way to accomplish the goal. I just don't want the OP to head down the path of using wine to achieve the goal if the intent of the project/course/whatever is learning to port things. Wine might obviate that in practice in the "real world" in a lot of cases, but it doesn't eliminate the value of the experience gained by doing it manually.

Were this a pet project in one's free time, and a working end product was more important than the experience gained getting there, i would think differently. As it stands, though, this seems to be an academic endeavor, and as such "getting there" seems to be more important than "being there".

-Lee

ChrisA
Mar 17, 2009, 11:11 AM
Get a mac, see if your code runs in CrossOver.

If it does NOT simply run using CrossOver then you can re-compile the code using a crossover library. This library re-implements the Windows API on a Mac. Then after you have re-compiles you have a native Mac OS executable that will no longer need crossover. Well OK it simply has crossover linked in, but from the user's point of view it is a native Mac app.

CrossOver is a version of "Wine". Wine is free and Open Source. But are willing to pay some money you get Cross Over which has been packaged up to consumer use and comes with some support. But Wine is free. "Darwine" is Wine ported to the Mac. This is what you want. If you know enough about computers to write in C++ then you don't need the hand holding the CrossOver offers and would be best off going direct to the Wine project and pulling the latest WDarwine source off their server.

recompile with the Darwine library. All of the Windows XP API is not implemented but because you have the source to your app you can change it if some XP function you need is not there.

EDIT:
If using Wine is not "sportsman like" and you want to actually poort the software then you have a choise to make. Do you want one code base for multiple platforms or do you want to split the project in two. If the latter then you have a re-write project. You can based your new code on the old, but it becomes a re-write.

If you want a common code base then you need to fine a graphical library that runs on both pllatforms and port to that. Look at
GTK+
wxWidgets
Qt
Links to the above and much good info is on the following http://en.wikipedia.org/wiki/Cross-platform

WofInside
Mar 17, 2009, 04:07 PM
Hello,

I want to make some points clear: We are students, however this is not exactly a college project. This program would be used for people, so our priority is to get it work in the simplest and fastest way possible, instead of taking our time to do all manually (we wish to but right now we prefer the simplest way).

So if we can try to recompile the windows code in Wine or Darwine library, and that will re-implement the Windows Api, it would be great.

I don't exactly remember what kind of memory selection the program does, but i will ask the programmer who make it in order to get more information about it.

Our priority is to make the code works in Mac in the same way that in Windows, making all the necessary modifications in the code in order to do that.

Thanks all of you for your answers, you people are very helpfully.

Regards

yeroen
Mar 17, 2009, 07:34 PM
Rewrite it using Qt.

WofInside
Apr 9, 2009, 03:08 PM
Well, I made the code in Win32, it's a DLL ( Module ) that hook a socket function and modify the information in buffer, sending some other information

My questions are:
- How I can modify binary data of a program for load a module
- How I can Compile a module
- How I can make a Hook to Socket Function like send. Is trampoline method valid for Mac OS X ?

That's all, thnkx

Greetings, WofInside

Sorry for reopen the trhead, but we need an answer for this last questions.

So far we made some advances writing the code in unix. We would like to know the answers of these questions so we can complete the code for Mac too.

Thanks to all the people who answer our questions.

Regards