如何在VB中调用VC制作的DLL,并传递自定义的结构数组??

zhaiyl 2003-12-29 05:55:51
请写一下生命和调用的方法,小弟第一次使用VB.实在是不清楚。
...全文
56 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
道素 2003-12-30
  • 打赏
  • 举报
回复
vc++6.0 vb6.0
winnt pwin95
我在VC++6.0中编写DLL程序,自定义类型如下:struct config
{
unsigned short int intermit;
unsigned short int address;
} card_config;


函数:extern "C" struct config __stdcall cardconfig(unsigned int intermit,unsigned int address)

{
intermit=3000;
card_config.intermit =intermit;
card_config.address =address;
return card_config;
}
另外,要在.def文件中加上:
EXPORTS
cardconfig @1

在vb6.0调用:
在模块中定义:
Type config
intermit As Integer
address As Integer
End Type

Declare Function cardconfig Lib "c:\hjm\adcard\debug\adcard.dll" (ByVal intermit As Integer, ByVal address As Integer) As config
在程序中如下写:
Dim c As config
intermit = 100
address = 200
c=cardconfig(intermit,address)
道素 2003-12-30
  • 打赏
  • 举报
回复
对不起,是我太马虎了,没有看你的标题,只看了正文
你如果用过api就应该接触过这个,举个例子(显示浏览文件对话框,传入结构):
Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Const BIF_RETURNONLYFSDIRS = 1
Const MAX_PATH = 260
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Sub Form_Load()
Dim iNull As Integer, lpIDList As Long, lResult As Long
Dim sPath As String, udtBI As BrowseInfo

With udtBI
'Set the owner window
.hWndOwner = Me.hWnd
'lstrcat appends the two strings and returns the memory address
.lpszTitle = lstrcat("C:\", "")
'Return only if the user selected a directory
.ulFlags = BIF_RETURNONLYFSDIRS
End With

lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If

MsgBox sPath
End Sub
道素 2003-12-29
  • 打赏
  • 举报
回复
function有返回值,sub没有
道素 2003-12-29
  • 打赏
  • 举报
回复
Option Explicit

Private Sub Command1_Click()
Dim iLength As Long
subTest "sub Test"
iLength = FuncTest("function Test")


End Sub

Private Sub subTest(s As String)
MsgBox s
End Sub
Private Function FuncTest(s As String) As Long
MsgBox s
FuncTest = Len(s)
End Function
zhaiyl 2003-12-29
  • 打赏
  • 举报
回复
大家帮忙啊

马上就可以结分

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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