C wrapper help

C wrapper help

Postby Randal » Tue Oct 18, 2016 3: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
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: C wrapper help

Postby cnavarro » Tue Oct 18, 2016 3: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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: C wrapper help

Postby Randal » Tue Oct 18, 2016 4: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
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: C wrapper help

Postby cnavarro » Tue Oct 18, 2016 4: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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: C wrapper help

Postby Randal » Tue Oct 18, 2016 5: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
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: C wrapper help

Postby Enrico Maria Giordano » Wed Oct 19, 2016 8:57 am

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: C wrapper help

Postby Randal » Wed Oct 19, 2016 1: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
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: C wrapper help

Postby Enrico Maria Giordano » Wed Oct 19, 2016 2:10 pm

How are you linking the lib?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: C wrapper help

Postby Randal » Wed Oct 19, 2016 4: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
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: C wrapper help

Postby Antonio Linares » Wed Oct 19, 2016 4:35 pm

Randal,

What error do you get ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C wrapper help

Postby Randal » Wed Oct 19, 2016 7:25 pm

Antonio Linares wrote:Randal,

What error do you get ?



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

Thanks,
Randal
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: C wrapper help

Postby Antonio Linares » Wed Oct 19, 2016 8:29 pm

Randal,

Please modify this line:

hb_retnl( SMSGETPROVIDER(&aProvider) );

into:

hb_retnl( SmsGetProviderA(&aProvider) );
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C wrapper help

Postby Randal » Thu Oct 20, 2016 3: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
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: C wrapper help

Postby Antonio Linares » Thu Oct 20, 2016 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C wrapper help

Postby Randal » Thu Oct 20, 2016 4: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
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

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

cron