惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AWS News Blog
AWS News Blog
T
Tenable Blog
Project Zero
Project Zero
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 热门话题
T
Threat Research - Cisco Blogs
T
Threatpost
Security Latest
Security Latest
C
Cisco Blogs
L
Lohrmann on Cybersecurity
S
Security @ Cisco Blogs
Google Online Security Blog
Google Online Security Blog
NISL@THU
NISL@THU
AI
AI
V
Vulnerabilities – Threatpost
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Last Watchdog
The Last Watchdog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Hacker News: Front Page
U
Unit 42
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MyScale Blog
MyScale Blog
O
OpenAI News
Scott Helme
Scott Helme
V2EX - 技术
V2EX - 技术
P
Proofpoint News Feed
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cyberwarzone
Cyberwarzone
博客园 - 【当耐特】
H
Heimdal Security Blog
S
Schneier on Security
阮一峰的网络日志
阮一峰的网络日志
Help Net Security
Help Net Security
D
DataBreaches.Net
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
TaoSecurity Blog
TaoSecurity Blog
K
Kaspersky official blog
N
News and Events Feed by Topic
WordPress大学
WordPress大学
P
Palo Alto Networks Blog

博客园 - 黄金海岸

sqlite3环境配置-初始篇 linux-vi备查 QT设计之编译 QT设计之Designer H3C交换机配置命令大全 sqlite3小试牛刀 - 黄金海岸 - 博客园 sqlite3环境配置 利用 AXIS开发Webservice(一) —— 如何发布自己的webservice(转) 在Visual C++ 中调用Excel 2000 软件配置管理-团队开发的基石 VC常用数据类型使用转换详解(转载) VC++中使用ADO方式操作ACCESS数据库(转载) 同行评审过程描述(四)——测量 同行评审过程描述(三)——走查步骤 同行评审过程描述(二)——评审步骤 同行评审过程描述(一)——概述(转载) Bugzilla windows安装红宝书(转载) 单元测试 单元测试的基本方法
vb和vc混合编程实例(ocx和dll) (转载)
黄金海岸 · 2007-01-08 · via 博客园 - 黄金海岸

前言:     
   由于以前用vb和vc++封装过dll和ocx文件. 或者在网上下的类;若重新编写和封装会很费时和费力. 如vb简单易用,对数据库操作通用类进行封装.现在vc中可以引用之。另外由于vc执行效率高,某些 较复杂算法或低层处理可在vc中进行封装. 这样经常要求混用.下面是实际中个例子记,分vb6.0,vc++各自创建和调用四个部分

   1: vb能封装ocx和active dll文件. 注意 active dll是一种动态,在被调用环境中不仅引用这个dll,而且还要引用这个dll所引用的其它文件,如 DBCommom.dll 是个数据库操作类封装,它引用了Ado 接口).其创建略,具体引用见后.
   
   2.vc中做dll时注意要提供接口,供其它程式调用.
     a>创建 win32 Dynamic-Link Library 如项目CMyTestDll
     b>加入成员function(在 .h中申明 .cpp中实现)

//取电脑名称
int CMyTestDll::GetComputerNameE(LPTSTR computer_name)
{
   DWORD buf=255;
   LPTSTR strname=new char[buf];
  if(GetComputerName(strname,&buf)!=0)
  {
  strcpy(computer_name,strname);
 return 1;
  }
  return 0;
}
//计算两个值之和
int CMyTestDll::Sum(int a, int b)
{
  return(a+b);
}

   c.>一定要加上CMyTestDll.def 文件 ,并在在其中定义导出各个function及参数,否则不能被调用
     EXPORTS
     GetComputerNameE @1;
     Sum @2; @3;
   d.>编译成dll便可以.最好每个function定义int为返回值.


  3.vb引用vc中dll 和普通API函数一样.(vb的long对应 vc的int)
    '引用
Private Declare Function GetComputerNameE Lib "目录\MyTestDll.dll" (ByVal strName As String) As Long
Private Declare Function Sum Lib "目录\\MyTestDll.dll" (ByVal g As Long, ByVal b As Long) As Long
    '调用
     Dim str As String * 20 ' 注意对于传址,一定要定义其空间大小(数组可以不指定)
     dim a As Long, b As Long
        a=25 b=78
      result = GetComputerNameE(str) 
      result=Sum(a, b)


  4.vc引用vb中ocx和dll
    如 C:\TestVb\DBCommon.dll 是个vb做的数据库通用类。包括对表的操作。
      在vc中要同时引用 DBCommon.dll和msado15.dll
    a>stdafx.h 中加上
       #import "C:\Program Files\Common Files\System\Ado\msado15.dll" no_namespace      rename("EOF","adoEOF")
    #import "E:\backup\Recycled\Study\VB\vb_Report\DBCommon.dll" named_guids(不知道类名用默认,否则用no_namespace 类名) 
     
    b>在调用时先要在App中InitInstance
       //初始化com类
      ::CoInitialize(NULL);

          //用指定命名来定义类型接口指针
          ::DBCommon::_clsDBCommonPtr pdb;
    HRESULT hr=pdb.CreateInstance(DBCommon::CLSID_clsDBCommon); 
   if(FAILED(hr))
   {
                 AfxMessageBox("Active dll error",MB_ICONINFORMATION);
    return false;
   }
 
   pdb->PutDBPath(CurrentMoudlePath); //向类中传入数据库存路径
   pdb->PutDBPwd((_bstr_t)strpwd); //向类中传入数据库存密码
   BSTR bstrNo=_com_util::ConvertStringToBSTR(Mydata->Name.GetBuffer(0));
  // BSTR bstrNo=::SysAllocString(L"Q50001");
     hr=pdb->Qutation_Print_Transe(&bstrNo);//向类中传入报价单号
        
  
   pdb.Detach(); //free memory
 
  若Active dll修改后(可删除ncb文件),要重新编译源程式便可!

   摘自:http://blog.vckbase.com/jim97/