heap is undefined and so ph->ap points somewhere random in memory. That's probably the problem.

Remember in C if you want to pass a variable to a function that will modify its value you have to pass the address of that variable. It's exactly the same with pointers; to initialise heap in HeapCreate you will need to pass in &heap which is of type heap **. And you WILL need to initialise heap before you use it.