access to window via its :hwnd

access to window via its :hwnd

Postby don lowenstein » Wed Jan 03, 2018 8:59 pm

I have a harbour .dll which I call dynamically.

I wish to pass a window-object ( ownd ) to the dll, but so far I have only been able to pass the window's handle to the .dll

so, today, the calling program passes the window's self:hwnd

the window handle is passed to the dynamic external .dll

question - when the .dll receives the window's handle, how does that process gain access to the actual window object, identified by :hwnd ??

If I could pass the actual windows object, that would be great.

I followed the basic convention used in the FWH samples babudll.prg and babu.prg.

thanks in advance.
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Re: access to window via its :hwnd

Postby Antonio Linares » Thu Jan 04, 2018 9:21 am

Don,

function oWndFromHwnd( hWnd ) --> oWnd

If you use:

HbDLLEntry2( "TEST2", oWnd, nil )

then you will have access to oWnd from HbDLLEntry2()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41206
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: access to window via its :hwnd

Postby don lowenstein » Fri Jan 05, 2018 11:34 pm

In this example, I added code to create a dialog in the calling program( babu.prg ) and added 1 control to it.

then, I pass to the .dll ( babudll.prg ) the following.

hItem1 := ItemNew( odialog:hwnd )
hItem2 := 'Dialog Handle Passed'

HbDLLEntry2( "TEST3", hItem1, hitem2 )

***************
within babudll.prg, the handle is properly passed.

Using, oWndFromHwnd( hWnd ) a problem exists, because that function searches the aWindows within the context of the dll.

The window was created in the calling program - babu.prg and therefore, the aWindows array in the babudll.prg does not see the window created in babu.dll, and therefore, returns NIL using this method.

Is it possible for babu.prg to pass to the dll a reference or pointer or something, so that the object created within babu.prg is visible in babudll.prg?

Using string, date, integer, boolean and decimal data types work perfectly.

thanks in advance for any guidance.
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Re: access to window via its :hwnd

Postby don lowenstein » Fri Jan 05, 2018 11:44 pm

I tried passing oWnd, but the system created a GPF and froze.

I tried passing the oWnd within an array.

The array passed properly, however, the when accessing the control itself the GPF ensued.
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Re: access to window via its :hwnd

Postby Antonio Linares » Sat Jan 06, 2018 6:52 am

Don,

Please post your modified PRGs here so we can test them
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41206
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: access to window via its :hwnd

Postby don lowenstein » Sat Jan 06, 2018 4:08 pm

Here is the "calling program" = babu.prg modified
After that is the "dll program" = babudll.prg modified

you may want to remove the altd() breaks and the reference to the external debugging libraries.
REQUEST HB_GT_WIN
REQUEST HB_GT_WIN_DEFAULT

*********************************************************

// Using Harbour DLLs
// To build BabuDLL.dll do: buildhd.bat DLL-DON

#include "FiveWin.ch"

static hDLL


REQUEST HB_GT_WIN
REQUEST HB_GT_WIN_DEFAULT


// Harbour requirement for console debug mode comment out for Production Make/Link
// comment out this procedure for prod

procedure hb_gt_gui_default
return



*****************************************************

function Main()



// local hItem1 := ItemNew( "Hello world!-billy/don" )
// local hItem2 := ItemNew( "From a Harbour DLL-billy/don" )


local hItem1
local hItem2

local marray := {}
local i, OPRINTER

local ownd, OWAITDLG , ODIALOG, WORKTEXT, OSAY, MDLL

altd(1)
altd()

hDLL = LoadLibrary( "DLL-DON2.DLL" )

SET RESOURCES TO
DEFINE DIALOG owaitdlg FROM 1, 1 TO 222, 333 ;
STYLE nOR( WS_VISIBLE, WS_POPUP ) PIXEL
OWAITDLG:CTITLE := 'Prepare System Parameters'

worktext := ''
WORKTEXT += CR_LF()
WORKTEXT += 'Retrieving System Import' + CR_LF()
WORKTEXT += CR_LF()
WORKTEXT += 'and Upload Parameters' + CR_LF()
WORKTEXT += CR_LF()
WORKTEXT += 'This may Take Several Seconds' + CR_LF()
WORKTEXT += CR_LF()
WORKTEXT += 'Please Wait' + CR_LF()

@ 10, 20 SAY OSAY VAR WORKTEXT ;
OF OWAITDLG

ACTIVATE DIALOG OWAITDLG ;
CENTERED ;
NOWAIT

// pass the window/osay hwnd
hitem1 := ItemNew( owaitdlg:hwnd )
hitem2 := ItemNew( OSAY:hwnd )

HbDLLEntry2( "TEST3", hItem1, hitem2 )

// pass the dialog
//hitem1 := ItemNew( owaitdlg )
//hitem2 := ItemNew( OSAY:hwnd )

//HbDLLEntry2( "TEST3", hItem1, hitem2 )


ItemRelease( hItem1 )
ItemRelease( hItem2 )

