锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
PROCESS_INFORMATION pi;
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpTitle = NULL;
si.lpDesktop = NULL;
si.dwX = si.dwY = si.dwYSize = si.dwXSize = 0;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.lpReserved2 = NULL;
si.cbReserved2 = 0;
BOOL ret = CreateProcess(strHostFileFullName, NULL, NULL, NULL, FALSE, 0, NULL, strPath, &si, &pi);
if (!ret) {
return false;
}
WaitForInputIdle(pi.hProcess, 30000);
XXXCtxActivator activator;
if(!activator.IsActivated())
return false;
CComPtr<IClassFactory> pFactory;
HRESULT hr = CoGetClassObject(CLSID_XXX, CLSCTX_LOCAL_SERVER, NULL, __uuidof(pFactory), reinterpret_cast<void**>(&pFactory));
if (FAILED(hr))
return false;
if(FAILED(hr))
return false;
// If created successfully, start the monitoring thread
DWORD dwProcessId = GetCurrentProcessId();
long nMonitoringPid = 0;
hr = s_spXXX->StartProcessManagementThread(dwProcessId, &nMonitoringPid); if (FAILED(hr) || nMonitoringPid == 0)
]]>


This is tricky issue. Thanks very much for Jeffery's help.
]]>
銆銆{
銆銆char name[30];
銆銆mutable int accesses;
銆銆
.
銆銆};
銆銆const data veep = {"david";,0,}
銆銆strcpy(veep.name,"Jimmy");// not allowed
銆銆veep.accesses++; // allowed
]]>
]]>鍚嶇О Factory Method 緇撴瀯
鎰忓浘 瀹氫箟涓涓敤浜庡垱寤哄璞$殑鎺ュ彛錛岃瀛愮被鍐沖畾瀹炰緥鍖栧摢涓涓被銆侳actory Method 浣夸竴涓被鐨勫疄渚嬪寲寤惰繜鍒板叾瀛愮被銆?/td> 閫傜敤鎬?/td>
{
public abstract class LightFactory
{
public abstract Light CreateLight();
}
public class BulbLightFactory : LightFactory
{
public override Light CreateLight()
{
return new BulbLight();
}
}
public class TubeLightFactory : LightFactory
{
public override Light CreateLight()
{
return new TubeLight();
}
}
}
{
public abstract class Light
{
public abstract void TurnOn();
public abstract void TurnOff();
}
public class BulbLight : Light
{
public override void TurnOn()
{
Console.WriteLine("Bulb Ligh is Turned on.\n");
}
public override void TurnOff()
{
Console.WriteLine("Bulb Ligh is Turned off.\n");
}
}
public class TubeLight : Light
{
public override void TurnOn()
{
Console.WriteLine("Tube Ligh is Turned on.\n");
}
public override void TurnOff()
{
Console.WriteLine("Tube Ligh is Turned off.\n");
}
}
}
{
public class Client
{
public static void Main()
{
LightFactory BulbFactory = new BulbLightFactory();
LightFactory TubeFactory = new TubeLightFactory();
Light l1 = BulbFactory.CreateLight();
Light l2 = TubeFactory.CreateLight();
l1.TurnOn();
l1.TurnOff();
Console.WriteLine("===============\n");
l2.TurnOn();
l2.TurnOff();
}
}
}
]]>
]]>
*char *memchr(buf, chr, cnt) - search memory for given character.
*
*Purpose:
* Searches at buf for the given character, stopping when chr is
* first found or cnt bytes have been searched through.
*
*Entry:
* void *buf - memory buffer to be searched
* int chr - character to search for
* size_t cnt - max number of bytes to search
*
*Exit:
* returns pointer to first occurence of chr in buf
* returns NULL if chr not found in the first cnt bytes
*
*Exceptions:
*
*******************************************************************************/
void * __cdecl memchr (
const void * buf,
int chr,
size_t cnt
)
{
while ( cnt && (*(unsigned char *)buf != (unsigned char)chr) ) {
buf = (unsigned char *)buf + 1;
cnt--;
}
return(cnt ? (void *)buf : NULL);
}
]]>
*memmove - Copy source buffer to destination buffer
*
*Purpose:
* memmove() copies a source memory buffer to a destination memory buffer.
* This routine recognize overlapping buffers to avoid propogation.
* For cases where propogation is not a problem, memcpy() can be used.
*
*Entry:
* void *dst = pointer to destination buffer
* const void *src = pointer to source buffer
* size_t count = number of bytes to copy
*
*Exit:
* Returns a pointer to the destination buffer
*
*Exceptions:
*******************************************************************************/
void * __cdecl mymemcpy (
void * dst,
const void * src,
size_t count
)
{
void * ret = dst;
/*
* copy from lower addresses to higher addresses
*/
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
return(ret);
}
void * __cdecl mymemmove (
void * dst,
const void * src,
size_t count
)
{
void * ret = dst;
if (dst <= src || (char *)dst >= ((char *)src + count)) {
/*
* Non-Overlapping Buffers
* copy from lower addresses to higher addresses
*/
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
}
else {
/*
* Overlapping Buffers
* copy from higher addresses to lower addresses
*/
dst = (char *)dst + count - 1;
src = (char *)src + count - 1;
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst - 1;
src = (char *)src - 1;
}
}
return(ret);
}
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
int a[10];
for(i; i < 10; i++)
{
a[i] = i;
}
mymemcpy(&a[4], a, sizeof(int)*6);
for(i = 0; i < 10; i++)
{
printf("%d ",a[i]);
}
printf("\n");
for(i=0; i < 10; i++)
{
a[i] = i;
}
mymemmove(&a[4], a, sizeof(int)*6);
for(i = 0; i < 10; i++)
{
printf("%d ",a[i]);
}
printf("\n");
return 0;
}
Result:
0 1 2 3 0 1 2 3 0 1
0 1 2 3 0 1 2 3 4 5
]]>
*memmove - Copy source buffer to destination buffer
*
*Purpose:
* memmove() copies a source memory buffer to a destination memory buffer.
* This routine recognize overlapping buffers to avoid propogation.
* For cases where propogation is not a problem, memcpy() can be used.
*
*Entry:
* void *dst = pointer to destination buffer
* const void *src = pointer to source buffer
* size_t count = number of bytes to copy
*
*Exit:
* Returns a pointer to the destination buffer
*
*Exceptions:
*******************************************************************************/
void * __cdecl memmove (
void * dst,
const void * src,
size_t count
)
{
void * ret = dst;
if (dst <= src || (char *)dst >= ((char *)src + count)) {
/*
* Non-Overlapping Buffers
* copy from lower addresses to higher addresses
*/
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
}
else {
/*
* Overlapping Buffers
* copy from higher addresses to lower addresses
*/
dst = (char *)dst + count - 1;
src = (char *)src + count - 1;
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst - 1;
src = (char *)src - 1;
}
}
return(ret);
}
]]>
*char *memset(dst, val, count) - sets "count" bytes at "dst" to "val"
*
*Purpose:
* Sets the first "count" bytes of the memory starting
* at "dst" to the character value "val".
*
*Entry:
* void *dst - pointer to memory to fill with val
* int val - value to put in dst bytes
* size_t count - number of bytes of dst to fill
*
*Exit:
* returns dst, with filled bytes
*
*Exceptions:
*
*******************************************************************************/
void * __cdecl memset (
void *dst,
int val,
size_t count
)
{
void *start = dst;
while (count--) {
*(char *)dst = (char)val;
dst = (char *)dst + 1;
return(start);
}
]]>