CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

还是VB调用VC的DLL问题

楼主progame(www.progame.org)2002-04-10 12:33:08 在 VB / 基础类 提问

EXE工程调用可以  
   
  但我现在是在我VB的DLL中使用别人已经写好的(我无法更改了,因为没源代码)的DLL  
   
  使用绝对路径声明可以,否则  
   
  Private   Declare   Function   DllName   Lib   "dllxxx.dll"   (ByVal....  
   
  这样就说无法找到文件,但我的DLL是要发布的,所以只能是相对路径  
   
  我现在已经将VC的这个DLL拷贝到我的工程路径下,为什么还是找不到  
   
  请问有什么办法? 问题点数:200、回复次数:25Top

1 楼ltpao(啊炮)回复于 2002-04-10 12:37:35 得分 20

拷到系统目录下Top

2 楼progame(www.progame.org)回复于 2002-04-10 12:39:18 得分 0

难道只能如此吗?Top

3 楼tanaya(唐博士http://blog.csdn.net/tanaya)回复于 2002-04-10 12:39:43 得分 10

在程序中使用:   LoadLibrary    
   
  Private   Declare   Function   LoadLibrary   Lib   "kernel32"   Alias   "LoadLibraryA"   (ByVal   lpLibFileName   As   String)   As   Long  
   
  动态调用Dll即可Top

4 楼Pipi0714(老顽童)回复于 2002-04-10 12:41:16 得分 10

注意:你的程序并没有错误,而是你启动你程序的时候一定是:先启动vb,然后打开或者...的方法启动的。这样不可以,就会出现你遇到的问题你只要进入的工程文件所在的文件夹启动你的工程才好用Top

5 楼wjying(葡萄)回复于 2002-04-10 12:44:30 得分 0

动态调用应该可以Top

6 楼progame(www.progame.org)回复于 2002-04-10 12:47:37 得分 0

我开始是使用工程组进行调试的,因为是做DLL  
   
  然后我也想是不是:   pipi0714(皮皮0714)   所说的问题  
   
  于是我直接进DLL的工程,然后编译  
   
  再使用测试的工程去调用DLL,结果也是出错Top

7 楼progame(www.progame.org)回复于 2002-04-10 12:48:32 得分 0

tanaya(蜡笔小新)   :  
   
  Private   Declare   Function   LoadLibrary   Lib   "kernel32"   Alias   "LoadLibraryA"   (ByVal   lpLibFileName   As   String)   As   Long  
     
  里面的lib后面和alias后面怎么写啊:(  
   
  我根本不知道那个DLL的Alias是什么的Top

8 楼progame(www.progame.org)回复于 2002-04-10 12:55:52 得分 0

U+pTop

9 楼foolflyfish(I am progame.)回复于 2002-04-10 13:03:39 得分 0

U~pTop

10 楼NowCan(城市浪人)回复于 2002-04-10 13:06:04 得分 10

VB的IDE环境里运行是达不到你要的效果的。  
  需要编译程exe文件再试。Top

11 楼wenw(阿文)回复于 2002-04-10 13:08:44 得分 10

放到程序目录下会经常出现找不到的错误,最好是放到系统目录下。  
  我编写的一个读硬盘物理序列号的程序就是这样的。Top

12 楼progame(www.progame.org)回复于 2002-04-10 13:17:51 得分 0

NowCan(能量、激情、雨水、彩虹——雷雨云):  
   
  我两边都编译了(DLL和测试exe),还是不行Top

13 楼progame(www.progame.org)回复于 2002-04-10 13:39:49 得分 0

快沉了要,U~p一下,把它打捞起来!Top

14 楼gump2000(阿甘)回复于 2002-04-10 13:43:58 得分 30

给你个例子看看  
   
  'code   submitted   by   Daniel   Kaufmann   (daniel@i.com.uy)  
  'In   a   form:  
  Private   Sub   Form_Load()  
          Dim   vFileName   As   String,   vHandle   As   Long  
          Me.AutoRedraw   =   True  
          vFileName   =   "C:\Windows\System\kernel32.dll"  
          'vFileName   =   "C:\Windows\Explorer.exe"  
          vHandle   =   LoadLibraryEx(vFileName,   0,   LOAD_LIBRARY_AS_DATAFILE)  
          If   vHandle   =   0   Then  
                  Print   "Invalid   library"  
                  Exit   Sub  
          End   If  
          Dim   i   As   resType  
          Set   f   =   Me  
          For   i   =   RT_FIRST   To   RT_LAST  
                  Print   "Tipo:   ";   i,  
                  EnumResourceNames   vHandle,   i,   AddressOf   EnumResNameProc,   0  
                  Print  
          Next  
          FreeLibrary   vHandle  
  End   Sub  
  'In   a   module:  
  Public   f   As   Form  
  Public   Declare   Function   LoadLibraryEx   Lib   "kernel32"   Alias   "LoadLibraryExA"   (ByVal   lpLibFileName   As   String,   ByVal   hFile   As   Long,   ByVal   dwFlags   As   Long)   As   Long  
  Public   Const   LOAD_LIBRARY_AS_DATAFILE   =   &H2  
  Public   Declare   Function   FreeLibrary   Lib   "kernel32"   (ByVal   hLibModule   As   Long)   As   Long  
  Public   Declare   Function   EnumResourceNames   Lib   "kernel32"   Alias   "EnumResourceNamesA"   (ByVal   HModule   As   Long,   ByVal   lpType   As   resType,   ByVal   lpEnumFunc   As   Long,   ByVal   lParam   As   Long)   As   Long  
  'String   management  
  Public   Declare   Function   StrLen   Lib   "kernel32"   Alias   "lstrlenA"   (ByVal   lpString   As   Long)   As   Long  
  Public   Declare   Function   StrCpy   Lib   "kernel32"   Alias   "lstrcpyA"   (ByVal   lpString1   As   String,   ByVal   lpString2   As   Long)   As   Long  
  Private   Const   DIFFERENCE   =   11  
  Public   Enum   resType   'Types   of   resources  
          RT_FIRST   =   1&  
          RT_CURSOR   =   1&  
          RT_BITMAP   =   2&  
          RT_ICON   =   3&  
          RT_MENU   =   4&  
          RT_DIALOG   =   5&  
          RT_STRING   =   6&  
          RT_FONTDIR   =   7&  
          RT_FONT   =   8&  
          RT_ACCELERATOR   =   9&  
          RT_RCDATA   =   10&  
          RT_MESSAGETABLE   =   (11)  
          RT_GROUP_CURSOR   =   (RT_CURSOR   +   DIFFERENCE)  
          RT_GROUP_ICON   =   (RT_ICON   +   DIFFERENCE)  
          RT_VERSION   =   (16)  
          'RT_DLGINCLUDE   =   (17)  
          'RT_PLUGPLAY   =   (19)  
          'RT_VXD   =   (20)  
          'RT_ANICURSOR   =   (21)  
          'RT_ANIICON   =   (22)  
          'RT_HTML   =   (23)  
          RT_LAST   =   (16)  
  End   Enum  
  Public   Function   EnumResNameProc(ByVal   HModule   As   Long,   ByVal   lpszType   As   resType,   ByVal   lpszName   As   Long,   ByVal   lParam   As   Long)   As   Long  
          Dim   Nombre   As   String,   IsNum   As   Boolean  
          If   (lpszName   >   &HFFFF&)   Or   (lpszName   <   0)   Then  
                  Nombre   =   PtrToVBString(lpszName)  
                  IsNum   =   False  
          Else  
                  Nombre   =   CStr(lpszName)  
                  IsNum   =   True  
          End   If  
          If   IsNum   Then  
                  f.Print   Nombre   +   "   ";  
          Else  
                  f.Print   """"   +   Nombre   +   """   ";  
          End   If  
          EnumResNameProc   =   1  
  End   Function  
  Private   Function   PtrToVBString(ByVal   lpszBuffer   As   Long)   As   String  
          Dim   Buffer   As   String,   LenBuffer   As   Long  
          LenBuffer   =   StrLen(lpszBuffer)  
          Buffer   =   String(LenBuffer   +   1,   0)  
          StrCpy   Buffer,   lpszBuffer  
          PtrToVBString   =   Left(Buffer,   LenBuffer)  
  End   Function  
  Top

15 楼gump2000(阿甘)回复于 2002-04-10 13:44:34 得分 0

Create   a   new   project   and   add   this   code   to   Form1  
  Private   Declare   Function   FreeLibrary   Lib   "kernel32"   (ByVal   hLibModule   As   Long)   As   Long  
  Private   Declare   Function   LoadLibrary   Lib   "kernel32"   Alias   "LoadLibraryA"   (ByVal   lpLibFileName   As   String)   As   Long  
  Private   Declare   Function   GetProcAddress   Lib   "kernel32"   (ByVal   hModule   As   Long,   ByVal   lpProcName   As   String)   As   Long  
  Private   Declare   Function   CallWindowProc   Lib   "user32"   Alias   "CallWindowProcA"   (ByVal   lpPrevWndFunc   As   Long,   ByVal   hWnd   As   Long,   ByVal   Msg   As   Any,   ByVal   wParam   As   Any,   ByVal   lParam   As   Any)   As   Long  
  Private   Sub   Form_Load()  
          On   Error   Resume   Next  
          'KPD-Team   1999  
          'URL:   http://www.allapi.net/  
          'E-Mail:   KPDTeam@Allapi.net  
          'We're   going   to   call   an   API-function,   without   declaring   it!  
          Dim   lb   As   Long,   pa   As   Long  
          'map   'user32'   into   the   address   space   of   the   calling   process.  
          lb   =   LoadLibrary("user32")  
          'retrieve   the   address   of   'SetWindowTextA'  
          pa   =   GetProcAddress(lb,   "SetWindowTextA")  
          'Call   the   SetWindowTextA-function  
          CallWindowProc   pa,   Me.hWnd,   "Hello   !",   ByVal   0&,   ByVal   0&  
          'unmap   the   library's   address  
          FreeLibrary   lb  
  End   Sub  
  Top

16 楼wjying(葡萄)回复于 2002-04-10 13:45:13 得分 10

你把所有的dll和可执行文件放在一起试试Top

17 楼gump2000(阿甘)回复于 2002-04-10 13:45:15 得分 0

再来一个  
   
  '   Add   2   Commandbuttons   and   a   textbox   to   the   form,   and   paste   this   code   into   the   form  
  Option   Explicit  
   
  Private   Declare   Function   FreeLibrary   Lib   "kernel32"   (ByVal   hLibModule   As   Long)   As   Long  
  Private   Declare   Function   LoadLibrary   Lib   "kernel32"   Alias   "LoadLibraryA"   (ByVal   lpLibFileName   As   String)   As   Long  
  Private   Declare   Function   GetProcAddress   Lib   "kernel32"   (ByVal   hModule   As   Long,   ByVal   lpProcName   As   String)   As   Long  
  Private   Declare   Function   CallWindowProc   Lib   "user32"   Alias   "CallWindowProcA"   (ByVal   lpPrevWndFunc   As   Long,   ByVal   hWnd   As   Long,   ByVal   Msg   As   Any,   ByVal   wParam   As   Any,   ByVal   lParam   As   Any)   As   Long  
  Private   Const   ERROR_SUCCESS   =   &H0  
   
  Private   Sub   Form_Load()  
          Text1.Text   =   "C:\WINDOWS\SYSTEM\COMCTL32.OCX"  
          Command1.Caption   =   "Register   server"  
          Command2.Caption   =   "Unregister   server"  
  End   Sub  
   
  Private   Sub   Command1_Click()  
          Call   RegisterServer(Me.hWnd,   Text1.Text,   True)  
  End   Sub  
   
  Private   Sub   Command2_Click()  
          Call   RegisterServer(Me.hWnd,   Text1.Text,   False)  
  End   Sub  
   
  Public   Function   RegisterServer(hWnd   As   Long,   DllServerPath   As   String,   bRegister   As   Boolean)  
          On   Error   Resume   Next  
   
          'KPD-Team   2000  
          'URL:   http://www.allapi.net/  
          'E-Mail:   KPDTeam@Allapi.net  
          'We're   going   to   call   an   API-function,   without   declaring   it!  
   
          '   Modified   by   G.   Kleijer  
          '   gkleijer@casema.net  
          '   going   to   call   the   DllRegisterServer/DllUnRegisterServer   API   of   the   specified   library.  
          '   there's   no   need   to   use   the   Regsvr32.exe   anymore.  
   
          '   Make   sure   the   path   is   correct   and   that   the   file   exists,   otherwise   VB   will   crash.  
   
          Dim   lb   As   Long,   pa   As   Long  
          lb   =   LoadLibrary(DllServerPath)  
   
          If   bRegister   Then  
                  pa   =   GetProcAddress(lb,   "DllRegisterServer")  
          Else  
                  pa   =   GetProcAddress(lb,   "DllUnregisterServer")  
          End   If  
   
          If   CallWindowProc(pa,   hWnd,   ByVal   0&,   ByVal   0&,   ByVal   0&)   =   ERROR_SUCCESS   Then  
                  MsgBox   IIf(bRegister   =   True,   "Registration",   "Unregistration")   +   "   Successful"  
        Else  
                  MsgBox   IIf(bRegister   =   True,   "Registration",   "Unregistration")   +   "   Unsuccessful"  
          End   If  
          'unmap   the   library's   address  
          FreeLibrary   lb  
  End   Function  
  Top

18 楼SnHnBn(大可达)回复于 2002-04-10 13:48:19 得分 0

编译成Exe,然后直接运行Exe,不能在IDE中运行!  
  Top

19 楼load(不是东西)回复于 2002-04-10 13:50:02 得分 100

按wjying(葡萄)   说的,然后加一句:  
   
  chdir   app.pathTop

20 楼SnHnBn(大可达)回复于 2002-04-10 13:50:43 得分 0

编译成Exe后,直接运行EXE文件,不能在IDE环境中运行。Top

21 楼progame(www.progame.org)回复于 2002-04-10 13:51:56 得分 0

wjying(葡萄):全部放一起可以了  
   
  但是一般来说exe不太可能和dll放一起的  
   
  要么是系统目录,要么是某个子文件夹下面  
   
  gump2000(阿甘)   :这个代码我不太看得懂的Top

22 楼gump2000(阿甘)回复于 2002-04-10 13:52:15 得分 0

编译成EXE测试是最好  
  应该可以的,我一直这样用的Top

23 楼progame(www.progame.org)回复于 2002-04-10 13:54:09 得分 0

wjying(葡萄):全部放一起可以了  
   
  但是一般来说exe不太可能和dll放一起的  
   
  要么是系统目录,要么是某个子文件夹下面  
   
  gump2000(阿甘)   :这个代码我不太看得懂的Top

24 楼progame(www.progame.org)回复于 2002-04-10 13:57:23 得分 0

cool,加入chdir   app.path  
   
  thanks,加分了Top

25 楼gump2000(阿甘)回复于 2002-04-10 13:59:14 得分 0

就是动态注册OCX啊,等等东西了Top

26 楼smart_monkey(爱华)回复于 2002-04-15 16:52:24 得分 0

我也有同样的问题,请告诉我你的信箱或详细的解决办法。Top

27 楼progame(www.progame.org)回复于 2002-04-17 16:09:20 得分 0

dim   str     as   string  
  str=curdir  
   
  chdir   app.path  
   
  进入到调用DLL的模块中。。。。  
   
  调用完毕  
   
  chdir   strTop

相关问题

  • vb调用vc++的dll
  • vc调用vb的dll
  • VC中调用VB生成的DLL(java调用VB的DLL)
  • vb调用vc的DLL问题
  • 如何在vb中调用vc的DLL
  • vb如何调用vc做的dll???
  • VB里怎样调用VC的DLL?
  • VB调用VC编写的DLL
  • vc中怎样调用vb写的dll
  • VB中如何调用VC写的DLL?

关键词

  • dll
  • 文件
  • vb
  • 调用
  • vhandle
  • vfilename
  • lplibfilename
  • 工程
  • 路径
  • 程序

得分解答快速导航

  • 帖主:progame
  • ltpao
  • tanaya
  • Pipi0714
  • NowCan
  • wenw
  • gump2000
  • wjying
  • load

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo