Tuesday, July 12, 2011

Can HMGExt create an OLE Object itself?

CCH : From the Harbour MiniGui Forum

Q. Hi

I would like to know if it's possible for HMGExt to create an OLE Object itself, so it can be used from another programs (An OLE Server)?.

Hugo

Answer


Yes , using Harbour you can do that

example :

#include "hbclass.ch"

#define CLS_Name  "SNLANG"
#define CLS_ID    "{A78E2493-5156-445C-A516-F330BD4FA013}"

PROCEDURE DllMain()

  LOCAL hAction

   hAction := { => }
   hb_HKeepOrder( hAction, .T. )
   hb_HSetCaseMatch( hAction, .F. )
   hAction[ "FILENAME" ]    := NIL                  // DISPID=1
   hAction[ "RUNNOVAFILE" ]  := @Run_NovaFile()         // DISPID=2

   /* Initialize OLE server ID and name.
    * WIN_OleServerInit() should be executed from DllMain()
    */
   WIN_OleServerInit( CLS_ID, CLS_Name, hAction, .T. )

RETURN

STATIC FUNCTION Run_NovaFile( ... )
   LOCAL hAction := QSelf()

   IF hAction[ "FILENAME" ] == NIL
      RETURN "(:FILENAME IS NOT SET)"
   ENDIF

 RETURN ( hAction[ "FILENAME" ] )

To build this sample, you can use hbmk2

hbmk2 -hbdynvm nova.prg  -lhbwin -lgtwin hbolesrv.hbc

and we have hbolesrv.def & hbolesrv.hbc

#
# $Id: hbolesrv.hbc 15142 2010-07-17 19:51:18Z vszakats $
#

stop={!hbdynvm}Warning: Target must be '-hbdynvm' when using '${hb_self}'. Process stopped.

libs=hbwin.hbc

gt=gtgui

cflags={watcom}-6r

sources={mingw}hbolesrv-mingw.def
sources={watcom}hbolesrv-watcom.def
sources={!mingw&!watcom}hbolesrv.def

;
; $Id: hbolesrv.def 14605 2010-05-26 10:08:01Z vszakats $
;

EXPORTS
DllGetClassObject       PRIVATE
DllCanUnloadNow         PRIVATE
DllRegisterServer       PRIVATE
DllUnregisterServer     PRIVATE
DllMain

When you download harbour you will find samples in this location

C:\hb21\contrib\hbwin\tests

Greetings,
Mahmoud Fayed
http://pwct.org

No comments:

Post a Comment