0

basically I am programming on a Mac, but I'm using source code from a group at school that had "windows.h" included.

I did some research and apparently there is no replica of that file for OSX.

I saw an answer on a thread here that said it was possible to make a "dummy" windows.h file and just insert whatever #includes or function prototypes I needed. To do this I just went online and got the functions I needed from some Microsoft directories.

I proceeded to do that and everything was working fine until the ZeroMemory function gave me errors.

So, inside of my dummy "windows.h" file:

void ZeroMemory([in] PVOID  Destination,[in] SIZE_T Length);

I get these errors:

Expected parameter declarator
Use of undeclared identifier 'in'
Expected ')'

Now, I have googled the function and its errors and I keep finding a bunch of code that just has this line of code in it, which doesn't really help much.

What I need to know is where do I go from here? Am I doing the right thing by creating this "dummy" windows.h file? Or is there another way to get around using windows.h?

The link I found the answer to use a dummy windows.h file is here.

I appreciate all the input, so if you have anything on your mind, please throw it down! Thanks so much everyone!


After changing some of the code according to the comments:

void ZeroMemory(PVOID  Destination, SIZE_T Length);

I get these errors:

Unknown type name PVOID
Unknown type name SIZE_T

I was thinking there may be some definitions I am missing but these are TYPE names, so they must be coming out of something like a Struct? Correct me if I'm wrong please? :D

Community
  • 1
  • 1
  • Syntax you used is wrong I think. You should declare it with `PVOID Destination[in]`. – ameyCU Dec 14 '15 at 04:59
  • 3
    I believe `[in]` is a documentation annotation to tell you it is an input parameter. It is not supposed to be part of the actual code. Just remove it. – kaylum Dec 14 '15 at 05:03
  • I'll try that once I finish grabbing carry out! Lol thank you. – CollegeStrugs Dec 14 '15 at 05:03
  • Thank you Kaylum and AmeyCU. I will removing the "in" and leave them as [] brackets. I'll keep you updated on how that fans out! – CollegeStrugs Dec 14 '15 at 05:05
  • 2
    No, the `[]` are also part of the doc annotation. Remove those too. Just `void ZeroMemory(PVOID Destination, SIZE_T Length);` – kaylum Dec 14 '15 at 05:06
  • Update: After removing the brackets I am left with 2 more errors, basically: unknown type name PVOID and unknown type name SIZE_T. I don't know if I am missing definitions on the top of the file, or where I should go from here? – CollegeStrugs Dec 14 '15 at 05:54
  • You are not going to go far with this approach... At the first function that seriously deals with Windows-specific stuff (say, `CreateWindow`) you won't be able to replicate the functionality without writing a Wine clone. – Matteo Italia Dec 14 '15 at 06:14
  • @Matteo Do you think if I download a regular, windows.h file and run it through the Wine app that could fix the issue? I don't think it will because windows.h calls Windos OS files and .dlls that OS X does not have.. – CollegeStrugs Dec 14 '15 at 06:25
  • @CollegeStrugs: exactly, that is not going to work unless you manage to install a fully-fledged cross-compile environment (plus Wine as a runtime environment), or manage to install and use winelib (seriously discouraged, it's a miracle it kinda works on Linux, I don't want to think at the issues you may run into on OS X). – Matteo Italia Dec 14 '15 at 06:46
  • `#ifndef _In_ #define _In_ #endif`, `typedef void* PVOID; typedef size_t SIZE_T;` , `void ZeroMemory(_In_ PVOID Destination, _In_ SIZE_T Length);` – BLUEPIXY Dec 14 '15 at 08:44

2 Answers2

0

If your header has [in] annotations then you grabbed the wrong file, most likely the IDL file instead of the actual header. In the header it should be _In_ instead, which will be an empty macro. In any case, you'll still have problems because you'll be missing the definitions of things like SIZE_T as you discovered. Unless you want to go and replace every dependency you hit, I'd recommend just replacing the calls themselves with your own versions. For ZeroMemory(p,s), you should be able to replace it trivially with memset(p,0,s). This of course assumes you're only using trivial functionality in the Windows header. If you're using actual platform-specific stuff like windowing, input, etc. then you'll probably just need to get a machine or VM running Windows.

MooseBoys
  • 6,641
  • 1
  • 19
  • 43
  • The goal of this project is for me to be able to implement joystick input from a USB xbox 360 controller, so yes I am using platform specific stuff because I believe input does have to run through the OS. To be honest, I actually did transfer over my code to a windows machine not too long ago but I had to convert from Xcode to Codeblocks and there was a huge mess trying to get all of the libraries I needed. It's like I'm trapped in the middle of OS X and Windows right now =/ – CollegeStrugs Dec 14 '15 at 06:29
  • @CollegeStrugs: either OS X already sees it as a joystick (and in that case you *may* be able to get away with a cross-compiler + wine) or this is not going to work at all (in particular, if you are writing a kernel-mode driver it's never going to work). – Matteo Italia Dec 14 '15 at 06:50
  • I've dug myself into a huge hole. It's kinda surprising to me that there is no tutorials online on how to do this. I'm programming my game through the open frameworks libraries and even open frameworks doesn't have much advice on this besides a plugin that's really confusing.. – CollegeStrugs Dec 14 '15 at 06:59
0

It is a very bad habit that developers on the windows platform tend to fall into, including "windows.h" in simple applications that otherwise conform to standard C or C++.

The most correct option would be to encourage the other students / teacher? to only use standard c or c++ header files when writing their applications. This will ensure that they do not use any windows api specific functions.

You can, of course, create a windows.h, and inline in any trivial windows methods (As MooseBoys answers, ZeroMemory can be trivially implemented with memset) to be able to compile simple programs without altering them, but sooner or later some program is going to use a windows api with no easy or convenient standard C / C++ or CoreFoundation (On OSX, the equivalent framework to access windowing things) equivalent.

Chris Becke
  • 750
  • 4
  • 10