FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour C wrapper help
Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
C wrapper help
Posted: Tue Oct 18, 2016 03:47 PM

All,

I am trying to write a C wrapper for a function. I've used the DLL command successfully for most of the functions however this function I think is going to require a C wrapper. I do have the lib for this function as well.

This particular function populates a C structure with values. I need to call the function and then return the values in C structure to my .prg. I found a sample on the forum and tried to duplicate it but have not been successful.

The error I'm getting is:

xLINK: error: Unresolved external symbol '_SMSGETPROVIDER referenced from (Testsms.obj)'.xLINK: error: Unresolved external symbol '_SMSGETPROVIDER referenced from (Testsms.obj)'.

This is a communications library named SocketTools. I've been using the DLL command version for sending emails via smtp for a few years and it works very well. I am using xHarbour. Below is my code.

Definition of function from help file.

/
INT WINAPI SmsGetProvider(
LPCTSTR lpszPhoneNumber,
LPSMSPROVIDER lpProvider
);
/

INCLUDE "fivewin.ch"

FUNCTION TestSms

SmsGetProvider( )

RETURN NIL

pragma BEGINDUMP

include <windows.h>

include <hbapi.h>

define SMS_MAXPROVIDERGUIDLEN 38

define SMS_MAXPROVIDERNAMELEN 128

define SMS_MAXCOMPANYNAMELEN 128

define SMS_MAXDOMAINNAMELEN 128

typedef struct tagSMS_PROVIDER
{
int nProviderId;
int nCountryCode;
int nRegionCode;
int nMessageLength;
char szGuid[SMS_MAXPROVIDERGUIDLEN];
char szName[SMS_MAXPROVIDERNAMELEN];
char szCompany[SMS_MAXCOMPANYNAMELEN];
char szDomain[SMS_MAXDOMAINNAMELEN];

} SMS_PROVIDER ;

HB_FUNC ( SMSGETPROVIDER )
{
SMS_PROVIDER aProvider ;

aProvider.nProviderId = hb_parnl( 1, 1 );
aProvider.nCountryCode = hb_parnl( 1, 2 );
aProvider.nRegionCode = hb_parnl( 1, 3 );
aProvider.nMessageLength = hb_parnl( 1, 4 );
hb_retnl( SMSGETPROVIDER(&aProvider) );
}

pragma ENDDUMP

Here is the .DEF contents if it helps.
LIBRARY "CSTXTAV8.DLL"

EXPORTS
SmsInitializeA @1
SmsInitializeW @2
SmsUninitialize @3
SmsEnableTraceA @4
SmsEnableTraceW @5
SmsDisableTrace @6
SmsEnumProvidersA @7
SmsEnumProvidersW @8
SmsGetErrorStringA @9
SmsGetErrorStringW @10
SmsGetFirstProviderA @11
SmsGetFirstProviderW @12
SmsGetGatewayA @13
SmsGetGatewayW @14
SmsGetLastError @15
SmsGetNextProviderA @16
SmsGetNextProviderW @17
SmsGetProviderA @18
SmsGetProviderW @19
SmsSendMessageA @20
SmsSendMessageW @21
SmsSetLastError @22

Any help greatly appreciated.

Thanks,
Randal

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: C wrapper help
Posted: Tue Oct 18, 2016 03:59 PM
First test with



aProvider.nProviderId = hb_parni( 1, 1 );
aProvider.nCountryCode = hb_parni( 1, 2 );
aProvider.nRegionCode = hb_parni( 1, 3 );
aProvider.nMessageLength = hb_parni( 1, 4 );
hb_retnl( SmsGetProvider(&aProvider) ); // C is Case sensitive

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
Re: C wrapper help
Posted: Tue Oct 18, 2016 04:34 PM

Cristobal:

Thank you for your reply. Still getting the same error.

xLINK: error: Unresolved external symbol '_SmsGetProvider referenced from (Testsms.obj)'.

Thanks,
Randal

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: C wrapper help
Posted: Tue Oct 18, 2016 04:47 PM

They have not provided any .h header file ?

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
Re: C wrapper help
Posted: Tue Oct 18, 2016 05:19 PM

Yes, there is a header file. I've added that to the top of my .prg but still get the same error message.

The header file is rather long so here is the portion of the header file that pertains to the function I'm trying to use. If you need the whole .h file let me know.

typedef struct _SMSPROVIDERW
{
INT nProviderId;
INT nCountryCode;
INT nRegionCode;
INT nMessageLength;
DWORD dwFlags;
DWORD dwReserved;
WCHAR szGuid[SMS_MAXPROVIDERGUIDLEN];
WCHAR szName[SMS_MAXPROVIDERNAMELEN];
WCHAR szCompany[SMS_MAXCOMPANYNAMELEN];
WCHAR szDomain[SMS_MAXDOMAINNAMELEN];
} SMSPROVIDERW, *LPSMSPROVIDERW;

typedef struct _SMSPROVIDERA
{
INT nProviderId;
INT nCountryCode;
INT nRegionCode;
INT nMessageLength;
DWORD dwFlags;
DWORD dwReserved;
CHAR szGuid[SMS_MAXPROVIDERGUIDLEN];
CHAR szName[SMS_MAXPROVIDERNAMELEN];
CHAR szCompany[SMS_MAXCOMPANYNAMELEN];
CHAR szDomain[SMS_MAXDOMAINNAMELEN];
} SMSPROVIDERA, *LPSMSPROVIDERA;

