请问在VC中调用VB写的dll该如何调用呢?

Lzh_lee 2002-06-27 01:05:36
如提。因一控件只能在VB里用。
...全文
38 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lzh_lee 2002-06-27
  • 打赏
  • 举报
回复
没办法下的办法了,因为必须要用到一个控件,但那控件只能在VB中用,但程序却又要用VC写,嘻嘻,是不是很复杂,见丑了。
nicolas 2002-06-27
  • 打赏
  • 举报
回复
呵呵,我一般是反过来做:VB调用VC写的dll.
Lzh_lee 2002-06-27
  • 打赏
  • 举报
回复
不好意思,自己摆了一个乌龙,我在一个目录里编译了那个dll,然后在那个目录注册了,再把那个dll拷到vc源程所在目录。谢谢你,kingzai()
Lzh_lee 2002-06-27
  • 打赏
  • 举报
回复
是的,我的DLL中封装了在VC中不可用的控件。我用了kingzai()的方法,hr的返回为空。给位能帮我看看吗?或者另指点迷津
#import "reportdll.dll" no_namespace named_guids

HRESULT hr;
_ReportPrinter *reporter;
hr = CoInitialize(0);
if(SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_ReportPrinter,NULL, CLSCTX_INPROC_SERVER,IID__ReportPrinter, (void**) &reporter);

if(SUCCEEDED(hr))
{

AfxMessageBox("ok1");
}
else
{
AfxMessageBox("lost");
}
}
stzhou 2002-06-27
  • 打赏
  • 举报
回复
我不太懂VB,你所说得DLL是封装了控件的形式吗?如果是,用#import就可以了。如果是纯粹的API,可以采用动态连接的方式。
kingzai 2002-06-27
  • 打赏
  • 举报
回复
//in my example,VB component is activex.it have a method
//CountStringLength
#include <iostream.h>
#include <comdef.h>
#include "vbTestCOM.h"

void main()
{
// Declare an HRESULT and a pointer to the clsVBTestClass interface
HRESULT hr;
_clsVBTestClass *IVBTestClass;

// Now we will intilize COM
hr = CoInitialize(0);

// Use the SUCCEEDED macro and see if we can get a pointer
// to the interface
if(SUCCEEDED(hr))
{
hr = CoCreateInstance( CLSID_clsVBTestClass,
NULL, CLSCTX_INPROC_SERVER,
IID__clsVBTestClass,
(void**) &IVBTestClass);

// If we succeeded then call the CountStringLength method,
// if it failed then display an appropriate message to the user.
if(SUCCEEDED(hr))
{
long ReturnValue;
_bstr_t bstrValue("Hello World");

hr = IVBTestClass->CountStringLength(bstrValue, &ReturnValue);
cout << "The string is: " << ReturnValue << " characters in length." << endl;
hr = IVBTestClass->Release();
}
else
{
// Something went wrong
cout << "CoCreateInstance Failed." << endl;
}
}
// Uninitialize COM
CoUninitialize();
}
hu_sunsky 2002-06-27
  • 打赏
  • 举报
回复
kingzai大侠能不能说得具体一点,对智能指针我不是很熟,谢谢
Lzh_lee 2002-06-27
  • 打赏
  • 举报
回复
kingzai(),能不能给个实例呢,我#import进去以后就不知道该怎么做了,根本不知道该怎样定义那个类。比如我定义的DLL名为reportdll.dll,提供了一个类reportprinter,这个类包含了两个方法,一个是GetStr(str1 as string,str2 as string),另一个是print()。现在我想在VC程序中调用这两个方法。
kingzai 2002-06-27
  • 打赏
  • 举报
回复
1.使用#import产生智能指针,再使用。
2.用CLASSWIZARD导入DLL、TLB等文件。直接产生自动化类
Lzh_lee 2002-06-27
  • 打赏
  • 举报
回复
怎么不能up的?

16,471

社区成员

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

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

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