I am trying to create a managed prototype in C # for an [CreateSymbolicLink][1]API function . The prototype in WinBase.h is:
BOOLEAN APIENTRY CreateSymbolicLink (
__in LPCWSTR lpSymlinkFileName,
__in LPCWSTR lpTargetFileName,
__in DWORD dwFlags
);
And BOOLEAN is defined as BYTEin WinNT.h. Good. Therefore, my guided prototype should be:
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool CreateSymbolicLink(string SymlinkFileName, string TargetFileName, UInt32 Flags);
At least I would think so. boolis just an alias for a System.Booleansingle-byte value. But it doesn't seem to work.
I am executing this code:
bool retval = CreateSymbolicLink(LinkFilename, TargetFilename, 0);
He returns true. But a symbolic link has not been created. The reason it was not created is because I do not work with elevated privileges. GetLastErrorreturns 1314, which according to WinError.h means that I do not have the required permission. As expected. But why is my return value true?
, :
static extern byte CreateSymbolicLink(string SymlinkFileName, string TargetFileName, UInt32 Flags);
:
byte retval = CreateSymbolicLink(LinkFilename, TargetFilename, 0);
: retval 0, , .
, , bool BOOLEAN ?