/*++ * File name: * scfuncsa.c * Contents: * Ascii version of the functions exported by scfuncs.c * Used by the perl extension * * Copyright (C) 1998-1999 Microsoft Corp. * --*/ #include #include #include #define PROTOCOLAPI #include "protocol.h" #include "tclient.h" #include "scfuncs.h" /* * External functions definitions */ #include "extraexp.h" /* * Internal functions definitions */ LPWSTR _Ascii2Wide(char *ascii); /*++ * Function: * SCConnectExA * Description: * Ascii version of SCConnectEx. Converts LPSTR params to LPWSTR * Arguments: * same as SCConnect * Return value: * the return value of SCConnect * Called by: * unknown (exported) --*/ PROTOCOLAPI LPCSTR SMCAPI SCConnectExA ( char *lpszServerName, char *lpszUserName, char *lpszPassword, char *lpszDomain, char *lpszShell, int xResolution, int yResolution, int ConnectinFlags, int Bpp, int AudioOpts, PCONNECTINFO *ppConnectData) { LPWSTR wszServerName, wszUserName, wszPassword, wszDomain; LPWSTR wszShell; LPCSTR rv = NULL; wszServerName = _Ascii2Wide(lpszServerName); wszUserName = _Ascii2Wide(lpszUserName); wszPassword = _Ascii2Wide(lpszPassword); wszDomain = _Ascii2Wide(lpszDomain); wszShell = _Ascii2Wide(lpszShell); if (wszServerName && wszUserName && wszPassword && wszDomain) rv = SCConnectEx(wszServerName, wszUserName, wszPassword, wszDomain, wszShell, // NULL is default shell xResolution, yResolution, ConnectinFlags, Bpp, AudioOpts, (PCONNECTINFO *) ppConnectData); else rv = ERR_ALLOCATING_MEMORY; if (wszServerName) free(wszServerName); if (wszUserName) free(wszUserName); if (wszPassword) free(wszPassword); if (wszDomain) free(wszDomain); if (wszShell) free(wszShell); return rv; } /*++ * Function: * SCConnectA * Description: * Ascii version of SCConnect. Converts LPSTR params to LPWSTR * Arguments: * same as SCConnect * Return value: * the return value of SCConnect * Called by: * !tclntpll.xs --*/ PROTOCOLAPI LPCSTR SMCAPI SCConnectA (char *lpszServerName, char *lpszUserName, char *lpszPassword, char *lpszDomain, int xResolution, int yResolution, PCONNECTINFO *ppConnectData) { LPWSTR wszServerName, wszUserName, wszPassword, wszDomain; LPCSTR rv = NULL; wszServerName = _Ascii2Wide(lpszServerName); wszUserName = _Ascii2Wide(lpszUserName); wszPassword = _Ascii2Wide(lpszPassword); wszDomain = _Ascii2Wide(lpszDomain); if (wszServerName && wszUserName && wszPassword && wszDomain) rv = SCConnect(wszServerName, wszUserName, wszPassword, wszDomain, xResolution, yResolution, (PCONNECTINFO *) ppConnectData); else rv = ERR_ALLOCATING_MEMORY; if (wszServerName) free(wszServerName); if (wszUserName) free(wszUserName); if (wszPassword) free(wszPassword); if (wszDomain) free(wszDomain); return rv; } /*++ * Function: * SCStartA * Description: * Ascii version of SCStart * Arguments: * same as SCStart * Return value: * return value from SCStart * Called by: * !tclntpll.xs --*/ PROTOCOLAPI LPCSTR SMCAPI SCStartA( PCONNECTINFO pConnectData, char *command) { LPWSTR wcmd; LPCSTR rv = NULL; wcmd = _Ascii2Wide(command); if (wcmd) { rv = SCStart( (PCONNECTINFO) pConnectData, wcmd); } else { rv = ERR_ALLOCATING_MEMORY; } if (wcmd) free(wcmd); return rv; } /*++ * Function: * SCCheckA * Description: * Ascii version of SCCheck * Arguments: * same as SCCheck * Return value: * return value from SCCheck * Called by: * !tclntpll.xs --*/ PROTOCOLAPI LPCSTR SMCAPI SCCheckA( PCONNECTINFO pConnectData, char *command, char *param) { LPWSTR wparam; LPCSTR rv = NULL; wparam = _Ascii2Wide(param); if (wparam) { rv = SCCheck( (PCONNECTINFO) pConnectData, command, wparam); } else { rv = ERR_ALLOCATING_MEMORY; } if (wparam) free(wparam); return rv; } /*++ * Function: * SCSendtextAsMsgsA * Description: * Ascii version of SCSendtextAsMsgs * Arguments: * same as SCSendtextAsMsgs * Return value: * return value from SCSendtextAsMsgs * Called by: * !tclntpll.xs --*/ PROTOCOLAPI LPCSTR SMCAPI SCSendtextAsMsgsA( PCONNECTINFO pConnectData, char *line) { LPWSTR wline; LPCSTR rv = NULL; wline = _Ascii2Wide(line); if (wline) rv = SCSendtextAsMsgs( (PCONNECTINFO) pConnectData, wline); else rv = ERR_ALLOCATING_MEMORY; if (wline) free(wline); return rv; } /*++ * Function: * _Ascii2Wide * Description: * Allocates buffer and converts an ascii string * to unicode * Arguments: * ascii - the input string * Return value: * pointer to converted string * Called by: * SCConnectA, SCStartA, SCCheckA, SCSendtextAsMsgsA --*/ LPWSTR _Ascii2Wide(char *ascii) { LPWSTR wszWide = NULL; INT_PTR wsize; INT_PTR ccLen; if (!ascii) goto exitpt; ccLen = strlen(ascii); wsize = (ccLen + 1) * sizeof(WCHAR); wszWide = (LPWSTR) malloc(wsize); // // MultiByteToWideChar uses an int for the character count, which is // theoretically insufficient on Win64. // if (wszWide) MultiByteToWideChar( CP_UTF8, 0, ascii, -1, wszWide, (int)(ccLen + 1)); exitpt: return wszWide; }