FreeLibrary( hDLL )

return nil


***********

FUNCTION CR_LF()

RETURN CHR(13) + chr(10)

*************

****************************************


DLL FUNCTION HBDLLENTRY( cProc AS LPSTR ) AS LONG PASCAL LIB hDLL

DLL FUNCTION HBDLLENTRY2( cProc AS LPSTR, pItem1 AS LONG, pItem2 AS LONG ) AS LONG PASCAL LIB hDLL

// DLL FUNCTION HBDLLENTRY3( cProc AS LPSTR, pItem1 AS PTR, pItem2 AS PTR ) AS LONG PASCAL LIB hDLL



#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapiitm.h>

HB_FUNC( ITEMNEW )
{
hb_retnl( ( unsigned long ) hb_itemNew( hb_param( 1, HB_IT_ANY ) ) );
}

HB_FUNC( ITEMRELEASE )
{
hb_retl( hb_itemRelease( ( PHB_ITEM ) hb_parnl( 1 ) ) );
}


#pragma ENDDUMP

************************************************************
************************************************************


"dll program"


// To build BabuDLL.dll do: buildhd.bat babuDLL

// To run this DLL, do buidh.bat dll-don2.prg


REQUEST HB_GT_WIN
REQUEST HB_GT_WIN_DEFAULT


// Harbour requirement for console debug mode comment out for Production Make/Link
// comment out this procedure for prod

procedure hb_gt_gui_default
return



***************************************************************

function Test()


MsgInfo( "Hello from inside the DLL!", 'our message 1' )

return nil


********************************************************************


function Test2( cMsg1, cMsg2 )

MsgInfo( cMsg1, cMsg2, 'our message 2' )

return nil


**************************************************************


function Test3( VAL1, VAL2 )



local a, b, c, d, e, f
local hwnd := val1

altd(1)
altd()

a := val2
b := a
altd(1)
altd()

c := d


altd(1)
altd()


// Function oWndFromHwnd( hWnd ) --> oWnd
b := oWndFromHwnd( hWnd )


return nil


****************************************************


#pragma BEGINDUMP

#include <windows.h>
#include <hbvm.h>
#include <hbapiitm.h>

BOOL WINAPI DllEntryPoint( HINSTANCE hinstDLL, DWORD fdwReason,
LPVOID lpvReserved )
{
HB_SYMBOL_UNUSED( hinstDLL );
HB_SYMBOL_UNUSED( fdwReason );
HB_SYMBOL_UNUSED( lpvReserved );


switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
// MessageBox( 0, "DLL properly loaded -", "DLL entry", 0 );
hb_vmInit( 0 );
break;

case DLL_PROCESS_DETACH:
// MessageBox( 0, "DLL unloaded - ", "DLL exit", 0 );
break;
}


return TRUE;

}

void pascal __export HBDLLENTRY( char * cProcName )
{
hb_itemDoC( cProcName, 0 );
}

void pascal __export HBDLLENTRY2( char * cProcName, PHB_ITEM pParam1, PHB_ITEM pParam2 )
{
hb_itemDoC( cProcName, 2, pParam1, pParam2 );
}

#pragma ENDDUMP


********************************************
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Re: access to window via its :hwnd

Postby Antonio Linares » Sat Jan 06, 2018 7:20 pm

Don,

Please remove NOWAIT from here and try it again:

ACTIVATE DIALOG OWAITDLG ;
CENTERED ;
NOWAIT
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41206
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: access to window via its :hwnd

Postby don lowenstein » Mon Jan 08, 2018 4:43 pm

Without the NOWAIT the dialog showed on the screen and waited until closed.

I tried to send a reference to an oPrinter object also. same results - the system either hung or GPF'ed depending on what and how I passed it.

I can't readily see how to gain access to an object created in one .exe, which is required to be examined within a Harbour .dll function, like FUNCTION TEST3()

Each time I attempt to reference the passed "object" the process terminated.
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Re: access to window via its :hwnd

Postby Antonio Linares » Tue Jan 09, 2018 11:03 am

Don,

In order to use Harbour objects created in the EXE from the DLL, you have to use a pcode DLL and not an autocontained DLL. The pcode DLL shares the EXE virtual machine, so it can access and manage the created objects from the EXE.

Please review FWH/samples/buildhdp.bat to build them

also review samples/pcodedl*.prg
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41206
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: access to window via its :hwnd

Postby don lowenstein » Tue Jan 09, 2018 3:43 pm

My ultimate goal is to create an object in Visual C# and have access to that object within Harbour code.

Do you think this is possible?
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Re: access to window via its :hwnd

Postby Antonio Linares » Tue Jan 09, 2018 7:04 pm

Don,

Yes, you can do it using the FiveNet design architecture:

https://bitbucket.org/fivetech/fivenet/wiki/Architecture

Please review FiveNet source code:
https://bitbucket.org/fivetech/fivenet/src

In its samples folder there are some working examples you can review
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41206
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: nageswaragunupudi and 12 guests