0

I get this error in a c code of mine
error C2440: '=' : cannot convert from 'LPVOID' to 'unsigned char *

if((buffer = HeapAlloc(   
        GetProcessHeap(),    
        HEAP_ZERO_MEMORY,    
        totalBufferSize   
    )) == NULL) {   
        fprintf(stderr, "Memory allocation error\n");   
        ExitProcess(1);   
    }   

and even this
error C2440: '=' : cannot convert from 'unsigned char *' to 'LPSTR'

blocks = (WAVEHDR*)buffer;   
    buffer += sizeof(WAVEHDR) * count;   
    for(i = 0; i < count; i++) {   
        blocks[i].dwBufferLength = size;   
        blocks[i].lpData = buffer;   
        buffer += size;   
    }   

How do I solve this? I get in windows using visual tudio 2008.I have already turned off unicode setting.

2
Contributors
1
Reply
4
Views
2 Years
Discussion Span
Last Post by Moschops
0

LPSTR is a windows typedef for a void*.

To cast a pointer from one type to another, put the type you're casting it to in front of it:

(char \*) HeapAlloc( ...

This will cast the LPSTR returned from HeapAlloc to a char*.

It's up to you to make sure it's a sensible thing to do.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.