Shared pain

Jason House jason.james.house at gmail.com
Thu Nov 18 05:32:13 PST 2010


I'm not familiar with the API, but are you able to declare your original _sta as immutable and call it a day? Immutable data should have the same protection as __gshared but with no implications of bypassing the type system.

If that's not helpful, can you give more details like calling patterns? Is the function called from one thread or from many? My quick read of the windows documentation makes it seem like that's true. Probably unimportant, but I'd use _sta.ptr instead of &_sta[0] because the former more clearly implies array pointer to me, but that may be my own quirky style. 

Steve Teale Wrote:

> I had D code that provided a basis for creation of Windows services, 
> which I have just tried to get working with the latest D2.
> 
> No dice.
> 
> The point of failure was in this method
> 
> static void StartService()

> {

>    if (!StartServiceCtrlDispatcherA(cast(SERVICE_TABLE_ENTRY *) &_sta[0]))

>    {
>       ...

>    }

> }
> 
> Where _sta is an array of SERVICE_TABLE_ENTRY structs. The bits of code 
> that install and remove the service worked fine, but the service control 
> dispatcher was clearly not happy about these structs being in TLS, and 
> the service crashed immediately when I tried to start it.
> 
> The class also has a couple of methods with signatures like:
> 
> extern (Windows) static export void service_ctrl(uint dwCtrlCode) {...}
> 
> That's probably not relevant, but I think it contributed to a host of 
> errors that finally made be take a big step back.
> 
> I re-implemented the thing in the style used for OOP in C.
> 
> struct ServiceBase
> {
>    SERVICE_TABLE_ENTRY[2] _sta;
>    ...
> }
> 
> __gshared ServiceBase __sb;
> 
> void initialize(ServiceBase* sb) { ... }
> void whatever(ServiceBase* sb ...) { ... }
> 
> and used the __sb global within the functions with the Windows signature, 
> which just became
> 
> extern (Windows) export void service_ctrl(uint dwCtrlCode) {...}
> 
> Now it's working again, but I want to change it into idiomatically sound 
> D code.
> 
> Style suggestions please!
> 
> Steve




More information about the Digitalmars-d mailing list