18,363
社区成员




BYTE *pBuffer = NULL;
int nLength = 0;
HRESULT hr=Convert( name, strlen(name), pBuffer, &nLength, CP_ACP, CP_UTF8 ); // 先传递一个空指针进去, 然函数返回所需的缓冲区大小
pBuffer = new BYTE[nLength]; // 根据返回的 nLength 分配内存
hr = Convert( name, strlen(name), pBuffer, &nLength,CP_ACP, CP_UTF8 ); // pBuffer中就是 UTF-8了
//
char *pName = new char[256];
memcpy (&pName, pBuffer, sizeof(pName));
body.name = pName;
//......//
delete []pName;
delete []pBuffer;
HRESULT Convert(char *strSource, int nSourceLength , byte *strTarget, int* pTargetLength, int sourceCodepage, int targetCodepage)
{
HRESULT hr = E_FAIL;
int len= nSourceLength;
int unicodeLen=MultiByteToWideChar(sourceCodepage,0,strSource,-1,NULL,0);
wchar_t * pUnicode;
pUnicode=new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
MultiByteToWideChar(sourceCodepage,0, strSource,-1,(LPWSTR)pUnicode,unicodeLen);
int targetLen=WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)strTarget,0,NULL,NULL);
if ( strTarget != NULL && ( targetLen + 1 <= *pTargetLength ) )
{
memset(strTarget,0,*pTargetLength);
WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)strTarget,targetLen,NULL,NULL);
hr = S_OK;
}
else
{
*pTargetLength = targetLen + 1;
}
delete []pUnicode;
return hr;
}
帮你改了一下
//
BYTE *pBuffer = NULL;
int nLength = 0;
Convert( "12345你好fg", strlen("12345你好fg"), pBuffer, &nLength,CP_ACP, CP_UTF8 ); // 先传递一个空指针进去, 然函数返回所需的缓冲区大小
pBuffer = new BYTE[nLength]; // 根据返回的 nLength 分配内存
Convert( "12345你好fg", strlen("12345你好fg"), pBuffer, &nLength,CP_ACP, CP_UTF8 ); // pBuffer中就是 UTF-8了
//
int Convert(char *str, int sourceCodepage, int targetCodepage)
{
int len=str.GetLength();
int unicodeLen=MultiByteToWideChar(sourceCodepage,0,str,-1,NULL,0);
wchar_t * pUnicode;
pUnicode=new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
MultiByteToWideChar(sourceCodepage,0,str,-1,(LPWSTR)pUnicode,unicodeLen);
BYTE * pTargetData;
int targetLen=WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,0,NULL,NULL);
pTargetData=new BYTE[targetLen+1];
memset(pTargetData,0,targetLen+1);
WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,targetLen,NULL,NULL);
char rt;
rt.Format("%s",pTargetData);
delete []pUnicode;
delete []pTargetData;
return rt;
}
extern "C" _declspec(dllexport) int SendParamter( char *IDNum, char *name )
D:\aaa\ZY_code\PhonePayment\PPcode\payment.cpp(34) : error C2228: left of '.GetLength' must have class/struct/union type
D:\aaa\ZY_code\PhonePayment\PPcode\payment.cpp(52) : error C2228: left of '.Format' must have class/struct/union type
D:\aaa\ZY_code\PhonePayment\PPcode\payment.cpp(92) : error C2440: '=' : cannot convert from 'int' to 'char *'
warning C4190: '<Unknown>' has C-linkage specified, but returns UDT 'CString' which is incompatible with C
// telpay.cpp : Defines the entry point for the DLL application: PhonePaymentService.wsdl.
// It is a program for the WSDL - Web Service linking.
#include <afx.h>
#include "stdafx.h"
#include "soapH.h"
#include "PhonePaymentServiceHttpBinding.nsmap"
#include "soapPhonePaymentServiceHttpBindingProxy.h"
#include<stdio.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" _declspec(dllexport) int SendParamter( char *IDNum, char *name )
////extern "C" _declspec(dllexport) int SendParamter(char *cardNo, char *validDate, char *cvv2 )
{
ns2__MBFRequestHeader header; //定义的header
ns3__sendPaymentInfoRequestBody body; //定义的body
ns3__sendPaymentInfoRequest request; //定义的request
ns3__sendPaymentInfoResponse response;//定义的response
_ns3__sendPaymentInfo soapinput;// 定义的输入
_ns3__sendPaymentInfoResponse soapoutput;// 定义的输出
//初始化soap
struct soap soap;
soap_init ( &soap );
const char* server = "http://192.168.100.53:9106/SuNingServiceWeb/mb"
//给输入变量赋值
header.MBServiceCode = "PHONE_PAY_SENDPAYMENTINFO";
body.IDNum = IDNum;
body.name = name;
request.MbfHeader = &header;
request.MbfBody = &body;
soapinput.input1 = &request;
char *flag = new char[256]; //soap输出的值
//调用Webservice
if(soap_call___ns1__sendPaymentInfo(&soap,server,NULL,&soapinput,&soapoutput) == 0)
{
response = *soapoutput.output1;
strcpy(flag,response.flag);
return atoi(flag);
}
else
{
soap_print_fault(&soap, stderr); // display the SOAP fault message on the stderr stream
return 2;
// exit(1);
}
//收尾
soap_destroy(&soap); // delete deserialized class instances
soap_end(&soap); // remove deserialized data and clean up
soap_done(&soap); // detach the gSOAP environment
delete []flag;
return 0;
}