New Job and Test

Hey! I have successfully moved to my new job.

this is a test of the


national broadcasting


Hey! what a cool way of publishing code!

using System;

using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
using System.Runtime.InteropServices;

namespace Test
{
//
// .NET class, interface exposed through DCOM
//

// exposed COM interface
[GuidAttribute(MyService.guidIMyInterface), ComVisible(true)]
public interface IMyInterface
{
string GetDateTime(string prefix);
}

// exposed COM class
[GuidAttribute(MyService.guidMyClass), ComVisible(true)]
public class CMyClass: IMyInterface
{
// Print date & time and the current EXE name
public string GetDateTime(string prefix)
{
Process currentProcess = Process.GetCurrentProcess();
return string.Format("{0}: {1} [server-side COM call executed on {2}]",
prefix, DateTime.Now, currentProcess.MainModule.ModuleName);
}
}

//
// My hosting Windows service
//
internal class MyService :
ServiceBase
{
public MyService()
{
// Initialize COM security
Thread.CurrentThread.ApartmentState = ApartmentState.STA;
UInt32 hResult = ComAPI.CoInitializeSecurity(
IntPtr.Zero, // Add here your Security descriptor
-1,
IntPtr.Zero,
IntPtr.Zero,
ComAPI.RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
ComAPI.RPC_C_IMP_LEVEL_IDENTIFY,
IntPtr.Zero,
ComAPI.EOAC_DISABLE_AAA
| ComAPI.EOAC_SECURE_REFS
| ComAPI.EOAC_NO_CUSTOM_MARSHAL,
IntPtr.Zero);
if (hResult != 0)
throw new ApplicationException(
"CoIntializeSecurity failed" + hResult.ToString("X"));
}

// The main entry point for the process
static void Main()
{
ServiceBase.Run(new ServiceBase[] { new MyService() });
}
///
/// On start, register the COM class factory
from Adi Oltean's WebLog

Comments

Popular Posts