There should not be any changes in this from .NET 3.5 to 4. (and, btw, msvcrt.dll is not part of the framework - it is the Microsft C++ Runtime Library). Are you sure nothing else has changed in your project.
I just tried this code, which works and prints "4" as expected:
class Test
{
public unsafe static void Main(string[] args)
{
byte[] bytes = new byte[] {70, 40, 30, 51, 0};
fixed(byte* ptr = bytes)
{
int len = strlen(ptr);
Console.WriteLine(len);
}
}
[DllImport("msvcrt.dll")]
private unsafe static extern int strlen(byte* pByte);
}
It is unclear to me why you would ever want to call strlen from managed code, but of course you might have your reasons. If you need an alternative managed implementation, here is a one liner you can use:
private static int managed_strlen(byte[] bytes)
{
return bytes.TakeWhile(b => b != 0).Count();
}
Of course that does not deal with multi-byte (unicode) characters, but I don't think strlen does either.