How to combine (or use) SDK dll into Fivewin HB/XHB?

User avatar
kim yong woo
Posts: 55
Joined: Sun Apr 12, 2009 10:51 am
Location: Seoul, Korea
Contact:

How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by kim yong woo »

Hello every experts!

I have limited experience with Fivewin. :(

I am trying to build-up telephone CID(Caller Identification) program with SDK published by phone company.

How Can I use this dll in FWH harbour/xHarbour?
Pleae help me...! :roll:

Attached my target DLL(KTOpenAPI.dll) as followings.
http://pharmalink.kr/images/K.zip

They mentioned to register their DLL ( KTOpenAPI.dll) as followings.
-----------------------------------------------------------------------------------
regsvr32 KTOpenAPI.dll

And and in MSC Sharp sample were as followings

Main.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace KTOpenAPICSharpSample
{
static class Program
{
/// <summary>
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new OpenAPI());
}
}
}

-------------------------------------------------------------------------
Form.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.InteropServices;
using KTPCBizLib;

namespace KTOpenAPICSharpSample
{
public partial class OpenAPI : Form
{
protected bool bLogin = false;
protected bool bAlreayLogined = false;
protected string strCONCaller = "";
protected bool bCONCalling = false;

public OpenAPI()
{
InitializeComponent();

textAuthKey.Text = "AuthKey Please";
textUserID.Text = "ID Input";
textUserPW.Text = "Password Input";
textServerType.Text = "0";

textCalleeNumber.Text = "";

comboMemoType.Items.Add("Private Memo");
comboMemoType.Items.Add("Common Memo");
comboMemoType.SelectedIndex = 1;

comboGrouptype.Items.Add("Private Group");
comboGrouptype.Items.Add("Common Group");
comboGrouptype.SelectedIndex = 1;

comboCallType.Items.Add("All");
comboCallType.Items.Add("Send");
comboCallType.Items.Add("Receive");
comboCallType.Items.Add("Absent");
comboCallType.Items.Add("Fail");
comboCallType.Items.Add("Reserve");
comboCallType.Items.Add("Mobile");
comboCallType.SelectedIndex = 0;

comboSmsType.Items.Add("All");
comboSmsType.Items.Add("Send");
comboSmsType.Items.Add("Receive");
comboSmsType.Items.Add("Absent");
comboSmsType.Items.Add("Fail");
comboSmsType.Items.Add("Reserve");
comboSmsType.Items.Add("Mobile");
comboSmsType.SelectedIndex = 0;

comboAdBirthdaytype.Items.Add("Lunar");
comboAdBirthdaytype.Items.Add("Calendar");
comboAdBirthdaytype.SelectedIndex = 1;

comboAdType.Items.Add("Private User");
comboAdType.Items.Add("Common User");
comboAdType.SelectedIndex = 1;

cbState.SelectedIndex = 0;

}

/// <summary>
/// Login
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLogin_Click(object sender, EventArgs e)
{
if (textAuthKey.TextLength == 0 ||
textUserID.TextLength == 0 ||
textUserPW.TextLength == 0 ||
textServerType.TextLength == 0 )
{
MessageBox.Show("Lack of Login Data!!");
return;
}

int nLoginResult = axKTPCBizX1.Login(Convert.ToInt32(textServerType.Text),
textAuthKey.Text,
textUserID.Text,
textUserPW.Text);


switch (nLoginResult)
{
case 200 :
textConnectState.Text = "Connected!";
break;
case 301 :
textConnectState.Text = "Double Login at another PC";
bAlreayLogined = true;
break;
case 0 :
default :
textConnectState.Text = "Failure";
break;
}
}
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by AntoninoP »

It is a very hard task, 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 8)

For now, what you can do is look at http://www.codeproject.com/Articles/632 ... in-plain-C
That personally combine with http://www.codeproject.com/Articles/184 ... teInstance (I prefer don't register dll that are not essential)

So, following the fist link (point 3) you can create KTOpenAPI.h and KTOpenAPI_i.c, then use them in code like this:

Code: Select all

#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
Here is missing the code to unload the dll.

If I run it, it says that KTPSock.dll is missing...
Last edited by AntoninoP on Fri Jul 03, 2015 10:27 am, edited 1 time in total.
User avatar
kim yong woo
Posts: 55
Joined: Sun Apr 12, 2009 10:51 am
Location: Seoul, Korea
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by kim yong woo »

Thanks so much for your supports, and sorry for missing KTSock.dll

KTSock.dll is included in following link.

http://pharmalink.kr/images/dll.zip

After following your advice, I will post results.

Thanks.. Thanks...
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by Antonio Linares »

Antonino,

Great code! :-)

