-
June 21st, 2005, 01:23 AM
#1
VB calling VC++ DLL
Hi,
I wrote a vb program calling vc++ dll.
so for example in the vb program...
we would declare such as the following
Public Declare Function AddNums Lib "C:\apress\ch9.dll" (By Val....)
I would like to know how it is it possible for the vb program to call the DLL dynamically without specifying the full directory path of the DLL.
That is eg. Public Declare Function AddNums Lib "ch9.dll" (By Val....)
Even though I placed the dll file into the VB directory, it would complain
"dll file not found", when I do not specify the full path.
I need to resolve this urgently.
Please advise, thanks.
Sally
-
June 21st, 2005, 01:24 AM
#2
VB calling VC++ DLL
Hi,
I wrote a vb program calling vc++ dll.
Using win XP, running vb and vc++ version 6.0
so for example in the vb program...
we would declare such as the following
Public Declare Function AddNums Lib "C:\apress\ch9.dll" (By Val....)
I would like to know how it is it possible for the vb program to call the DLL dynamically without specifying the full directory path of the DLL.
That is eg. Public Declare Function AddNums Lib "ch9.dll" (By Val....)
Even though I placed the dll file into the VB directory, it would complain
"dll file not found", when I do not specify the full path.
I need to resolve this urgently.
Please advise, thanks.
Sally
-
June 21st, 2005, 03:26 AM
#3
Re: VB calling VC++ DLL
Hi..
put it in the same exe folder
or in the windows system folder...
-
June 21st, 2005, 03:30 AM
#4
Re: VB calling VC++ DLL
No, I'm afraid it is not possible to dynamically vary the path to the DLL. Had the same problem a while back.
Two solutions:
1) make a DLL which sits in your application root and acts as a delegator. i.e. takes all the information required and passes it to / from the required DLL. (needs an extra paramater for the dll path and name). You VB app will call this DLL and it will then pass the info to the required dll.
2) register the DLL using the regsvr32 function from the command propmt. That way your dll will be able to exist in any location and your VB app can call it without supplying a path.
Mike
-
June 21st, 2005, 03:38 AM
#5
Re: VB calling VC++ DLL
Originally Posted by Pinky98
2) register the DLL using the regsvr32 function from the command propmt. That way your dll will be able to exist in any location and your VB app can call it without supplying a path.
This is true in case the DLL has the DLLRegiserServer function...
this is the case in COM DLLs but not in standard DLLs that I assume sallypeh is trying..
-
June 21st, 2005, 03:40 AM
#6
Re: VB calling VC++ DLL
not in my experience... maybe I did some thing else to make it work... but regsvr32 always seems to give me the required result.
Mike
-
June 21st, 2005, 03:41 AM
#7
Re: VB calling VC++ DLL
Mike
-
June 21st, 2005, 04:48 AM
#8
Re: VB calling VC++ DLL
Originally Posted by Pinky98
not in my experience... maybe I did some thing else to make it work... but regsvr32 always seems to give me the required result.
This is without specifying the full path...
============================
Hi, I placed the vc++ dll inside the directory of vb program.
I tried moving many times, reset pc, etc. Then it seems able to find the dll file. It did not complain "File not found" error.
However, it does not work correctly, though it manage to find the pointer to my vc++ dll, but there is no response from the vc++ dll to vb. If i tried running my vb program from vc++ environment for debugging purposes, it works fine! Gosh, I need to get the vb program running from vb IDE, not vc++ IDE.
Is there particular way on how to know whether vb program is calling the correct vc++ dll program?
Please help. Thanks, Sally
If i did not understand wrongly, if the path is not specified, it will just take
the relative path that the exe file resides...
Last edited by sallypeh; June 21st, 2005 at 04:56 AM.
-
June 21st, 2005, 06:35 AM
#9
Re: VB calling VC++ DLL
Mmmmm, sounds to me like the ubiquitous name convesion problem!
This problem is really aweful, but fairly easy to fix. Basically the calling convesion (_stdcall) which allows C++ Dlls to be seen by VB changes the name of the C++ function. Take a look at some of these for a possible solution:
http://www.codeguru.com/forum/showth...threadid=29471
http://www.codeguru.com/forum/showthread.php?t=227421
http://www.codeguru.com/forum/showthread.php?t=252517
(the 2nd is probably clearest)
hope that helps.
-
June 22nd, 2005, 10:51 PM
#10
Re: VB calling VC++ DLL
Originally Posted by Pinky98
---------------
Hi, I use the standard convention - ie . _stdcall convention.
Now, I tried redoing a smaller version of my original c++ dll
and with the same vb program.
However, this time round. Something very strange.
I copied all the dlls into the vb folder where my vb program.exe lies.
I noticed if I run from vb IDE, it would complain my vc++ dll file not found...
but if I run purely my vb program (vb.exe file which I compiled)...it works fine!!!
So, I went over to my vc++ project workspace, and execute the same vb program for debugging purposes...it works fine. Then went over to vb IDE, to run my vb program again. This time round, it does not complain the dll file not found,...but it does not work correctly, it does not achieve the same result as what the vb program exe achieves earlier.
Please advise...
I am very confused now.
Thanks, Sally
-
June 23rd, 2005, 12:45 AM
#11
Re: VB calling VC++ DLL
Are you sure you are referencing the correct DLL?? That is about the only thing I could think could be wrong.
First time you ran it (and didn't work)... you may have been trying to reference the dll in the working directory (when you start a project from inside IDE this is VB's folder, but when you start by double clicking the project file then it is the project folder).
Why it gave you different results... I don't know. I'm as confused as you are. Maybe a bug in the c++?
Maybe try "building" up the dll... i.e. first do a simply x+2 operation... then increase this a bit until eventually you find the problem or it works correctly.
Mike
-
June 23rd, 2005, 01:04 AM
#12
Re: VB calling VC++ DLL
VB application sometimes behaves differently when being run from sourcecode as compare to running in compiled binary.
If we use the VB project to run from the IDE, sometimes the app.path (startup directory of the application) will points to vb.exe location (e.g c:\progfiles\microsoft vs\vb.exe), but when run from compiled binary the app.path property always points to the exe location.
Now for your problem, like previously suggested,
- place the dll in system directory, or
- place the dll in one of the folder specified in your PATH environment setting, or
- place the dll in the same folder as your exe, but make sure you call the ChDir function in your app to change the default dir to your app startup directory or change the PATH environment variable on runtime to include your startup directory and restore it when your app terminates.
-
June 23rd, 2005, 03:47 AM
#13
Re: VB calling VC++ DLL
Hi,
I have another type of problem regarding using VC++ dll in VB. I have several parameters which are pass into the vc dll to get certain values. They are either of type LONG( vc= integer) or SINGLE(vc=float). The values i get for LONG variables are correct but those of SINGLE are wrong. Any idea what could be a reason?
Tks.
Aaron
-
June 23rd, 2005, 05:21 AM
#14
Re: VB calling VC++ DLL
Originally Posted by Luthv
VB application sometimes behaves differently when being run from sourcecode as compare to running in compiled binary.
If we use the VB project to run from the IDE, sometimes the app.path (startup directory of the application) will points to vb.exe location (e.g c:\progfiles\microsoft vs\vb.exe), but when run from compiled binary the app.path property always points to the exe location.
Now for your problem, like previously suggested,
- place the dll in system directory, or
- place the dll in one of the folder specified in your PATH environment setting, or
- place the dll in the same folder as your exe, but make sure you call the ChDir function in your app to change the default dir to your app startup directory or change the PATH environment variable on runtime to include your startup directory and restore it when your app terminates.
------------------
Hi,
I run on other pcs with xp with service pack 2, and from vb IDE, it works pretty ok. Only My pc run from vb IDE, doesn't work fine.
Strange...and I reinstalled the whole visual studio 6.0 of my pc, I still encounter this problem on my pc. Besides, I even upgrade to xp service pack2.
I tried placing the dll files in the same directory with the vb exe file and also tried placing the dll files in the system directory.
Either way, EXE file can work, But run from VB IDE cannot work.
Btw, what is this PATH env? where can I set it?
Please advise,
Thanks, Sally
Last edited by sallypeh; June 23rd, 2005 at 05:37 AM.
-
June 23rd, 2005, 05:24 AM
#15
Re: VB calling VC++ DLL
have you tried upgrading your Visual studio to service pack 6?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|