ifdef UNICODE

define SMSPROVIDER SMSPROVIDERW

define LPSMSPROVIDER LPSMSPROVIDERW

else

define SMSPROVIDER SMSPROVIDERA

define LPSMSPROVIDER LPSMSPROVIDERA

endif

Here are the functions defined in the .h file...

PUBLIC INT WINAPI SmsGetProviderW(
IN LPCWSTR lpszPhoneNumber,
OUT LPSMSPROVIDERW lpProvider
);

PUBLIC INT WINAPI SmsGetProviderA(
IN LPCSTR lpszPhoneNumber,
OUT LPSMSPROVIDERA lpProvider
);

ifdef UNICODE

define SmsGetProvider SmsGetProviderW

else

define SmsGetProvider SmsGetProviderA

endif

I have tried changing the function name to include A or W as above but still get the same error.

xLINK: error: Unresolved external symbol '_SmsGetProviderW referenced from (Testsms.obj)'.

Thanks,
Randal

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: C wrapper help
Posted: Wed Oct 19, 2016 08:57 AM

You have to link some libs they surely provide containing the undefined function.

EMG

Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
Re: C wrapper help
Posted: Wed Oct 19, 2016 01:56 PM

Enrico:

Thanks for your reply. They do provide a lib and dll and I am linking the library file. Here is a list of functions from the lib.

CSTXTAV8.DLL:__IMPORT_DESCRIPTOR_CSTXTAV8
CSTXTAV8.DLL:__NULL_IMPORT_DESCRIPTOR
CSTXTAV8.DLL:CSTXTAV8_NULL_THUNK_DATA
CSTXTAV8.DLL:_SmsDisableTrace@0
CSTXTAV8.DLL:_SmsEnableTraceA@8
CSTXTAV8.DLL:_SmsEnableTraceW@8
CSTXTAV8.DLL:_SmsEnumProvidersA@12
CSTXTAV8.DLL:_SmsEnumProvidersW@12
CSTXTAV8.DLL:_SmsGetErrorStringA@12
CSTXTAV8.DLL:_SmsGetErrorStringW@12
CSTXTAV8.DLL:_SmsGetFirstProviderA@8
CSTXTAV8.DLL:_SmsGetFirstProviderW@8
CSTXTAV8.DLL:_SmsGetGatewayA@12
CSTXTAV8.DLL:_SmsGetGatewayW@12
CSTXTAV8.DLL:_SmsGetLastError@0
CSTXTAV8.DLL:_SmsGetNextProviderA@8
CSTXTAV8.DLL:_SmsGetNextProviderW@8
CSTXTAV8.DLL:_SmsGetProviderA@8
CSTXTAV8.DLL:_SmsGetProviderW@8
CSTXTAV8.DLL:_SmsInitializeA@8
CSTXTAV8.DLL:_SmsInitializeW@8
CSTXTAV8.DLL:_SmsSendMessageA@12
CSTXTAV8.DLL:_SmsSendMessageW@12
CSTXTAV8.DLL:_SmsSetLastError@4
CSTXTAV8.DLL:_SmsUninitialize@0

What am I doing wrong?

Thanks,
Randal

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: C wrapper help
Posted: Wed Oct 19, 2016 02:10 PM

How are you linking the lib?

EMG

Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
Re: C wrapper help
Posted: Wed Oct 19, 2016 04:01 PM
Enrico Maria Giordano wrote:How are you linking the lib?

EMG



I'm using xBuilder so I've just added it to the project. I also tried using the command line option to make sure the lib is being linked and I get the same error.

Thanks,
Randal
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: C wrapper help
Posted: Wed Oct 19, 2016 04:35 PM

Randal,

What error do you get ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
Re: C wrapper help
Posted: Wed Oct 19, 2016 07:25 PM
Antonio Linares wrote:Randal,

What error do you get ?



xLINK: error: Unresolved external symbol '_SmsGetProvider referenced from (Testsms.obj)'.

Thanks,
Randal
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: C wrapper help
Posted: Wed Oct 19, 2016 08:29 PM

Randal,

Please modify this line:

hb_retnl( SMSGETPROVIDER(&aProvider) );

into:

hb_retnl( SmsGetProviderA(&aProvider) );

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
Re: C wrapper help
Posted: Thu Oct 20, 2016 03:51 AM
Antonio Linares wrote:Randal,

Please modify this line:

hb_retnl( SMSGETPROVIDER(&aProvider) );

into:

hb_retnl( SmsGetProviderA(&aProvider) );



I get the same error message.

xLINK: error: Unresolved external symbol '_SmsGetProviderA referenced from (Testsms.obj)'.

Randal
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: C wrapper help
Posted: Thu Oct 20, 2016 09:43 AM

The DLL is using C++ mode.

So you need to compile your C code using C++ mode

Using Borland or Microsoft this is quite easy. What C compiler are you using ?

Could you use free xHarbour ? that would easily solve it.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
Re: C wrapper help
Posted: Thu Oct 20, 2016 04:21 PM
Antonio Linares wrote:The DLL is using C++ mode.

So you need to compile your C code using C++ mode

Using Borland or Microsoft this is quite easy. What C compiler are you using ?

Could you use free xHarbour ? that would easily solve it.


Antonio:

I'm using xHarbour commercial and xCC. Is there anyway to compile this using xCC?

Thanks,
Randal