Maybe I'm going about this wrong...

BlitzMax Forums/BlitzMax Programming/Maybe I'm going about this wrong...

I was given then following C++ code by Indiepath which changes the folder permissions (I want to use it with Vista):

bool CgeneralFuncs::CreateDirectoryUserFullAccess(LPCTSTR lpPath)
{
	int f = CreateDirectory(lpPath,NULL);
	if(!f)
		return false;
	
	HANDLE hDir = CreateFile(lpPath,READ_CONTROL|WRITE_DAC,0,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL);
	if(hDir == INVALID_HANDLE_VALUE)
		return true;
	
	ACL* pOldDACL=NULL;
	SECURITY_DESCRIPTOR* pSD = NULL;
	GetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,&pOldDACL,NULL,(void**)&pSD);
	
	EXPLICIT_ACCESS ea={0};
	ea.grfAccessMode = GRANT_ACCESS;
	ea.grfAccessPermissions = GENERIC_ALL;
	ea.grfInheritance = CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE;
	ea.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
	ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
	ea.Trustee.ptstrName = TEXT("Users");
	
	ACL* pNewDACL = NULL;
	SetEntriesInAcl(1,&ea,pOldDACL,&pNewDACL);
	
	SetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,pNewDACL,NULL);
	
	LocalFree(pSD);
	LocalFree(pNewDACL);
	CloseHandle(hDir);
	return true;
}


I've spent all try trying to convert it into BMax by using Externs and Types instead of structures etc. Got pretty far but got stuck on passing an array of types into a function (see recent thread).

Anyway, perhaps there's a different way. Can this source code be included (and compiled) in with my BMax project somehow so I can call it as an extern function? OR can it be turned into a Dll that I can call from Bmax instead?

Any ideas, I've basically got nuts today trying to do this...

You could Import the C++ file into your BlitzMax code and call the function, you'd have to take it out of the class or wrap it though.

Can this source code be included (and compiled) in with my BMax project somehow


I would think so. Pass in a C string, get back an Int (bool) result. You'll need to #include whatever it needs, and it should work fine.

Rememember to free the C string when you are done with it ( MemFree() )

So um, how would I do that? Yes I see that it's part of the CgeneralFuncs class. That may be Indiepath's. I guess I need to find out what his includes are that are required for that to compile...

*Indiepath where for art thou?*

You'd use Import "cfile.cpp", if you can wrap the class or take it out the class you should be able to use it. BlitzMax has limitations when using C++ Classes.

So simple as that. I use import "cfile.cpp" and then I presume do Extern "C" and declare the function yes?

I gotta find out what the C includes are...

Yea, Advanced topics -> Interfacing with C in the BlitzMax help explains more.

K thanks.