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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
S
Securelist
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
腾讯CDC
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
量子位
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Cyberwarzone
Cyberwarzone
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
T
Tenable Blog
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
N
News | PayPal Newsroom
P
Proofpoint News Feed
O
OpenAI News
C
CERT Recently Published Vulnerability Notes
B
Blog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy

博客园 - 黄金海岸

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/