in the website xharbour.com i found it
How to create a DLL
The "how do I create code which is accessible in other applications" question is asked pretty often when you browse newsgroups, faq's and forums. This is no different with xHarbour. In this article we'll explain how to create a DLL which holds code that you can easily use in other applications and thus creating less work for the time-driven developers out there.
First things first. How do we make our xHarbour code available for applications written in for example Visual Basic? The answer is easy: by posing our code as an OLE object. OLE (Object Linking and Embedding) is a technology that allows embedding and linking to other objects. The nice thing about OLE is that you can use it to achieve something (execute a piece of xHarbour code) in an environment which is not able to do it on it's own.
Ok, but how do we do this in the real world?
With the OleServer.lib from xHarbour.com, you basically just add 5 lines of code to the top of your program:
#pragma BEGINDUMP
#define CLS_Name "MyOleServer"
#define CLD_ID "{D385CFF0-01BE-42ea-8272-336CDE8ABA5A}"
#include "OleServer.h"
#pragma ENDDUMP
The GUID used in this example can be randomly generated by Microsoft's GuidGen tool to generate GUID's. It's also possible to generate GUID's via the website http://www.guidgen.com/. By adding this code, your functions, classes, methods and properties will be available as OLE methods. Below is a complete sample demonstrating this working method.
#pragma BEGINDUMP
#define CLS_Name "SampleOleServer"
#define CLS_ID "{D385CFF0-01BE-42ea-8272-336CDE8ABA5A}"
#include "OleServer.h"
#pragma ENDDUMP
#include "hbclass.ch"
/*
OPTIONAL FUNCTION - if it exists, it will set the Server to a specific Object Instance or you may return the same Object previously created if you want all OLE intanaces to refer to just one Object.
*/
FUNCTION CreateInstance
LOCAL oOleServer := MyOleServer()
// Transfer all errors to the Client
ErrorBlock( {|e| Break(e) } )
/*
If you return an Object, it becomes *the* Server, otherwise the non
ststic PROCEDURES and FUNCTIONS
of this module will be the exported Methods, and PUBLICS MEMVARS will
be the exported Properties.
*/
RETURN oOleServer
CLASS MyOleServer
PUBLIC:
DATA MyProperty
METHOD MyMethod( x )
ENDCLASS
METHOD MyMethod( x ) CLASS MyOleServer
::MyProperty := x
IF HB_IsByRef( @x )
SWITCH ValType( x )
CASE 'C'
x := "Modified!"
EXIT
CASE 'D'
CASE 'N'
x++
EXIT
CASE 'A'
x := { "Modified!" }
EXIT
END
ENDIF
RETURN Self
And a sample to test our OleServer:
PROCEDURE Main()
LOCAL oServer, xByRef
oServer := CreateObject( "SampleOleServer" )
oServer:MyMethod( "test" )
? ValToPrg( oServer:MyProperty )
RETURN
Please note that you should always distribute the xHBDll.dll (or xharbour.dll if using the .org distributions) together with your own .dll and they must be located in the same directory.
Also, your installer should register your DLL using the following command: RegSvr32 <YourPrgOleServer.dll>
And building the DLL can be done with: xBuild YourPrgOleServer.dll YourPrgOleServer.prg or by using the xBuild wizard with the "DLL" option checked.
So i´m trying use it..
dll.prg
- Code: Select all Expand view
- #pragma BEGINDUMP
#define CLS_Name "SampleOleServer"
#define CLS_ID "{D385CFF0-01BE-42ea-8272-336CDE8ABA5A}"
#include "OleServer.h"
#pragma ENDDUMP
#include "hbclass.ch"
/*
OPTIONAL FUNCTION - if it exists, it will set the Server to a specific Object Instance or you may return the same Object previously created if you want all OLE intanaces to refer to just one Object.
*/
FUNCTION CreateInstance
LOCAL oOleServer := MyOleServer()
// Transfer all errors to the Client
ErrorBlock( {|e| Break(e) } )
/*
If you return an Object, it becomes *the* Server, otherwise the non
ststic PROCEDURES and FUNCTIONS
of this module will be the exported Methods, and PUBLICS MEMVARS will
be the exported Properties.
*/
RETURN oOleServer
CLASS MyOleServer
PUBLIC:
DATA MyProperty
METHOD MyMethod( x )
ENDCLASS
METHOD MyMethod( x ) CLASS MyOleServer
::MyProperty := x
IF HB_IsByRef( @x )
SWITCH ValType( x )
CASE 'C'
x := "Modified!"
EXIT
CASE 'D'
CASE 'N'
x++
EXIT
CASE 'A'
x := { "Modified!" }
EXIT
END
ENDIF
RETURN Self
and..
My progman menu.prg
- Code: Select all Expand view
PROCEDURE Main()
LOCAL oServer, xByRef
oServer := CreateObject( "SampleOleServer" )
oServer:MyMethod( "test" )
? ValToPrg( oServer:MyProperty )
RETURN
while i will compile dll.prg show me that dont have oleserver.H
i´m searching for this file more don´t have in my computer...
it´s possible create with fivewin or need something ?
thanks so much.