CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  ATL/ActiveX/COM

新手关于ATL.请进.百分相救.

楼主cici2006(以不变应万变)2006-03-03 13:35:31 在 VC/MFC / ATL/ActiveX/COM 提问

我按照VCKBASE里面的这个例子:  
  http://www.vckbase.com/document/viewdoc/?id=211做的,.注册了.  
  按照例子我也做了VC的TEST程序.  
  为什么就不能正常运行呢?  
  程序在CoCreateInstance在这个函数中调用失败.不能进入到IF中.所以就不能调用AddNumbers这个函数了.是为什么呢?请高手相救.谢谢!  
  //   声明HRESULT和Simple_ATL接口指针  
  HRESULT   hr;  
  hr   =   CoInitialize(0);  
  IFirst_ATL   *IFirstATL   =   NULL;  
  //   使用SUCCEEDED   宏并检查我们是否能得到一个接口指针    
  if(SUCCEEDED(hr))  
  {  
  hr   =   CoCreateInstance(   CLSID_First_ATL,   NULL,   CLSCTX_INPROC_SERVER,  
  IID_IFirst_ATL,   (void**)   &IFirstATL);  
  //   如果成功,则调用AddNumbers方法,否则显示相应的出错信息  
  if(SUCCEEDED(hr))  
  {  
  long   ReturnValue   =   0;  
  IFirstATL->AddNumbers(5,   7,   &ReturnValue);  
  std::cout   <<   "The   answer   for   5   +   7   is:   "   <<   ReturnValue   <<   std::endl;  
  IFirstATL->Release();    
  }  
  else  
  {  
  std::cout   <<   "CoCreateInstance   Failed."   <<   std::endl;  
  }  
  }  
  //   释放COM  
  CoUninitialize(); 问题点数:100、回复次数:15Top

1 楼cici2006(以不变应万变)回复于 2006-03-03 13:58:07 得分 0

大哥们都到哪里去了呢?Top

2 楼striking(庸人自扰)回复于 2006-03-03 14:40:47 得分 10

#include   "..\SImple_ATL\Simple_ATL_i.c"  
   
  instead   of   the   following  
  /*   const   IID   IID_IFirst_ATL   =    
  {0xC8F6E230,0x2672,0x11D3,{0xA8,0xA8,0x00,0x10,0x5A,0xA9,0x43,0xDF}};  
   
  const   CLSID   CLSID_First_ATL   =    
  {0x970599E0,0x2673,0x11D3,{0xA8,0xA8,0x00,0x10,0x5A,0xA9,0x43,0xDF}};  
  */  
   
  Top

3 楼cici2006(以不变应万变)回复于 2006-03-03 15:03:16 得分 0

楼上大哥,我这没有加入.是加了.c这个文件.  
  还是不行.  
  我用VC   Active   control   test   这个工具,看不到我的这个ATL已经在里面呀.  
  但是我用regsvr32这个已经注册了这个DLL了呀.Top

4 楼lein2101()回复于 2006-03-03 15:11:40 得分 0

你调用CoCreateInstance的返回值是什么?DEBUG看一下。Top

5 楼striking(庸人自扰)回复于 2006-03-03 15:20:58 得分 0

Add   the   next   line   to   your   stdafx.h,  
   
  #import    
  "..\Simple_ATL\Debug\Simple_ATL.DLL"   no_namespace  
   
  //   Simple_ATL_test.cpp   :   Defines   the   entry   point   for   the   console   application.  
  //  
   
  #include   "stdafx.h"  
  #include   <iostream>  
   
  using   namespace   std;  
   
  int   main(int   argc,   char*   argv[])  
  {  
  ::CoInitialize(NULL);  
   
  cout   <<   "Creating   COM   object..."   <<   endl;  
   
  IFirst_ATLPtr   first;                 //   <----   This   is   the   automagicly   made   smartpointer   type.  
                                                                            //   Its   your   interface   name   with   "Ptr"   on   the   end  
  HRESULT   hr;  
   
  long   result;  
   
                    //   This   is   really   cool,   we   use   a   dot   to   get   to   the   smart   pointer   methods  
                    //   And   once   an   instance   is   created,   we   use   ->   to   get   to   the   instance  
                    //   methods.     Some   really   funky   operator   overloading.  
  hr   =   first.CreateInstance(__uuidof(First_ATL));  
   
  if   (SUCCEEDED(hr))  
  {  
  first->AddNumbers(   5L,   7L,   &result   );  
   
  cout   <<   "The   result   is   "   <<   result   <<   endl;  
  }  
  else  
  {  
  cout   <<   "Oh   buggar."   <<   endl;  
  }  
   
  first   =   NULL; //   Release   the   object  
  //   I   this   is   very   much   like   doing  
  //   set   first   =   nothing  
  //   in   VB.     Importaint   to   do   before   the   next   statment...  
   
  ::CoUninitialize();  
   
  return   0;  
  }Top

