?? siclient.cpp
字號:
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
// 如果SIServerLib.dll文件沒有找到,你需要創建SIServer解決方案,然后執行/Bin
//目錄的CreateTypeLib.bat腳本文件,生成該文件
#using "../bin/SIServerLib.dll"
using namespace System;
using namespace SIServerLib;
using namespace Reflection; //只用于后期綁定
//這個類用于說明如何進行早期綁定
__gc class CSIEB
{
public:
//構造函數
CSIEB()
{ //創建一個COM組件對象的實例,也就是說生成一個運行態可
//調用的包裝類,這個類負責組件實例化
pSystemInfo = new CDGetSystemInfo;
}
// 返回當前主機的名字
String* PrintComputerName()
{
if (pSystemInfo)
{
// 從Com組件服務器獲得主機名
return String::Concat(S"當前主機的名字為",pSystemInfo->GetMyComputerName());
}
else
return (String*) 0;
}
private:
CDGetSystemInfo *pSystemInfo;
};
// Class to demonstrate late binding.
__gc class CSILB
{
public:
// Constructor
CSILB()
{
// Get Type object for COM server. It uses ProgID of DClock class.
typ = Type::GetTypeFromProgID("SIServer.DGetSystemInfo");
// obtain instance of COM object.
obj = Activator::CreateInstance(typ);
// Create array of parameters.
args = new Object*[0];
}
// Returns string that has current time.
// If bAddDate is not 0, it returns date and time,
// if bAddDate is 0, returns time only.
String* PrintComputerName()
{
if (!typ || !obj)
return (String*) 0;
return String::Concat(S"當前主機的名字為",typ->InvokeMember("GetMyComputerName", BindingFlags::InvokeMethod, Type::DefaultBinder, obj,0));
}
private:
Type *typ;
Object *obj;
Object* args[];
};
// This is the entry point for this application
#ifdef _UNICODE
int wmain(void)
#else
int main(void)
#endif
{
String *result;
// Create and use managed C++ class that uses early binding.
try
{
CSIEB *objEB;
objEB = new CSIEB();
result = objEB->PrintComputerName();
if (result)
Console::WriteLine(result);
else
Console::WriteLine(S"出錯信息: 無法得到主機名字");
// 創建使用一個后期綁定的托管C++類
CSILB *objLB;
objLB = new CSILB();
result = objLB->PrintComputerName();
if (result)
Console::WriteLine(result);
else
Console::WriteLine(S"出錯信息: 無法得到主機名字");
}
catch(Exception* e)
{
Console::WriteLine("錯誤信息: {0}", e->Message);
}
Console::Write("\n\n按回車鍵繼續");
Console::ReadLine();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -