Thanks for the answers but I think I was looking at the wrong side of the problem, let me explain this better.
I'm working in two applications, one in C# and another one in C++ unmanaged, in both applications I encrypt and decrypt data using the functions in advapi32.
The problem that I'm having is with C++. When I encrypt a string of data, sometimes I get in the output null characters ('\0') and for some reason when I try to retrieve that encrypted data and save it to another location in memory or to the disk, I cant' reach or have access to the data after the null character.
In C# I can get all the data, even the null chars and the data after them.
Obviously because of this, when I save data with C++ and try to read it again and decrypt it with C# I get bad data errors.
At the first moment I thought the problem may be something with the way in which I pass the data to the Encrypt method, and that was the reason of my first question, but now I realize the it is something with the output of the encrypt method.
I appreciate any pointers that you can give me.