不好意思刚才没写清楚,我需要的是 VC++.NET 的代码。
先谢谢各位了。
先谢谢各位了。
解决方案 »
- 高手可以近来看看!
- 100分! 请教高手,如何删除带颜色块列表项的(下拉)列表框?
- DateTime_SetSystemtime的问题
- vc++中mscomm控件中的setting属性的“bbbb,p,d,s”可以用变量吗?
- 求助高手:mfc绘图右键单击特定区域响应
- 问个界面缩放布局的问题。
- vc如何将一个服务程序安装到系统中?
- C++用ADO调用MSSQL超时
- 在CMainFrame中(或自定义类),如何向CmyView (EditView)中输出文字。
- 请问你们当初学C++时在语法上泡的多不多
- 谁能告诉我CInternetSession构造函数的第5个参数怎么使用?
- CSDN最近怎么什么问题也解决不了??????????????????我再问一遍!!!!!!!!!!(111222)
拜托啦
第一个给出能调试通过的 vc++.net 代码的,马上就结贴给分!!!
具体的我也不记得了
这个问题不就是 com 的基础吗???感觉应该很简单啊!没人知道吗?
// compile with: /link /OPT:NOREF
#define _ATL_ATTRIBUTES 1
#include <atlbase.h>
#include <atlcom.h>
#include <stdio.h>
#include "evh_server.h" //此处为com头文件[ module(name="EventReceiver") ];[ event_receiver(com) ]
class CReceiver { //接受器com
public:
HRESULT MyHandler1(int nValue) { //处理函数
printf("MyHandler1 was called with value %d.\n", nValue);
return S_OK;
} HRESULT MyHandler2(int nValue) {
printf("MyHandler2 was called with value %d.\n", nValue);
return S_OK;
} void HookEvent(IEventSource* pSource) { //连接事件
__hook(&IEvents::MyEvent, pSource, &CReceiver::MyHandler1);
__hook(&IEvents::MyEvent, pSource, &CReceiver::MyHandler2);
} void UnhookEvent(IEventSource* pSource) { //取消连接
__unhook(&IEvents::MyEvent, pSource, &CReceiver::MyHandler1);
__unhook(&IEvents::MyEvent, pSource, &CReceiver::MyHandler2);
}
};int main() { //.exe
// Create COM object
CoInitialize(NULL);
IEventSource* pSource = 0;
HRESULT hr = CoCreateInstance(__uuidof(CSource), NULL, CLSCTX_ALL,
__uuidof(IEventSource), (void **) &pSource);
if (FAILED(hr)) {
return -1;
} // Create receiver and fire event
CReceiver receiver;
receiver.HookEvent(pSource);
pSource->FireEvent();
receiver.UnhookEvent(pSource); CoUninitialize();
return 0;
}
//注:CSource是服务器Com类
//代码使用了vs.net的属性编程,没有使用托管代码
//其实是vs.net的例子:)