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

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

Postby kim yong woo » Wed Jul 15, 2015 1: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: Select all  Expand view  RUN
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: Select all  Expand view  RUN
 hr = GetClassObject(rclsid, &IID_IClassFactory, (LPVOID *)&pIFactory);

  if (!SUCCEEDED(hr))
    return hr;
 


Following is lines around 75
Code: Select all  Expand view  RUN
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.
User avatar
kim yong woo
 
Posts: 57
Joined: Sun Apr 12, 2009 10:51 am
Location: Seoul, Korea

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

Postby kim yong woo » Wed Jul 15, 2015 1:42 pm

KTOpenApi.prg
Code: Select all  Expand view  RUN
#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

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

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

Postby AntoninoP » Wed Jul 15, 2015 1: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: Select all  Expand view  RUN
"%VCINSTALLDIR%"bin\cl -TP -W3 -c /GS- /I%hdir%\include /GA %1.c

substitute with
Code: Select all  Expand view  RUN
"%VCINSTALLDIR%"bin\cl -W3 -c /GS- /I%hdir%\include /GA %1.c
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

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

Postby kim yong woo » Wed Jul 15, 2015 1: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: Select all  Expand view  RUN
Microsoft (R) Windows (R) Resource Compiler Version 6.2.9200.20789
Copyright (C) Microsoft Corporation.  All rights reserved.
 
User avatar
kim yong woo
 
Posts: 57
Joined: Sun Apr 12, 2009 10:51 am
Location: Seoul, Korea

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

Postby Antonio Linares » Wed Jul 15, 2015 5: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42120
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby AntoninoP » Thu Jul 16, 2015 8:27 am

Dear Mr.Woo,
I am really sorry, the solution is very simple,
First register their DLL ( KTOpenAPI.dll) as followings.
Code: Select all  Expand view  RUN
regsvr32 KTOpenAPI.dll

then use a code like this:
Code: Select all  Expand view  RUN
#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
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

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

Postby kim yong woo » Fri Jul 17, 2015 2: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
User avatar
kim yong woo
 
Posts: 57
Joined: Sun Apr 12, 2009 10:51 am
Location: Seoul, Korea

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 25 guests

cron