谁能教教我VB6怎么编写DLL,并且调用运行

谁能教教我VB6怎么编写DLL,并且调用运行,第1张

在vb中制作dll文件及在vb程序中引用此文件

一、在vb中制作dll文件

(1)新建一个Active DLL工程,名字为vbTestdll,类模块的名字为testdll

(2)在类模块中实现一个函数,内容如下:

Public Function mydll() As String

mydll = "Hello World"

End Function

(3)保存,然后在文件菜单中选择 Make vbtestdll.dll项,生成dll文件

二、在vb程序中使用此dll文件

(1)新建一个标准工程。

(2)在工程-引用-浏览里找到vbtestdll.dll文件,并且把它引入

(3)写测试代码,内容如下

Option Explicit

Dim test As testdll'类模块名字

Private Sub Form_Load()

Set test= New testdll 'DLL的一个新实例

Me.Caption = test.mydll '我的标题=返回DLL的Hello World

End Sub

//例子:

//Cpp文件

#define DLL1_API extern "C" _declspec(dllexport)

#include "Dll1.h"

#include <Windows.h>

#include <stdio.h>

int _stdcall add(int a,int b)

{

return a+b

}

int _stdcall subtract(int a,int b)

{

return a-b

}

//h文件

#ifdef DLL1_API

#else

#define DLL1_API extern "C" _declspec(dllimport)

#endif

DLL1_API int _stdcall add(int a,int b)

DLL1_API int _stdcall subtract(int a,int b)

//其他有什么问题欢迎在线和我交流

都有相同的父类:PersonClass

public void DoWork()

{

Assembly a =Assembly.Load("PersonClass")

Type[] types = a.GetTypes()

foreach (Type type in types)

{

MyLog.Info(type.Name)

PersonClass obj = (PersonClass)Activator.CreateInstance(type)

obj.Name= “xxx”

obj.SayHi()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11695410.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存