6 楼cici2006(以不变应万变)回复于 2006-03-03 15:33:54 得分 0

楼上楼上.DEBUG..返回是一个很大的负数  
  楼上:  
  我加上  
  #import    
  "..\Simple_ATL\Debug\Simple_ATL.DLL"   no_namespace  
  这句话就显示两个错误  
  f:\vc示例\test\findatl\testatl\debug\findatl.tlh(17)   :   warning   C4099:   Simple_ATL:   type   name   first   seen   using   'class'   now   seen   using   'struct'  
                  f:\vc示例\test\findatl\findatl.h(50)   :   see   declaration   of   Simple_ATL  
  f:\vc示例\test\findatl\testatl\debug\findatl.tlh(32)   :   warning   C4099:   'Simple_ATL'   :   type   name   first   seen   using   'class'   now   seen   using   'struct'  
                  f:\vc示例\test\findatl\findatl.h(50)   :   see   declaration   of   'Simple_ATL'  
  f:\vc示例\test\findatl\testatl\debug\findatl.tlh(36)   :   error   C2011:   'INoWindow'   :   'struct'   type   redefinition  
  f:\vc示例\test\findatl\testatl\debug\findatl.tli(15)   :   error   C2065:   'raw_AddNumbers'   :   undeclared   identifierTop

7 楼cici2006(以不变应万变)回复于 2006-03-03 15:38:20 得分 0

ATL应该是不需要导入  
  #import    
  "..\Simple_ATL\Debug\Simple_ATL.DLL"   no_namespace  
  这个DLL吧.  
  像一般软件做的ATL的控件,根本就不需要得到这个路径的DLL呀.  
  直接用接口就行了呀.  
  不晓得我这个问题是怎么回事.是不是没有注册上呢?Top

8 楼lein2101()回复于 2006-03-03 15:49:39 得分 0

既然你得到了返回值,就用VC带的Error   Lookup查一下看有没有这个值Top

9 楼cici2006(以不变应万变)回复于 2006-03-03 15:56:02 得分 0

楼上:  
  值是:0x8007007E   找不到指定的模块。    
  是不是我这个没有注册上还是怎么呢?  
  望回复.Top

10 楼lein2101()回复于 2006-03-03 16:04:37 得分 90

看起来是注册的问题,你到注册表里查一下,看看对应的COM路径是不是正确。Top

11 楼cici2006(以不变应万变)回复于 2006-03-03 16:19:21 得分 0

楼上。你能告诉我怎么查吗?  
  注册表里面怎么样查找呢?  
  谢谢了。Top

12 楼lein2101()回复于 2006-03-03 16:30:16 得分 0

这个不难,就是到注册表的HKEY_CLASS_ROOT下找,你知道你的COM的CLISD值吧(不知道看一下工程里的.rgs文件),用这个值来找,找到后看一下InprocServer32里的路径Top

13 楼cici2006(以不变应万变)回复于 2006-03-03 16:36:42 得分 0

有这个值。  
  显示地址的  
  F:\vc示纠例齖\Test\FindATL\RELEAS~1\FindATL.DLL  
  变成了这样。是不是不对呢?Top

14 楼lein2101()回复于 2006-03-03 16:41:09 得分 0

你用这个地址注册一下看看。Top

15 楼cici2006(以不变应万变)回复于 2006-03-03 16:42:48 得分 0

楼主。我改了个英文名字就可以了。谢谢。  
  分都给你了。:)  
  你能告诉我你的QQ或者MSN或者EMAIL吗?  
  以后可能还有需要请教的呢。不过,放心我不会烦你的。哈哈  
  真的谢谢了。Top

相关问题

  • 一百分相送,求救!!!!
  • 百分求救!!!!
  • ##########百分求救!!!###############
  • 百分求救
  • 救命啊,一百分相送
  • 求救,CRC16的代码,百分相赠!!!
  • 百分求救!急!
  • 关于使用一个ATL控件的一个问题,百分相送!!!
  • 〓☆救我一命!百分相送!高手请进!☆〓
  • 谁能救我?WIN2K启动出了大问题!!百分相送!!!

关键词

  • atl
  • hr
  • null
  • ifirstatl
  • addnumbers
  • 调用
  • succeeded
  • cout
  • std
  • 不能

得分解答快速导航

  • 帖主:cici2006
  • striking
  • lein2101

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo