69 lines
1.4 KiB
C++

// This is the main DLL file.
#include "stdafx.h"
#include "DirectoryAndFileAPI.h"
using namespace DirectoryAndFileAPI;
char *DirAndFileFuncts::StringToCharStr(String *InStr)
{
int len = (InStr->get_Length)();
char *rtnstr = new char [len+1];
ZeroMemory(rtnstr,len+1);
for (int i=0; i<len; i++)
rtnstr[i] = (InStr->get_Chars)(i);
return rtnstr;
}
String *DirAndFileFuncts::GetLongName(String *NameIn)
{
char *tmpNameIn;
char *tmpNameOut;
char *fnPtr = NULL;
int rtnval;
tmpNameIn = StringToCharStr(NameIn);
tmpNameOut = new char[1];
memset(tmpNameOut,0,1);
// This will get the buffer size we need
rtnval = GetFullPathName(tmpNameIn,1,tmpNameOut,&fnPtr);
if (rtnval > 1)
{
delete tmpNameOut;
tmpNameOut = new char[rtnval+1];
memset(tmpNameOut,0,rtnval+1);
rtnval = GetFullPathName(tmpNameIn,rtnval,tmpNameOut,&fnPtr);
}
NameOut = new String(tmpNameOut);
return NameOut;
}
String *DirAndFileFuncts::GetShortName(String *NameIn)
{
char *tmpNameIn;
char *tmpNameOut;
int rtnval;
tmpNameIn = StringToCharStr(NameIn);
tmpNameOut = new char[1];
memset(tmpNameOut,0,1);
rtnval = GetShortPathName(tmpNameIn,tmpNameOut,1);
if (rtnval > 1)
{
delete tmpNameOut;
tmpNameOut = new char[rtnval+1];
memset(tmpNameOut,0,rtnval+1);
rtnval = GetShortPathName(tmpNameIn,tmpNameOut,rtnval);
}
NameOut = new String(tmpNameOut);
return NameOut;
}