Wednesday, April 04, 2007

How to develope a C# component ?

How to develope a C# component ?


Create a new DLL project and add the following...
Server

using System;
using System.Runtime.InteropServices;

namespace WMDateTime
{
[Guid("D52E9FC7-6374-4d5a-B0DA-7343ABB3BF82")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IWMDateTime
{
///
/// Event that can be specified by the caller. Set when the config changes
/// or when a new message is available.
///

[DispId(1)]
long UTCNow { get; }
}

public class WMDateTime : IWMDateTime
{
public WMDateTime() {}
public long UTCNow
{
get
{
DateTime d1 = DateTime.UtcNow;
return d1.Ticks;
}
}
}
}

in the Post Build event add the following :
"C:\Program Files\Microsoft Visual Studio .NET 2003\sdk\v1.1\Bin\"tlbexp $(TargetPath)




C++ COM client :
------------------
1. IWMDateTimePtr dt;

if (FAILED(dt.CreateInstance(__uuidof(WMDateTime))))
{
hr = HRESULT_FROM_WIN32(ERROR_DLL_NOT_FOUND);
return hr;
}
m_dtAudStartTime = dt->GetUTCNow(); //C# component's function

Labels:

0 Comments:

Post a Comment

<< Home