Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: LivedKrad on April 04, 2006, 05:00 PM

Title: Call VB6 function from a DLL
Post by: LivedKrad on April 04, 2006, 05:00 PM
Is there any way to call a function contained within a VB6 EXE from a VB6 DLL? I've already create a Standard DLL with VB6, with exportable functions. However now, I'd like to import functions to the DLL from the loading executable. Is this possible?
Title: Re: Call VB6 function from a DLL
Post by: TheMinistered on April 04, 2006, 05:05 PM
there are certain hacks you can do to the compiler (hooking it before it's finished and changing intermediary code...) but, I think I might know of a way to do it with pure vb code.
Title: Re: Call VB6 function from a DLL
Post by: LivedKrad on April 04, 2006, 05:18 PM
Eh, but using pure VB code would involve COM/ActiveX executables would it not?
Title: Re: Call VB6 function from a DLL
Post by: warz on April 04, 2006, 07:59 PM
So, you're making a VB application that uses a VB dll, but want to avoid using VB code to call functions from within the application?
Title: Re: Call VB6 function from a DLL
Post by: Joe[x86] on April 04, 2006, 08:46 PM
If you wrote a standard DLL (that exports functions like a C++ or ASM DLL), then all you have to do is declare the header line.

Declare functName(ArgName As ArgType, ...) As retType

It can be private or public, but I trust you know scopes by now.
Title: Re: Call VB6 function from a DLL
Post by: UserLoser on April 05, 2006, 12:10 AM
Quote from: LivedKrad on April 04, 2006, 05:00 PM
Is there any way to call a function contained within a VB6 EXE from a VB6 DLL? I've already create a Standard DLL with VB6, with exportable functions. However now, I'd like to import functions to the DLL from the loading executable. Is this possible?

Pass the address of the function to the DLL then call it.  Simple enough, see AddressOf operator
Title: Re: Call VB6 function from a DLL
Post by: TheMinistered on April 05, 2006, 01:12 AM
But passing via AddressOf will not avoid a COM call if the fxn is located inside an Object.  It just bypasses creation of the object.

It seems somewhat redundant to comile a standard dll via vb (linker hack) just to use the dll from a vb exe.  Why not just use an ActiveX dll?

Seems like there would be way more overhead in doing so... probably simpler to load the activex dll and pass an object to it, because your going to have way more overhead in calling that fxn address.
Title: Re: Call VB6 function from a DLL
Post by: Joe[x86] on April 05, 2006, 02:22 PM
Although this is completely unrelated (I think?), how do you use an ActiveX DLL in VB?
Title: Re: Call VB6 function from a DLL
Post by: topaz on April 05, 2006, 05:40 PM
You reference it or add it as a control.
Title: Re: Call VB6 function from a DLL
Post by: Ringo on April 05, 2006, 05:49 PM
Quote from: LivedKrad on April 04, 2006, 05:00 PM
Is there any way to call a function contained within a VB6 EXE from a VB6 DLL? I've already create a Standard DLL with VB6, with exportable functions. However now, I'd like to import functions to the DLL from the loading executable. Is this possible?
Yeah, just use a activeX.exe and a activeX.dll project (as group project if u want), then link the exe to the dll via project > references > browse > exe/dll and then add the exe.

But i dont think you can then link the dll to the exe on top of that, because VB doesnt allow cyclic references.
Or just use good old events :)

Hope this helps.
Title: Re: Call VB6 function from a DLL
Post by: LivedKrad on April 07, 2006, 12:54 PM
Quote from: Topaz on April 05, 2006, 05:40 PM
You reference it or add it as a control.

That would defeat the purpose of having non-COM libraries use the functions in my executable as well. So, there's no non-COM way to do this? Perhaps I could use Events like Ringo said to have the executable catch events fired by the DLL?
Title: Re: Call VB6 function from a DLL
Post by: MyndFyre on April 07, 2006, 01:37 PM
I don't have VB6 on here to try this, but can't you create a function in the DLL that accepts a function as a parameter a la AddressOf (someone else said this), so you more or less "register" EXE functions with the DLL?
Title: Re: Call VB6 function from a DLL
Post by: TheMinistered on April 07, 2006, 03:39 PM
Events are part of COM... maybe you should do some more research on this entire subject and maybe you will see why I said making a standard dll in vb and then loading it via a vb executable and passing a fxn addr is redundant.  In fact, why don't you research COM because I think we all know how standard dlls work.
Title: Re: Call VB6 function from a DLL
Post by: LivedKrad on April 08, 2006, 08:42 PM
Maybe.
Title: Re: Call VB6 function from a DLL
Post by: ntaryl on March 12, 2007, 09:56 AM
Hi  again   
Maby this  link  help  u   
http://www.vb-helper.com/howto_make_standard_dll.html
see  the way how to call function from a standalone .dll
Sorry if iam Wrong 
thanks 
Title: Re: Call VB6 function from a DLL
Post by: rabbit on March 12, 2007, 11:04 AM
Stop reviving old threads.