To convert unsigned char to unsigned short in VC++ 
Author Message
 To convert unsigned char to unsigned short in VC++

I have a method in VC++ that receives for parameter a type unsigned char
(variable num).
Inside this method I need to load this value in a pointer of type unsigned
short.
As I make to convert it?

void CMvoipCtrl::Call(unsigned char num)
{
 CConferenceManager o_CMgr;
 o_CMgr.CreateCall (num,NULL);

Quote:
}

-----------------------------------------------

HRESULT CConferenceManager::CreateCall
(
   BSTR bstrHostAddress,
   INmConference* pINmConference
)
{
   if (m_pINmManager == NULL || pINmConference  == NULL)
       return E_FAIL;

   INmCall* pINmCall = NULL;
   HRESULT hr = m_pINmManager->CreateCall(&pINmCall, NM_CALL_DEFAULT,
                                      NM_ADDR_IP, bstrHostAddress,
                                      pINmConference);
   return hr;

Quote:
}

The parameter bstrHostAddress is indirectly a pointer to a type of data
unsigned short.

BSTR bstrHostAddress;
typedef OLECHAR* BSTR;
typedef WCHAR OLECHAR;
typedef wchar_t WCHAR;
typedef unsigned short wchar_t;
-----------------------------------------------

Thanks and Best Regards.

-----------------------------------------------
Sebastian Piccolotto



Sat, 20 Sep 2003 23:56:11 GMT  
 To convert unsigned char to unsigned short in VC++
The convenience way:

#include <atlconv.h>

 void CMvoipCtrl::Call(unsigned char num)
 {
    char szNum[2] = "\0";
    memset(szNum,num,1);
   CConferenceManager o_CMgr;
  o_CMgr.CreateCall (A2OLE(num),NULL);

 }

alternative see Win32 API "MultiByteToWideChar" and MS KnowledgeBase:
ID: Q138813
HOWTO: Convert from ANSI to Unicode & Unicode to ANSI for OLE

Andre


Quote:
> I have a method in VC++ that receives for parameter a type unsigned char
> (variable num).
> Inside this method I need to load this value in a pointer of type unsigned
> short.
> As I make to convert it?

> void CMvoipCtrl::Call(unsigned char num)
> {
>  CConferenceManager o_CMgr;
>  o_CMgr.CreateCall (num,NULL);

> }

> -----------------------------------------------

> HRESULT CConferenceManager::CreateCall
> (
>    BSTR bstrHostAddress,
>    INmConference* pINmConference
> )
> {
>    if (m_pINmManager == NULL || pINmConference  == NULL)
>        return E_FAIL;

>    INmCall* pINmCall = NULL;
>    HRESULT hr = m_pINmManager->CreateCall(&pINmCall, NM_CALL_DEFAULT,
>                                       NM_ADDR_IP, bstrHostAddress,
>                                       pINmConference);
>    return hr;
> }

> The parameter bstrHostAddress is indirectly a pointer to a type of data
> unsigned short.

> BSTR bstrHostAddress;
> typedef OLECHAR* BSTR;
> typedef WCHAR OLECHAR;
> typedef wchar_t WCHAR;
> typedef unsigned short wchar_t;
> -----------------------------------------------

> Thanks and Best Regards.

> -----------------------------------------------
> Sebastian Piccolotto



Sun, 21 Sep 2003 00:54:48 GMT  
 To convert unsigned char to unsigned short in VC++
I like to use the macros define in <ATLCONV.H>.

Search for "String Conversion Macros" in MSDN.


Quote:
> I have a method in VC++ that receives for parameter a type unsigned char
> (variable num).
> Inside this method I need to load this value in a pointer of type unsigned
> short.
> As I make to convert it?

> void CMvoipCtrl::Call(unsigned char num)
> {
>  CConferenceManager o_CMgr;
>  o_CMgr.CreateCall (num,NULL);

> }

> -----------------------------------------------

> HRESULT CConferenceManager::CreateCall
> (
>    BSTR bstrHostAddress,
>    INmConference* pINmConference
> )
> {
>    if (m_pINmManager == NULL || pINmConference  == NULL)
>        return E_FAIL;

>    INmCall* pINmCall = NULL;
>    HRESULT hr = m_pINmManager->CreateCall(&pINmCall, NM_CALL_DEFAULT,
>                                       NM_ADDR_IP, bstrHostAddress,
>                                       pINmConference);
>    return hr;
> }

> The parameter bstrHostAddress is indirectly a pointer to a type of data
> unsigned short.

> BSTR bstrHostAddress;
> typedef OLECHAR* BSTR;
> typedef WCHAR OLECHAR;
> typedef wchar_t WCHAR;
> typedef unsigned short wchar_t;
> -----------------------------------------------

> Thanks and Best Regards.

> -----------------------------------------------
> Sebastian Piccolotto



Sun, 21 Sep 2003 00:56:34 GMT  
 To convert unsigned char to unsigned short in VC++

Quote:
> #include <atlconv.h>

>  void CMvoipCtrl::Call(unsigned char num)
>  {
>     char szNum[2] = "\0";
>     memset(szNum,num,1);
>    CConferenceManager o_CMgr;
>   o_CMgr.CreateCall (A2OLE(num),NULL);

>  }

1) Nope. CreateCall accepts first parameter as BSTR, it's not OLE string. So
you have to use A2BSTR macro. Inside this macro creates BSTR string with
SysAllocStringLen, so you should cleanup it w/ SysFreeString. Or better way
is wrapper class, which automatically destroys BSTR handle.

    o_CMgr.CreateCall ( CComBSTR(num),NULL);

2) Look at
http://msdn.microsoft.com/library/partbook/Win32API_O'Reilly/ora_apip...
pic1.htm link for BSTR format description.

Regards,
Vadim.



Sun, 21 Sep 2003 02:17:51 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. To convert unsigned char to unsigned short in VC++

2. bytes to unsigned char, unsigned short, unsigned int, ...

3. Casting from unsigned char[] to unsigned short

4. Converting Unsigned Short to Unsigned long

5. How to convert unsigned long to unsigned char?

6. Converting Unsigned short to char type!

7. Sorting a Huge Unicode File use strcmp(unsigned char *, unsigned char *)

8. Sorting a Huge Unicode File use strcmp(unsigned char *, unsigned char *)

9. Sorting a Huge Unicode File use strcmp(unsigned char *, unsigned char *)

10. Converting unsigned char to signed char invokes UB?

11. converting const char* to unsigned char[1024]

12. Convert from char to unsigned char

 

 
Powered by phpBB® Forum Software