PDA

Click to See Complete Forum and Search --> : How to use DLL created in VC++ on VB programs?


serhiy
Dec 20th, 2000, 02:38 AM
Goodday everybody...

I would like to know how do i use DLL developed in VC++ in VB programs? What are the procedure i need to do to link it to my VB programs and how do i actually use the functions available in the DLL on my VB programs?

Your help will be most appreciated...

Vlatko
Dec 20th, 2000, 05:19 AM
You should have declared the functions in the DLL for export and then you can use them in VB:

Private Declare Function FunctionName Lib "dllname.dll" (arguments as something) as something
'this is if the function in the dll returns a value else use

Private Declare Sub FunctionName Lib "dllname.dll" (arguments as something)

ttingen
Dec 20th, 2000, 08:08 AM
Do you know if you have to specify the path of the dll or not?

Does windows start looking for it in Windows\System or the application's directory?

Just curious.

misterkiasu
Dec 20th, 2000, 08:44 PM
Hi ttingen, if you dont specify the path, windows will look for the dll files based on the directories you've specified in the PATH ENVIRONMENT, and they usually check in the current folder first (the folder in which you store your VB project files).
If you do not put the dll in one of the directories specified in the PATH Environment, you may specify the path so that windows can locate the dll file directly.

Hope it helps.

serhiy
Dec 20th, 2000, 08:52 PM
thanks vlatko...
export the functions in th DLL? how do i do that?

hi misterkiasu...
where do i specify the PATH ENVIRONMENT?

Vlatko
Dec 21st, 2000, 05:07 AM
If you put this in a C++ dll:

void _stdcall message(HWND hwnd)
{
MessageBox(hwnd,"text","Text",MB_OK);
}


and this in VB:

Private Declare Sub Message Lib "dllname.dll" (ByVal hwnd as Long)

'call it
Message Form1.hWnd
'pops up a message box


You can also use a def file and write the function names you want to export there

EXPORTS
Message

serhiy
Dec 21st, 2000, 10:16 PM
thanks vlatko...

but this can be used if the DLL is created as a Library-Type DLL, right?
what if i want to create an ActiveX DLL? can i create an ActiveX DLL in VC++ and how do i do it?

and also, this can bed use only if the function is a general function, right? what if i want to use a function which is in a class? how should i do it? In VB, how can i declare an object of the class created in the DLL?

correct me if i'm wrong...

parksie
Dec 22nd, 2000, 06:31 AM
At the moment you can't use a C++ class from VB. All the virtuality semantics break down once you start copying things around :(.

serhiy
Dec 28th, 2000, 08:18 PM
parksie...

what do you mean by "All the virtuality semantics break down once you start copying things around"?

can you please explain? thanks...

parksie
Dec 29th, 2000, 12:30 PM
In C++, you have virtual inheritance. This means that a pointer to an object may not actually refer to that TYPE of object. It is usually used to great advantage in COM. What happens:

class Base {
public:
int Function() { return 5; }
};

class Derived: public Base {
int Function() { return 1; }
}

So, Derived is derived from Base. Normal sense indicates:

Base *pBase = new Base;
Derived *pDerived = new Derived;

pBase->Function(); // Returns 5
pDerived->Function(); // Returns 1


If you do THIS, though:

Base *pWhat = new Derived;

pWhat->Function(); // Returns 1

The magic of virtual inheritance is what causes the derived class' function to be called.

This is virtuality semantics.

In VB, you can't use a C++ class because there is no way to tell, even when reading vfptr, what function should be called.