⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 project3.cpp

📁 此程序用于VC调用VB编写的DLL文件
💻 CPP
字号:
//
//此工程用于实验用VC调用VB编写的DLL文件
//
//**************
// project3.cpp
// 程序制作者:PC.Hacker
// QQ:313241942
//**************

#include "stdafx.h"
#include "iostream.h"
#define _WIN32_DCOM
#include "objbase.h"     
#include "stdio.h"
#import "vbtest.dll" no_namespace     //包含DLL文件路径
//DLL文件VB源码
//Public Function deal(Byval strv As String)
//	deal=Len(strv)
//End Function
//
void main()
{
BSTR bstrDesc;
try
{
CoInitialize(NULL);                    //初始化com
CoInitializeEx(0,COINIT_APARTMENTTHREADED);
do
{
char st[20]="tihs is a test";
long st1;
_bstr_t strv;                          //_bstr_t对应vb中的String类型
strv=(_bstr_t)st;
_Class1Ptr ptr;                        //建立一个指向VB DLL中类的指针
ptr.CreateInstance(__uuidof(Class1));  //获得Class1类的句柄
st1 = ptr->deal(strv);                 //调用DLL中的函数deal()
cout<<"字符串长度"<<st1<<"\n";         //输出字符串长度
}while(1);
}
catch(_com_error &e)
{
bstrDesc = e.Description();
}
CoUninitialize();                      //卸载(释放)com
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -