首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

关于vb建立标准DLL的有关问题

2012-03-16 
关于vb建立标准DLL的问题想用vb做一个标准的DLL供JAVA来调用,但是在用vb来测试这个DLLD时出错,思路如下,请

关于vb建立标准DLL的问题
想用vb做一个标准的DLL供JAVA来调用,但是在用vb来测试这个DLLD时出错,思路如下,请高手指点:

一、在vb中建立一个activex dll,再新建空模块module1和类模块class1,class1中代码如下:

Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Const MAX_LEN = 200 '字符串最大长度
Const DESKTOP = &H0& '桌面
Const PROGRAMS = &H2& '程序集
Const MYDOCUMENTS = &H5& '我的文档
Const MYFAVORITES = &H6& '收藏夹
Const STARTUP = &H7& '启动
Const RECENT = &H8& '最近打开的文件
Const SENDTO = &H9& '发送
Const STARTMENU = &HB& '开始菜单
Const NETHOOD = &H13& '网上邻居
Const FONTS = &H14& '字体
Const SHELLNEW = &H15& 'ShellNew
Const APPDATA = &H1A& 'Application Data
Const PRINTHOOD = &H1B& 'PrintHood
Const PAGETMP = &H20& '网页临时文件
Const COOKIES = &H21& 'Cookies目录
Const HISTORY = &H22& '历史


Public Function getpath(ByVal mycom As String) As String
Dim sTmp As String * MAX_LEN '存放结果的固定长度的字符串
Dim nLength As Long '字符串的实际长度
Dim pidl As Long '某特殊目录在特殊目录列表中的位置

Select Case mycom

Case "windows"
'*************************获得Windows目录**********************************
length = GetWindowsDirectory(sTmp, MAX_LEN)
getpath = Left(sTmp, length)


Case "system"
'*************************获得System目录***********************************
length = GetSystemDirectory(sTmp, MAX_LEN)
getpath = Left(sTmp, length)


Case "temp"
'*************************获得Temp目录***********************************
length = GetTempPath(MAX_LEN, sTmp)
getpath = Left(sTmp, length)


Case "desktop"
'*************************获得DeskTop目录**********************************
SHGetSpecialFolderLocation 0, DESKTOP, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "sendto"
'*************************获得发送到目录**********************************
SHGetSpecialFolderLocation 0, SENDTO, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "mydocuments"
'*************************获得我的文档目录*********************************
SHGetSpecialFolderLocation 0, MYDOCUMENTS, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "programs"
'*************************获得程序集目录***********************************
SHGetSpecialFolderLocation 0, PROGRAMS, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "startup"
'*************************获得启动目录*************************************
SHGetSpecialFolderLocation 0, STARTUP, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "startmenu"
'*************************获得开始菜单目录*********************************
SHGetSpecialFolderLocation 0, STARTMENU, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "favorites"
'*************************获得收藏夹目录***********************************


SHGetSpecialFolderLocation 0, MYFAVORITES, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "recent"
'**********************获得最后打开的文件目录*******************************
SHGetSpecialFolderLocation 0, RECENT, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "nethood"
'*************************获得网上邻居目录*********************************
SHGetSpecialFolderLocation 0, NETHOOD, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "fonts"
'*************************获得字体目录**********************************
SHGetSpecialFolderLocation 0, FONTS, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "cookies"
'*************************获得Cookies目录**********************************
SHGetSpecialFolderLocation 0, COOKIES, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "history"
'*************************获得历史目录**********************************
SHGetSpecialFolderLocation 0, HISTORY, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "pagetmp"
'***********************获得网页临时文件目录*******************************
SHGetSpecialFolderLocation 0, PAGETMP, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "shellnew"
'*************************获得ShellNew目录*********************************
SHGetSpecialFolderLocation 0, SHELLNEW, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "appdata"
'***********************获得Application Data目录*****************************
SHGetSpecialFolderLocation 0, APPDATA, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)


Case "printhood"
'*************************获得PrintHood目录*********************************
SHGetSpecialFolderLocation 0, PRINTHOOD, pidl
SHGetPathFromIDList pidl, sTmp
getpath = Left(sTmp, InStr(sTmp, Chr(0)) - 1)

Case Else
getpath = "没有该目录"

End Select


End Function



Public Function getlinkpath(ByVal filename As String) As String

 Dim Obj As Object
 Set Obj = CreateObject("WScript.Shell")
 Dim Shortcut As Object
 Set Shortcut = Obj.CreateShortcut(filename)
 getlinkpath = Shortcut.TargetPath
 Shortcut.Save

End Function


二、通过网上的中断生成dll的方法,在编译生成DLL过程中获得class1.obj,getpath.obj,module1.obj三个文件。复制到c:\aaa目录下,我的vb装在c盘默认目录下。

三、用批处理手工编译生成DLL文件。vb原始自带的连接程序为link.exe,批处理by.bat内容如下:
cd C:\Program Files\Microsoft Visual Studio\VB98
link.exe "c:\aaa\Class1.obj" "c:\aaa\Module1.obj" "c:\aaa\getpath.obj" "c:\Program Files\Microsoft Visual Studio\VB98\VBAEXE6.LIB " /ENTRY:__vbaS /EXPORT:getpath /EXPORT:getlinkpath /OUT:"c:\aaa\getpathok.dll" /BASE:0x11000000 /SUBSYSTEM:WINDOWS,4.0 /VERS 

四、成功在c:\aaa\下生成getpathok.dll,在vb中新建EXE工程,一个窗体form1;窗体上两个文本框text1,text2;两个按钮command1,command2;代码如下:

Option Explicit
Private Declare Function getpath Lib "getpathok.dll" (ByVal mycom As String) As String
Private Declare Function getlinkpath Lib "getpathok.dll" (ByVal filename As String) As String

Private Sub Command1_Click()
  'MsgBox getpath(trim(text1.text))
  MsgBox getpath("sendto")
End Sub

Private Sub Command2_Click()
  MsgBox getlinkpath("a.lnk")
End Sub

五、把第四步建立的工程生成test.EXE文件,放到c:\aaa目录下,再拷贝IE快捷方式a.lnk到c:\aaa目录下,运行test.exe。text.exe出错自动关闭。注册getpathok.dll文件时提示失败,返回代码0xc0000005。



个人觉得应该是class1中代码有问题,因为用网上的实例(class1中代码为空,module1中有两个简单的函数,注册DLL时也提示失败,返回代码一样,但是在vb中调用时可以成功通过)恳请高手指点。

[解决办法]
activex dll不是标准的DLL,做标准的还是用C吧,VB做不了
[解决办法]

探讨
activex dll不是标准的DLL,做标准的还是用C吧,VB做不了

[解决办法]
探讨

activex dll不是标准的DLL,做标准的还是用C吧,VB做不了

[解决办法]
vb不直接支持做一个标准的DLL
[解决办法]
用VC++
[解决办法]
http://download.csdn.net/source/3261993 上传上去了 嘿嘿
[解决办法]
amicForVB
vb6的一个插件支持导出函数与入口(dllmain)设置
菜单->工程->属性->扩展
挺方便的.

热点排行