#include <fiveWin.ch>
proc main()
LOCAL IKTPCBizX
CoInitialize(0)
IKTPCBizX := IKTPCBizX_New()
if( IKTPCBizX<>0 )
IKTPCBizX_LogIn(IKTPCBizX, ;
/*nServer*/666, ;
/*sAuthKey*/"Example", ;
/*sLoginID*/"Antonino", ;
/*sLoginPwd*/"FiveWinForum")
IKTPCBizX_Release(IKTPCBizX)
endif
return
#pragma BEGINDUMP
#define CINTERFACE
#define COBJMACROS
#include <windows.h>
#include <hbapi.h>
#include "KTOpenAPI.h"
#include "KTOpenAPI_i.c"
HRESULT __stdcall MyCoCreateInstance(
LPCTSTR szDllName,
IN REFCLSID rclsid,
IUnknown* pUnkOuter,
IN REFIID riid,
OUT LPVOID FAR* ppv)
{
HRESULT hr = REGDB_E_KEYMISSING;
HMODULE hDll = LoadLibrary(szDllName);
if (hDll == 0)
return hr;
typedef HRESULT (__stdcall *pDllGetClassObject)(IN REFCLSID rclsid,
IN REFIID riid, OUT LPVOID FAR* ppv);
pDllGetClassObject GetClassObject =
(pDllGetClassObject)GetProcAddress(hDll, "DllGetClassObject");
if (GetClassObject == 0)
{
FreeLibrary(hDll);
return hr;
}
IClassFactory *pIFactory;
hr = GetClassObject(rclsid, &IID_IClassFactory, (LPVOID *)&pIFactory);
if (!SUCCEEDED(hr))
return hr;
hr = IClassFactory_CreateInstance(pIFactory, pUnkOuter, riid, ppv);
IClassFactory_Release(pIFactory);
return hr;
}
HB_FUNC( IKTPCBIZX_NEW )
{
IKTPCBizX* pKTPCBiz;
HRESULT hr;
hr = MyCoCreateInstance("KTOpenAPI.dll", &CLSID_KTPCBizX, 0, &IID_IKTPCBizX, (void**)&pKTPCBiz);
#ifndef _WIN64
hb_retnl( (long)pKTPCBiz );
#else
hb_retnll( (long long)pKTPCBiz );
#endif
}
LPWSTR UTF8toUTF16( LPCSTR utf8 );
/*
LPWSTR UTF8toUTF16( LPCSTR utf8 )
{
int wLen = MultiByteToWideChar( CP_UTF8, 0, utf8, -1, 0, 0 );
LPWSTR pString = ( LPWSTR ) hb_xgrab( wLen * 2 );
MultiByteToWideChar( CP_UTF8, 0, utf8, -1, pString, wLen );
return pString;
}
*/
HB_FUNC( IKTPCBIZX_LOGIN )
{
#ifndef _WIN64
IKTPCBizX *pKTPCBiz = ( IKTPCBizX* ) hb_parnl( 1 );
#else
IKTPCBizX *pKTPCBiz = ( IKTPCBizX* ) hb_parnll( 1 );
#endif
BSTR sAuthKey = SysAllocString(UTF8toUTF16(hb_parc(3)));
BSTR sLoginID = SysAllocString(UTF8toUTF16(hb_parc(4)));
BSTR sLoginPwd = SysAllocString(UTF8toUTF16(hb_parc(5)));
long nResult = 0;
if( pKTPCBiz )
{
//IKTPCBizX_Login(pKTPCBiz, hb_parnl(2), sAuthKey, sLoginID, sLoginPwd, &nResult );
pKTPCBiz->lpVtbl -> Login(pKTPCBiz,hb_parnl(2), sAuthKey, sLoginID, sLoginPwd, &nResult );
}
SysFreeString(sAuthKey);
SysFreeString(sLoginID);
SysFreeString(sLoginPwd);
hb_retnl(nResult);
}
HB_FUNC( IKTPCBIZX_RELEASE )
{
#ifndef _WIN64
IKTPCBizX *pKTPCBiz = ( IKTPCBizX* ) hb_parnl( 1 );
#else
IKTPCBizX *pKTPCBiz = ( IKTPCBizX* ) hb_parnll( 1 );
#endif
if( pKTPCBiz )
{
IKTPCBizX_Release(pKTPCBiz);
}
hb_ret();
}
#pragma ENDDUMP
HB_FUNC( IKTPCBIZX_NEW )
{
IKTPCBizX* pKTPCBiz;
HRESULT hr;
hr = MyCoCreateInstance("KTOpenAPI.dll", &CLSID_KTPCBizX, 0, &IID_IKTPCBizX, (void**)&pKTPCBiz);
hb_retptr( (void*)pKTPCBiz );
}
...
HB_FUNC( IKTPCBIZX_RELEASE )
{
IKTPCBizX *pKTPCBiz = ( IKTPCBizX* ) hb_parptr( 1 );
if( pKTPCBiz )
{
IKTPCBizX_Release(pKTPCBiz);
}
hb_ret();
}
AntoninoP wrote:I am not sure if there is a tool that create COM interface for Harbour automatically, if it does not exist, i could create it
Daniel Garcia-Gil wrote:use hb_rerptr( (void*) pValue ) to send at HIGH LEVEL
use hb_parptr( nParams ) to recibe in LOW LEVEL
AntoninoP wrote:Thank you, I don't saw it, theoretically (and practically) the int has always the same length of pointer, so I could use hbparni and hbretni.
#include "FiveWin.ch"
function Main()
MsgInfo( SizeOfInt(), "Size of int" )
MsgInfo( SizeOfPtr(), "Size of pointer" )
return nil
#pragma BEGINDUMP
#include <hbapi.h>
HB_FUNC( SIZEOFINT )
{
hb_retnl( sizeof( int ) );
}
HB_FUNC( SIZEOFPTR )
{
hb_retnl( sizeof( void * ) );
}
#pragma ENDDUMP
int returns 4 and a pointer returns 8:
procedure main
? valtype(C_retptr())
? valtype(C_retni())
? C_PTRINT(C_retni())
return
#pragma BEGINDUMP
#include <hbapi.h>
HB_FUNC( C_RETPTR )
{
hb_retptr( (void*)611 );
}
HB_FUNC( C_RETNI )
{
hb_retni( 611 );
}
HB_FUNC( C_PTRINT )
{
hb_retni( (int)hb_parptr(1) );
}
#pragma ENDDUMP
P
N
0
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 47 guests