www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - need help with Windows CreateNamedPipe Security attributes process

reply Jonathan Villa <jv_vortex msn.com> writes:
Hi,

I've been trying to create a NamedPipe with security attributes 
but at compile time throws:
Error 42: Symbol Undefined _InitializeSecurityDescriptor 8
Error 42: Symbol Undefined _SetSecurityDescriptorDacl 16

This is my code, I'm trying to do it using a class:


module asi.pipe;

import core.sys.windows.windows;
import core.sys.windows.winbase;
import core.stdc.stdlib;

class Pipe
{
	private HANDLE hPipe;
	private SECURITY_ATTRIBUTES sa;

	this(string name)
	{
		CreatePipe(name);
	}

	private void CreatePipe(string pipename)
	{

		sa.lpSecurityDescriptor = malloc(SECURITY_DESCRIPTOR.sizeof);
		InitializeSecurityDescriptor(cast(PSECURITY_DESCRIPTOR)sa.l
SecurityDescriptor, 1);
		SetSecurityDescriptorDacl(cast(PSECURITY_DESCRIPTOR)sa.lpSecurityDescriptor,
TRUE, cast(ACL*)0, FALSE);
		sa.nLength = sa.sizeof;
		sa.bInheritHandle = TRUE;

		CreateNamedPipeA(cast(char*)pipename,
						 PIPE_ACCESS_DUPLEX,
						 (PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT),
						 PIPE_UNLIMITED_INSTANCES,
						 4096,
						 1536,
						 0,
						 &sa);
	}
}


Additional Info:
The installer came with just a few files to handle with Windows, 
comparing the the huge files that are in the repository of 
druntime: 
https://github.com/D-Programming-Language/druntime/tree/master/src/core/sys/windows
So I renamed the old import to Windows2 and copied this whole 
github/windows folder there and used its winbase.d because there 
are the functions definitions that I needed.

This functions that throw me errors belongs to the advapi32.dll 
file. I tried to add pragma(lib "advapi32"); but it didn't work.

I'm new/noob dealing with D and I would appreciate any help.

thanks.
Nov 30 2015
parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Tuesday, 1 December 2015 at 04:10:55 UTC, Jonathan Villa wrote:
 Hi,

 I've been trying to create a NamedPipe with security attributes 
 but at compile time throws:
 Error 42: Symbol Undefined _InitializeSecurityDescriptor 8
 Error 42: Symbol Undefined _SetSecurityDescriptorDacl 16
What is causing this: Is this a compile or a linker error?
 This is my code, I'm trying to do it using a class:


 module asi.pipe;

 import core.sys.windows.windows;
 import core.sys.windows.winbase;
 import core.stdc.stdlib;

 class Pipe
 {
 	private HANDLE hPipe;
 	private SECURITY_ATTRIBUTES sa;

 	this(string name)
 	{
 		CreatePipe(name);
 	}

 	private void CreatePipe(string pipename)
 	{

 		sa.lpSecurityDescriptor = malloc(SECURITY_DESCRIPTOR.sizeof);
 		InitializeSecurityDescriptor(cast(PSECURITY_DESCRIPTOR)sa.l
SecurityDescriptor, 1);
is the cast necessary?
 		SetSecurityDescriptorDacl(cast(PSECURITY_DESCRIPTOR)sa.lpSecurityDescriptor,
TRUE, cast(ACL*)0, FALSE);
 		sa.nLength = sa.sizeof;
 		sa.bInheritHandle = TRUE;

 		CreateNamedPipeA(cast(char*)pipename,
you want toStringz(pipename) or if you know pipename is a null terminated string pipename.ptr
 						 PIPE_ACCESS_DUPLEX,
 						 (PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT),
 						 PIPE_UNLIMITED_INSTANCES,
 						 4096,
 						 1536,
 						 0,
 						 &sa);
 	}
 }


 Additional Info:
 The installer came with just a few files to handle with 
 Windows, comparing the the huge files that are in the 
 repository of druntime: 
 https://github.com/D-Programming-Language/druntime/tree/master/src/core/sys/windows
 So I renamed the old import to Windows2 and copied this whole 
 github/windows folder there and used its winbase.d because 
 there are the functions definitions that I needed.

 This functions that throw me errors belongs to the advapi32.dll 
 file. I tried to add pragma(lib "advapi32"); but it didn't work.
this needs a comma i.e. pragma(lib ,"advapi32"); it may also require the appropriate file suffix (.dll or .lib)
 I'm new/noob dealing with D and I would appreciate any help.

 thanks.
