FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to combine (or use) SDK dll into Fivewin HB/XHB?
Posts: 57
Joined: Sun Apr 12, 2009 10:51 AM
Re: How to combine (or use) SDK dll into Fivewin HB/XHB?
Posted: Wed Jul 15, 2015 01:38 PM
Dear Sirs,

Came again to get help of specialists..

Compiled open1.prg with Harbour 32 bit, and MSVC 2013 Express mentioned above.
In MSVC, there was "Previous definition" Error found..

E:\vs2013exp\VC\INCLUDE\sal.h(455) : see previous definition of '_COM_Outptr_'
E:\vs2013exp\VC\INCLUDE\sal.h(352) : see previous definition of '_Out_opt_'
E:\vs2013exp\VC\INCLUDE\sal.h(314) : see previous definition of '_In_'

Deleted thos 3 line of #define(#define _COM_Outptr_,#define _Out_opt_,#define _In_)
And, compiled.

There was following error
Code (fw): Select all Collapse
open1.prg(60) : error C2664: 'HRESULT (const IID &,const IID &,LPVOID *)' : cannot convert argument 2 from 'const IID *' to 'const IID &'
        Reason: cannot convert from 'const IID *' to 'const IID'
        No constructor could take the source type, or constructor overload resolution was ambiguous
open1.prg(75) : error C2664: 'HRESULT MyCoCreateInstance(LPCTSTR,const IID &,IUnknown *,const IID &,LPVOID *)' : cannot convert argument 2 from 'const CLSID *'
to 'const IID &'
        Reason: cannot convert from 'const CLSID *' to 'const IID'
        No constructor could take the source type, or constructor overload resolution was ambiguous


Following is around line 60 of open1.prg
Code (fw): Select all Collapse
  hr = GetClassObject(rclsid, &IID_IClassFactory, (LPVOID *)&pIFactory);

  if (!SUCCEEDED(hr))
    return hr;


Following is lines around 75
Code (fw): Select all Collapse
HB_FUNC( IKTPCBIZX_NEW )
{
   IKTPCBizX* pKTPCBiz;
   //HRESULT 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 );


In compiling with Borland, there was no problem on MyCoCreateInstance(), -IKTPCBizX_New,
And, error happend with IKTPCBizX_LogIn.

But, in compiling with MSVC, there was error in MyCoCreateInstance(), -IKTPCBizX_New,...

Please kindly advise to me..

Thanks.
Posts: 57
Joined: Sun Apr 12, 2009 10:51 AM
Re: How to combine (or use) SDK dll into Fivewin HB/XHB?
Posted: Wed Jul 15, 2015 01:42 PM
KTOpenApi.prg
Code (fw): Select all Collapse
#include "fiveWin.ch"

Procedure main()
   LOCAL IKTPCBizX
   Local nTest

   CoInitialize(0)
   IKTPCBizX := IKTPCBizX_New()
       ? 1, IKTPCBizX
   if( IKTPCBizX<>0 )
     ? 2
      nTest:=IKTPCBizX_LogIn(IKTPCBizX, 0, "Example", "Antonino",  "FiveWinForum")
         ? 3
         ? nTest

      IKTPCBizX_Release(IKTPCBizX)
   endif

return

#pragma BEGINDUMP
#define CINTERFACE
#define COBJMACROS

#define _COM_Outptr_
#define _Out_opt_
#define _In_

#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;

  typedef HRESULT (__stdcall *pDllGetClassObject)(IN REFCLSID rclsid,
                   IN REFIID riid, OUT LPVOID FAR* ppv);
  pDllGetClassObject GetClassObject;

  IClassFactory *pIFactory;

  HMODULE hDll = LoadLibrary(szDllName);
  if (hDll == 0)
    return hr;

  GetClassObject = (pDllGetClassObject)GetProcAddress(hDll, "DllGetClassObject");
  if (GetClassObject == 0)
  {
    FreeLibrary(hDll);
    return hr;
  }

  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;
   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
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: How to combine (or use) SDK dll into Fivewin HB/XHB?
Posted: Wed Jul 15, 2015 01:46 PM
It is a problem of compiling in C or in C++ mode, the code is for compile in C mode.
remove the -TP option where call cl.

in buildh32.bat from FwiveWin\samples there is:
Code (dos): Select all Collapse
<div class="dos" id="{CB}" style="font-family: monospace;">"%VCINSTALLDIR%"bin\cl -TP -W3 -c /GS- /I%hdir%\include /GA %1.c</div>

substitute with
Code (dos): Select all Collapse
<div class="dos" id="{CB}" style="font-family: monospace;">"%VCINSTALLDIR%"bin\cl -W3 -c /GS- /I%hdir%\include /GA %1.c</div>
Posts: 57
Joined: Sun Apr 12, 2009 10:51 AM
Re: How to combine (or use) SDK dll into Fivewin HB/XHB?
Posted: Wed Jul 15, 2015 01:48 PM
Dear Sirs,

The KTOpenApi.prg was identical with the source compilored with Mr.AntoninP.
(without #define area)

But, there was no problem with his compilation, and error in mine.

Can this difference be generated from difference in rc.exe?
My rc.exe detail was as following..
Code (fw): Select all Collapse
Microsoft (R) Windows (R) Resource Compiler Version 6.2.9200.20789
Copyright (C) Microsoft Corporation.  All rights reserved.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to combine (or use) SDK dll into Fivewin HB/XHB?
Posted: Wed Jul 15, 2015 05:03 PM
Kim,

But, there was no problem with his compilation, and error in mine


What is exactly the error ?

Were you able to contact Daniel ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: How to combine (or use) SDK dll into Fivewin HB/XHB?
Posted: Thu Jul 16, 2015 08:27 AM
Dear Mr.Woo,
I am really sorry, the solution is very simple,
First register their DLL ( KTOpenAPI.dll) as followings.
Code (fw): Select all Collapse
regsvr32 KTOpenAPI.dll

then use a code like this:
Code (fw): Select all Collapse
#include <fiveWin.ch>

proc main()
   LOCAL IKTPCBizX, cTest
   CoInitialize(0)
   
   IKTPCBizX := win_OleCreateObject("{16AB1B2A-A22E-4FAC-92CB-84102DF5CE3D}","{5C41C7F0-BE5D-4819-A086-E13B80666454}")
   //                                ^^ ClassID  KTPCBizX                      ^^ IID of   IKTPCBizX
   
   ? 1,IKTPCBizX
   if .not. empty( IKTPCBizX )
      ? 2
      cTest := IKTPCBizX:Login( ;
               /*nServer*/666, ;
               /*sAuthKey*/"Example", ;
               /*sLoginID*/"Antonino",  ;
               /*sLoginPwd*/"password")
      ? 3, cTest
   else
      ? "error:"+win_oleErrorText()
   endif
   ? "exit"
return


Regards,
Antonino
Posts: 57
Joined: Sun Apr 12, 2009 10:51 AM
Re: How to combine (or use) SDK dll into Fivewin HB/XHB?
Posted: Fri Jul 17, 2015 02:36 PM

Dear All members,

Thanks so much for your kindness...!
I've got the solution, thanks to your supports.

Deeply appreciated...

Y.W.Kim

Continue the discussion