Thank you for your great help!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by Daniel Garcia-Gil »

Hello

a simple tip

harbour support a pointer parameter to communicate between high and low level, is very useful to avoid #define _win64

example
use hb_rerptr( (void*) pValue ) to send at HIGH LEVEL
use hb_parptr( nParams ) to recibe in LOW LEVEL

Code: Select all

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();
}
 
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by hua »

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 8)
Antonino, I'm sure it would be a great and appreciated tool to have :D
FWH 11.08/FWH 19.03
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by AntoninoP »

Daniel Garcia-Gil wrote:use hb_rerptr( (void*) pValue ) to send at HIGH LEVEL
use hb_parptr( nParams ) to recibe in LOW LEVEL
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.
I made a sin of copy and paste from FiveWin's source code :twisted:
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by Antonio Linares »

When FWH was built those functions did not exist

Later on we could have modified FWH code to use them, and we don't
discard to do it in the future.

Anyhow FWH current code works very well :-)

but its true that we could remove those ifdefs and use those functions
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by nageswaragunupudi »

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.
Mr Antonino

Do you mean to say the sizes of int and pointer on 64-bit OS also is the same?

This is what I thought till now:
On 32-bits, sizes of int, long and pointer are all 4 bytes only.
But on 64-bits size of int is still 4 bytes where as long and pointer are 8 bytes.
Therefore size of int is not the same as size of pointer on 64-bits. So we can not us hb_parni and hb_retni for pointers on 64-bits.

I seek clarification from experts like, Antonio, Daniel and AntonioP to please check and give their opinion on this for my benefit as well for the benefit of all who learn from this thread.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by Antonio Linares »

Here is a simple example to test those sizes.

To check it for 64 bits, please use FWH 64 and do build64.bat sizes:

int returns 4 and a pointer returns 8:

sizes.prg

Code: Select all

#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by nageswaragunupudi »

int returns 4 and a pointer returns 8:
Yes.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by nageswaragunupudi »

I request guidance from the experts on using hb_retptr()

I have in my C Code
HBITMAP hBmp;
I want to return the value of handle HBITMAP.

Should i write
hb_retptr( ( void * ) &hBmp ) ?
If not what is the correct way?
Regards

G. N. Rao.
Hyderabad, India
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by Antonio Linares »

This should be fine:

hb_retptr( ( void * ) hBmp );
regards, saludos

Antonio Linares
www.fivetechsoft.com
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by AntoninoP »

Apologies for everyone, I checked, and you are right:

size of int depends by the compiler, on windows it is 32bit even for 64bit application

even the strandard says: "Plain ints have the natural size suggested by the architecture of the execution environment",
:oops: :oops:

Anyway I mus say that do hb_retptr and hb_retni/hb_retnl/hb_retnll is not the same
try this:

Code: Select all

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
it write:

Code: Select all

P
N
0
so we can not substute hb_parn*/hb_retn* with hb_parptr/hb_retptr because they are 2 different things
Last edited by AntoninoP on Mon Jul 06, 2015 8:40 am, edited 1 time in total.
User avatar
kim yong woo
Posts: 55
Joined: Sun Apr 12, 2009 10:51 am
Location: Seoul, Korea
Contact:

Re: How to combine (or use) SDK dll into Fivewin HB/XHB?

Post by kim yong woo »

Dear Mr.Antonio Linares

Would you kindly upload or email to me KTOpenAPI.h and KTOpenAPI_i.c?

I am not a expert :oops: to create those things.

Thanks.

Y.W.Kim
Post Reply