Nov 30 2015
parent reply Jonathan Villa <jv_vortex msn.com> writes:
On Tuesday, 1 December 2015 at 05:26:25 UTC, Nicholas Wilson 
wrote:

 What is causing this: Is this a compile or a linker error?
this is the real output of the error: Building Debug\ASI.exe... OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html Debug\ASI.obj(ASI) Error 42: Symbol Undefined _SetSecurityDescriptorDacl 16 Debug\ASI.obj(ASI) Error 42: Symbol Undefined _InitializeSecurityDescriptor 8 Building Debug\ASI.exe failed!
 is the cast necessary?
I tried without the cast and it throws me a compile error, so I made the cast.
 you want toStringz(pipename) or if you know pipename is a null 
 terminated string pipename.ptr
Thanks for your advice, I'm very noob with D so I downloaded the new book that came out that can be free. It's supposed that the name will come in the arguments (I've not written that yet, I did just put some basic string "pipechanneltest" <-string literal.
 pragma(lib ,"advapi32");
 it may also require the appropriate file suffix (.dll or .lib)
Yes, I wrote it with comma, it was just a typo error. advapi32.lib I found it in my DMD installation folder (dmd2/windows/lib) (62.5K), same as kernel32.lib (106K). Can I use .lib files from my Windows SDK? it's heavier (189K). I wrote after the pragma(lib ,"kernel32"); the following line: pragma(lib, "advapi32.lib"); I tried without file suffix and with .dll suffix and it failed in all cases. MAN! what the heck? I changed the build from x86 to x64 and there's no more errors. Even without the new pragma line. Either way I would prefer x64 over x86.
Dec 01 2015
next sibling parent Rikki Cattermole <alphaglosined gmail.com> writes:
On 02/12/15 3:40 AM, Jonathan Villa wrote:
 On Tuesday, 1 December 2015 at 05:26:25 UTC, Nicholas Wilson wrote:

 What is causing this: Is this a compile or a linker error?
this is the real output of the error: Building Debug\ASI.exe... OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html Debug\ASI.obj(ASI) Error 42: Symbol Undefined _SetSecurityDescriptorDacl 16 Debug\ASI.obj(ASI) Error 42: Symbol Undefined _InitializeSecurityDescriptor 8 Building Debug\ASI.exe failed!
 is the cast necessary?
I tried without the cast and it throws me a compile error, so I made the cast.
 you want toStringz(pipename) or if you know pipename is a null
 terminated string pipename.ptr
Thanks for your advice, I'm very noob with D so I downloaded the new book that came out that can be free. It's supposed that the name will come in the arguments (I've not written that yet, I did just put some basic string "pipechanneltest" <-string literal.
 pragma(lib ,"advapi32");
 it may also require the appropriate file suffix (.dll or .lib)
Yes, I wrote it with comma, it was just a typo error. advapi32.lib I found it in my DMD installation folder (dmd2/windows/lib) (62.5K), same as kernel32.lib (106K). Can I use .lib files from my Windows SDK? it's heavier (189K). I wrote after the pragma(lib ,"kernel32"); the following line: pragma(lib, "advapi32.lib"); I tried without file suffix and with .dll suffix and it failed in all cases. MAN! what the heck? I changed the build from x86 to x64 and there's no more errors. Even without the new pragma line. Either way I would prefer x64 over x86.
Different linker, different defaults. -ms32coff probably will also work :) It all comes down to the old import libs for system libraries that comes with dmd for 32bit.
Dec 01 2015
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 1 December 2015 at 14:40:38 UTC, Jonathan Villa wrote:
 MAN! what the heck? I changed the build from x86 to x64 and 
 there's no more errors. Even without the new pragma line. 
 Either way I would prefer x64 over x86.
64 bit should work better because then it uses the linker and dll definitions from Microsoft, which are more up to date. The ones that come with 32 bit dmd are ancient... like Windows 2000ish. We've known about this for ages but nobody has updated them....
Dec 01 2015
parent Jonathan Villa <jv_vortex msn.com> writes:
On Tuesday, 1 December 2015 at 14:48:37 UTC, Adam D. Ruppe wrote:
 On Tuesday, 1 December 2015 at 14:40:38 UTC, Jonathan Villa 
 wrote:
 MAN! what the heck? I changed the build from x86 to x64 and 
 there's no more errors. Even without the new pragma line. 
 Either way I would prefer x64 over x86.
64 bit should work better because then it uses the linker and dll definitions from Microsoft, which are more up to date. The ones that come with 32 bit dmd are ancient... like Windows 2000ish. We've known about this for ages but nobody has updated them....
Ok, I'm fine with it; I'm gonna stick with x64, It looks like the better option. Thanks all for your help ^^
Dec 01 2015