com高手请进!!!!急

look__look 2002-06-20 02:31:42
在vb中引用的com ,vc中怎样使用(有idl文件)??
...全文
172 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
ma811 2002-06-21
  • 打赏
  • 举报
回复
先调用::CoInitialize(0);
最后用::CoUnin...
look__look 2002-06-21
  • 打赏
  • 举报
回复
怎么没有人能告诉我答案!
look__look 2002-06-21
  • 打赏
  • 举报
回复
在线等待!!
look__look 2002-06-21
  • 打赏
  • 举报
回复
dll不是我做的,是厂商提供的,vb使用正常!!
在第5步时,有问题,有时产生os异常,有时返回0x800401f0!!
volcary 2002-06-21
  • 打赏
  • 举报
回复
1.注册你的DLL yourcom.dll -regserver32
2.#import "youcom.dll" no_namespace
3.coinitialize(null)
4.定义 yourcomclassPtr cominter
5.cominter.cocreateinstance()
......
6.cominter.Release();
7.couninitialize()
look__look 2002-06-21
  • 打赏
  • 举报
回复
在exe中调用CreateInstance()时出错了代码是0x800401f0!!我怎么找不到呀!!
look__look 2002-06-21
  • 打赏
  • 举报
回复
问题解决了,这是msdn中写的:

BUG: AfxOleInit Returns TRUE Without Initializing OLE in a DLL
Last reviewed: March 11, 1998
Article ID: Q154320
The information in this article applies to:
The Microsoft Foundation Classes, included with: Microsoft Visual C++, 32-bit Edition, version 4.2


SYMPTOMS
When developing an MFC Regular DLL, you may want to use OLE without exposing an OLE object, such as displaying a dialog from within the DLL which contains an OLE control. A failure may occur when calling DoModal() in the dialog creation if you used AfxOleInit or AfxEnableControlContainer to initialize OLE within the DLL. Typically, this would be done by calling them in the InitInstance of the CWinApp derived class.



CAUSE
In an MFC Regular DLL, AfxOleInit() will not initialize OLE since MFC cannot uninitialize OLE in the DLL_PROCESS_DETACH, ExitInstance(). In that case, OLE may already have been unloaded. The decision to not initialize OLE is by design. The bug is that AfxOleInit() will return TRUE after setting m_bNeedTerm to -1. According to the documentation, AfxOleInit() returning TRUE means that OLE was initialized, which is not the case in a DLL.



RESOLUTION
In order to uninitialize OLE when initialized in the DLL, would require exported methods for initialization and uninitialization that the client would have to call, since the uninitialization would have to occur before CWinApp::ExitInstance, which is a part of DLL_PROCESS_DETACH.

A better solution is to initialize and uninitialize OLE in the client application. This can be done in MFC by calling AfxOleInit in the application's InitInstance method of the CWinApp derived class. MFC will then uninitialize OLE when exiting the application.

Alternatively, you could use the SDK to initialize and uninitialize OLE in the client application by calling OleInitialize(NULL) in the InitInstance method and OleUninitialize in the ExitInstance method.

To ensure that the container initializes OLE before using the DLL, use the sample code below to display a message to the user when OLE hasn't been initialized.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION


Sample Code

/* Compile options needed: None
*/


BOOL CMyRegularDll::InitInstance() {
#ifdef _DEBUG
// Initialize OLE
HRESULT hr = OleInitialize(NULL);
if (hr == S_FALSE) {
OleUninitialize();
}else{
if (hr == S_OK) {
AfxMessageBox("OLE needs to be initialized in the Client
Application before using this DLL");
}else{
AfxMessageBox("There is a problem with initializing OLE");
}
return FALSE;
}
#endif

// Call if using OLE Controls
AfxEnableControlContainer();

// Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications.
COleObjectFactory::RegisterAll();

// TODO: Add your specialized code here

return TRUE;

}



--------------------------------------------------------------------------------

Additional reference words: 4.20 kbdsi CoCreateInstance 0x800401f0
CreateDlgControls Dialog creation failed registered vcbuglist420
Keywords : MfcOLE
Technology : kbMfc; kbole
Version : winnt:4.20
Platform : winnt
Issue type : kbbug
Solution Type : kbnofix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 11, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.


volcary 2002-06-21
  • 打赏
  • 举报
回复
注册路径不能有中文字符(注册信息是写在注册表中的,中文有时是乱码)
look__look 2002-06-21
  • 打赏
  • 举报
回复
msdn上说#import会自动调用coinitialize();
我调用 coinitialize();时返回S_FALSE;
pcwl 2002-06-20
  • 打赏
  • 举报
回复
你COM是用什么篇写的
look__look 2002-06-20
  • 打赏
  • 举报
回复
难道谁都不知道吗!
look__look 2002-06-20
  • 打赏
  • 举报
回复
你们到底知道不知道呀!!
look__look 2002-06-20
  • 打赏
  • 举报
回复
我怎么使用dll里的com???,这是关键!!
jeffchen 2002-06-20
  • 打赏
  • 举报
回复
在msdn上查import有详细的解释
look__look 2002-06-20
  • 打赏
  • 举报
回复
谁给我个例子
look__look 2002-06-20
  • 打赏
  • 举报
回复
有例子吗!!
scliym 2002-06-20
  • 打赏
  • 举报
回复
#import "youcom.dll" no_namespace
jsd198 2002-06-20
  • 打赏
  • 举报
回复
有几种方法,最常用的是用#import导入dll即可
look__look 2002-06-20
  • 打赏
  • 举报
回复
在vc中用cocreateinstance(),产生异常!

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