Need help on writing DLL 
Author Message
 Need help on writing DLL

Hi,

    I'm a VB programmer and needs to write a DLL in VC++ for the
SetWindowsHookEx to work with system messages. Basically, what I need to do
is a DLL to intercept system messages and provides callbacks to my VB
procedure. I've tried to write my own DLL in VC and looked into the MSDN
sample of Spy program but the source codes are just too confusing.
    Can anyone give me some help here. Thanks.



Thu, 27 Jun 2002 03:00:00 GMT  
 Need help on writing DLL
Look for the string "vb5dll.doc" on http://msdn.microsoft.com  .  This
document comes with VB and discusses interfacing VB and C++ DLLs...

Les


Quote:
> Hi,

>     I'm a VB programmer and needs to write a DLL in VC++ for the
> SetWindowsHookEx to work with system messages. Basically, what I need to
do
> is a DLL to intercept system messages and provides callbacks to my VB
> procedure. I've tried to write my own DLL in VC and looked into the MSDN
> sample of Spy program but the source codes are just too confusing.
>     Can anyone give me some help here. Thanks.



Thu, 27 Jun 2002 03:00:00 GMT  
 Need help on writing DLL
I have just written my first DLL. This worked for me but will probably bring
tears to the eyes of the more experienced.

1)You need a WinMain call in the cpp code of your DLL

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID)
{
 return(TRUE);

Quote:
}

2)Then the c++ function
long  __stdcall fnGenDayValues(char* strLogVal, double* DayArray, char*
StatusArray, int gapiszero, double MeterCoefficient)
{
Does stuff
return something

Quote:
}

Note the  __stdcall

3)You need to  add a def file to your C++ project and  place in it an export statement :

; Voucher1.def : Declares the module parameters for the DLL.

LIBRARY      "RTGen"
DESCRIPTION  'RTDM File Generation Windows Dynamic Link Library'

EXPORTS
    ; Explicit exports can go here
 DllMain
 fnGenDayValues

4) Visual Basic
The VB declaration for the function  is:
'Public Declare Function fnGenDayValues Lib "RTGEN.dll" (ByVal strLogVal As String, DayArray As Double, ByVal StatusArray As String, ByVal gblgapiszero As Long, ByVal MeterCoefficient As Double) As Long
OR
Public Declare Function fnGenDayValues Lib "K:\Vbasic Projects\StarkRT\RTGEN\Ver1_32\VC++\debug\RTGEN.dll" (ByVal strLogVal As String, DayArray As Double, ByVal StatusArray As String, ByVal gblgapiszero As Long, ByVal MeterCoefficient As Double) As Long

Note one explicity states the directory, use this while debugging your DLL.
Release the one that implies the application directory to the customer with the final release version.
To debug your DLL make a vb executable of your app.
Then start the VC++ debug for the DLL. It will activate your app and away you go.

The hardest part I found was stating the right data types in the passed parameters.
To pass an array, pass the first element by reference. eg 'DayArray' above
HTH

Quote:

> Hi,

>     I'm a VB programmer and needs to write a DLL in VC++ for
the
> SetWindowsHookEx to work with system messages. Basically, what I need to
do
> is a DLL to intercept system messages and provides callbacks to my VB
> procedure. I've tried to write my own DLL in VC and looked into the MSDN
> sample of Spy program but the source codes are just too confusing.
>     Can anyone give me some help here. Thanks.



Sun, 30 Jun 2002 03:00:00 GMT  
 Need help on writing DLL

Quote:

>     I'm a VB programmer and needs to write a DLL in VC++ for the
> SetWindowsHookEx to work with system messages.
...
> the source codes are just too confusing.

Yes, I still don't understand much of the so-called "documentation".

I've written up a crude cheat-sheet on mixing VB with DLLs written in
VC.
  http://www.rdrop.com/~cary/program/mixed_language.html
Maybe you'll find it helpful. Please tell me how it can be improved.

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 30 Jun 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. I need help writing dlls for win95

2. Writing Display Drivers needs some dll ??

3. Needed info about eVC data types for writing a DLL

4. Need Help Referencing another DLL's methods in a secondary DLL

5. Need Help Referencing another DLL's methods in a secondary DLL

6. HELP!!! Need help calling a DLL

7. DLL in VC++ HELP NEEDED ! Help me

8. Need some help in writing a simple C program

9. Need help for writing a function returning pointer

10. help.need to write a script in c......

11. Help with writing to disk needed

12. Need some help in writing a simple C program

 

 
Powered by phpBB® Forum Software