• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >vc/mfc > 最简单的com和客户端调用,也出问题。初学者200分相送

最简单的com和客户端调用,也出问题。初学者200分相送

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-06-04

佚名通过本文主要向大家介绍了ca88.com下载客户端,酷6.com视频客户端,dr.com宽带客户端,dr.com宽带认证客户端,dr.com校园客户端等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: 最简单的com和客户端调用,也出问题。初学者200分相送
描述:

我用ATL写了个最简单的com(MessageBoxSvr.dll),里面只有一个接口IMsg,接口只有一个方法(函数)SendMsg(),函数只有一条语句MessageBox("Hello Com");
我在客户调用是这样的,在stdafx.h中用#import "..."(MessageBox.dll的完整路径),然后再对话框初始化中调用OleInitialize();测试按钮调用我的com:
void CMessageClientDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
IMsgPtr pMsg = NULL;//智能指针
pMsg.CreateInstance(__uuidof(IMsg));
pMsg->SendMsg();
}
编译通过,执行的时候。出现错误
“Runtime Error,abnormal Program termination”。组件已经注册。


解决方案1:

gz

解决方案2:

Header: Declared in objbase.h.
  Library: Use ole32.lib.

解决方案3:

用CoInitialize()

解决方案4:

CoInitializeEx
Initializes the COM library for use by the calling thread, sets the thread's concurrency model, and creates a new apartment for the thread if one is required. 
HRESULT CoInitializeEx(
  void * pvReserved,
  DWORD dwCoInit
);
Parameters
pvReserved 
[in] Reserved; must be NULL. 
dwCoInit 
[in] Flags specifying the concurrency model and initialization options for the thread. Values for this parameter are taken from the COINIT enumeration. Any combination of values from the COINIT enumeration can be used, except that the COINIT_APARTMENTTHREADED and COINIT_MULTITHREADED flags cannot both be set. 
Return Values
This function supports the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following: 
S_OK 
The COM library was initialized successfully on the calling thread. 
S_FALSE 
The COM library is already initialized on the calling thread. 
RPC_E_CHANGED_MODE 
A previous call to CoInitializeEx specified a different concurrency model for the calling thread, or the thread that called CoInitializeEx currently belongs to the neutral threaded apartment. 
Remarks
CoInitializeEx must be called at least once, and is usually called only once, for each thread that uses the COM library. Multiple calls to CoInitializeEx by the same thread are allowed as long as they pass the same concurrency flag, but subsequent valid calls return S_FALSE. To close the COM library gracefully on a thread, each successful call to CoInitialize or CoInitializeEx, including any call that returns S_FALSE, must be balanced by a corresponding call to CoUninitialize.
Note   You must include the #define _WIN32_DCOM preprocessor directive at the beginning of your code to be able to use CoInitializeEx.
A thread must call CoInitializeEx or CoInitialize before calling any other COM library function except the CoGetMalloc function and other memory allocation calls (CoTaskMemAlloc, CoTaskMemFree, CoTaskMemReAlloc, and the IMalloc methods on the task allocation supplied by CoGetMalloc). 
Once the concurrency model for a thread is set, it cannot be changed. A call to CoInitializeEx on a thread that was previously initialized with a different concurrency model will fail and return RPC_E_CHANGED_MODE. 
If neither concurrency model is specified by the dwCoInit parameter, the default is COINIT_MULTITHREADED.
Objects created in a single-threaded apartment (STA) receive method calls only from their apartment's thread, so calls are serialized and arrive only at message-queue boundaries (when the Win32 function PeekMessage or SendMessage is called).
Objects created on a COM thread in a multithread apartment (MTA) must be able to receive method calls from other threads at any time. You would typically implement some form of concurrency control in a multithreaded object's code using Win32 synchronization primitives such as critical sections, semaphores, or mutexes to help protect the object's data. 
When an object that is configured to run in the neutral threaded apartment (NTA) is called by a thread that is in either an STA or the MTA, that thread transfers to the NTA. If this thread subsequently calls CoInitializeEx, the call fails and returns RPC_E_CHANGED_MODE.
CoInitializeEx provides the same functionality as CoInitialize and also provides a parameter to explicitly specify the thread's concurrency model. The current implementation of CoInitialize calls CoInitializeEx and specifies the concurrency model as single-thread apartment. Applications developed today should call CoInitializeEx rather than CoInitialize. 
Because OLE technologies are not thread-safe, the OleInitialize function calls CoInitializeEx with the COINIT_APARTMENTTHREADED flag. As a result, an apartment that is initialized for multithreaded object concurrency cannot use the features enabled by OleInitialize.
Because there is no way to contr

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • COM服务端返回S_OK,但客户端收到却是其它值?
  • COM+服务在客户端失去连接后,怎么捕捉啊
  • COM中如何把接口从客户端传到服务端
  • 请问我写的COM+客户端程序啥地方出错了?
  • 如何利用COM+创建服务器端和客户端安装程序
  • COM服务端如何更改默认客户端程序?
  • com服务器对象如何检测异常退出的客户端对象
  • COM与客户端之间的回调函数
  • 如果我想在COM中调用客户程序的函数,该如何作?
  • COM如何将客户程序中的函数传递给服务器exe?

相关文章

  • 2017-06-05 MFCAppWinzarddll程序创建时没有选automation选项,怎么才能支持自动化(如果不从头做)
  • 2017-06-04 关于程序结构的问题!
  • 2017-06-04 activex控件在delphi里面调用,怎么没有onclick事件
  • 2017-06-05 cab文件如何安装或者转换为exe文件?
  • 2017-06-04 不用ALT,只用C/C++如果写一个COM才能在网页中被创建,以及方法可以被调用?
  • 2017-06-04 如何得到realplayer控件的视频?
  • 2017-06-04 ATL中的返回结果问题
  • 2017-06-04 ExtJsOS挑战ChromeOS?
  • 2017-06-05 IVideoWindow播放视频的时候加系统时间
  • 2017-06-04 如何利用MSComm控件传送文件的例子

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 生成一个OCX控件遇到控件中edit无法显示问题
    • 初学者还问:关于ATL的补充接口
    • 编译的时候报errorC2065:AfxConnectionAdvise:undeclaredidentifier
    • dll中封装ado问题
    • 文本宽度的问题
    • 用VC6作了一个任务栏上的工具栏,但是知道怎么让工具栏自动显示出来
    • 请问,做一个dcom程序,怎样注册server端client端,
    • 调用dll结束时出错
    • 主程序没启动,ActiveX控件就生成了!
    • 怎样将线程里的数据传给窗口编辑框

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有