Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Shalako

macrumors newbie
Original poster
Feb 19, 2012
3
0
Hello,

I am new to Xcode and Objective C. I normally use RealStudio but I need to covert some C++ into Objective C so I can compile a dylib for a poker program project. So far I have converted everything over ok except a few lines containing this CopyMemory function:

CopyMemory (m_ucTotalSuit, m_ucBoardSuit, 4);

I believe this is a windows API of some sort. Does anybody know what the equivalent would be in Xcode/Obj C? Any help would be greatly appreciated.

Thanks
 
It looks like memcpy(), which is a standard C function available everywhere. This suggests perhaps that it's not quite like memcpy()? If the line you have there copies 4 bytes from m_ucBoardSuit to m_ucTotalSuit, then it is. But it can differ in other ways like error handling and so on?

Edit: just found out (from Google) that CopyMemory is nothing but a macro for memcpy(), stupid Microsoft. So you could probably try this:

Code:
#define CopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
 
Last edited:
Hello,

I am new to Xcode and Objective C. I normally use RealStudio but I need to covert some C++ into Objective C so I can compile a dylib for a poker program project. So far I have converted everything over ok except a few lines containing this CopyMemory function:

CopyMemory (m_ucTotalSuit, m_ucBoardSuit, 4);

I believe this is a windows API of some sort. Does anybody know what the equivalent would be in Xcode/Obj C? Any help would be greatly appreciated.

Thanks

Without knowing what m_ucTotalSuit and m_ucBoardSuit really are, in Objective C there's

memcpy()

BUT: This simply copies memory regions, it does not deal with reference counting or anything. It purely copies bztes from one location to another.

It has no meaning in the lifecycle of your objects. So if these variables above are indeed objects you probably want to "clone" them.

PS: Convert them into Obj-C classes and duplicate them by implementing NSCopying.

Without knowing your code, it's really hard to tell.

EDIT: subsonix beat me ;)
 
I'll give you some really great help, that will serve you well for many years to come. Here we go:

You have Safari running already. Decide what you want to learn about, in your case "CopyMemory". Enter the term into the Google search box and hit return. In this case, it gets you straight to the MSDN article describing what the function does.

So what is the Standard C function that does exactly the same thing as CopyMemory? And what is the Standard C function that does exactly the same thing as MoveMemory, which is explained about half down the page?

(Guys, PLEASE don't mention the names of these functions. If someone cannot use Google, learning that is the topmost priority, and anything keeping them from learning to use Google is just damaging. )

Edit: Sadly, too late.
 
Code:
#define CopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))

Thank you for the fast reply. I tried that and still got the same error:

error: 'memcpy' was not declared in this scope

I am so out of my league on this project but I am determined to figure it out so I have at least some Xcode experience.
 
Learning Xcode and Objective C by porting windows code is a questionable approach anyways.

There are tons of examples in the documentation anyways.
Learning something new sometimes requirees forgetting what you already learned....
 
Thanks for all of the help. I fixed it by including:

#include <string.h>

I really am a novice!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.