|
-
Sep 6th, 2001, 07:48 PM
#1
Thread Starter
PowerPoster
whats the different betwwen the lib and DLL?
I 've a simple question here.
Can someone explain to me whats the different between the lib and DLL?
If I plan to write a Serial Port driver and I require to do the following things...
- A function to open the serial port like OpenPort(char *PortNo)
- A Send data function like Send2Mobile(char *data)
- A CALLBACK function to the main program when received a data from serial port. This call back function might return the data in structure form.
That the minimum function that I need, hope someone can give me some idea.
So far I can write a DLL after getting the guide line from parksie 
but not able to write a call back function.
regards,
Chris.C
-
Sep 7th, 2001, 05:31 AM
#2
The difference between a static library (lib) and a dynamic link library (dll) is that the code from the lib is directly included in your program while the code from the dll is only referenced. A lib is a collection of code, and if the linker detects the usage of this code in your program, it inserts the code into you exe. A dll is also a collection of code, but if the linker detects usage of this code, a reference to the code of the dll is inserted. This means that a dll needs only to be loaded once for all apps that use it, while a lib is included in every app that uses it. The advantage of libs is that you don't need to distribute more than one file (probably).
Callbacks:
Do you mean you want to call a VB function?
A VB callback must be located in the main module. Watch out for ByVal and ByRef parameter passing conventions.
In C, you have to declare a pointer to the callback function, like this:
Code:
typedef return type (__stdcall * TYPENAME)(parameter list);
And you have to get the address of the function, for example by an init function:
Code:
void __stdcall InitDriver(TYPENAME pfnCallBack);
which saves the address of the function and has to be called from VB like this:
Code:
private declare sub InitDriver(ByVal pfn as long)
call InitDriver (addressof Callbackfunc)
You can later call this function from the DLL like this:
Code:
pfnCallBack(parameter);
Just don't forget:
Code:
int i = 5;
int *pi = &i;
PINT p = &i;
pfnCallBack( i, // this is a value, use ByVal
&i, // this is a pointer, use ByRef
pi, // also a pointer
p); // also a pointer
Therefor, this is the callback:
Code:
public sub CallBack (ByVal i as long, ByRef pi1 as long, ByRef pi2 as long, ByRef pi3 as long)
.
.
.
end sub
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 10th, 2001, 07:33 AM
#3
Thread Starter
PowerPoster
Thx cornedBee, finally i manage to work out the CALLBACK but I still can not passing a structure back from DLL to VB/VC external program.
Can you please look into this thread
regards,
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
|