Error C2440 '=' can not convert
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Error C2440 '=' can not convert

  1. #1
    Join Date
    May 2009
    Posts
    3

    Angry Error C2440 '=' can not convert

    Hi there,

    I'm trying to teach myself how to write dlls and plugins and I found an sdk and decided to write an encryption plug-in for it, here's the code:

    Code:
    // returns encrypted buffer that must be freed
    BYTE * __cdecl AESEncrypt_Encrypt(void *pInternal, BYTE *pBuffer, int nBufLen, int *pnOutBufLen)
    {
    	AESEncrypt_DATA *data = (AESEncrypt_DATA*)pInternal;
    
    	BYTE *buf;
    	int i;
    	
    	buf=(BYTE *)malloc(nBufLen);
    	data->Nk = data->Nr / 32;
    	data->Nr = data->Nk + 6;
    	data->in=pBuffer;
    	KeyExpansion(data);
    
    	Cipher(data);
    	
    	buf=data->out;  // <--- this is the line of the error
    	*pnOutBufLen=nBufLen;
    	return buf;
    }
    
    typedef unsigned char BYTE;
    
    typedef struct {
    	unsigned char Key[16];
    	int Nr;
    	int Nk;
    	int Nb;
    	unsigned char in[16], out[16], state[4][4];
    	int Rcon[255];
    
    	// The array that stores the round keys.
    	unsigned char RoundKey[240];
    } AESEncrypt_DATA;
    The error says:

    Error C2440 '=' can not convert BYTE to unsigned char [16]

    It has been driving me crazy, it's been 2 weeks and I can't figure out why or what I'm doing wrong...

    I have included the structure and the typedef as they were laid out in the SDK

    I'd greatly appreciate any help or guidance

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,885

    Re: Error C2440 '=' can not convert

    I suspect you're trying to copy the data in one array into another array. However, what that statement says is that you want to redirect the pointer. which is definitely wrong in this case (not just the type conversion---you'd lose the malloced memory too).

    Try using std::copy.

  3. #3
    Join Date
    May 2009
    Posts
    3

    Re: Error C2440 '=' can not convert

    Quote Originally Posted by Lindley View Post
    I suspect you're trying to copy the data in one array into another array. However, what that statement says is that you want to redirect the pointer. which is definitely wrong in this case (not just the type conversion---you'd lose the malloced memory too).

    Try using std::copy.
    Thanks alot Lindley, I was so caught up on doing the copying that I didn't even thing of using any of the STD functions, I ended up using memcopy and it worked beautifully, thanks for steering me towards the right solutions

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,885

    Re: Error C2440 '=' can not convert

    memcpy will work fine in this case. However, on arrays of more complex types it might not work, which is why I suggested std::copy----the latter will essentially reduce to memcpy on types where that is applicable, but it won't break on other types.

  5. #5
    Join Date
    May 2009
    Posts
    3

    Re: Error C2440 '=' can not convert

    I did not know that, thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center