What you are trying to do you can do like this (assuming width and height are the image dimensions):
CvSize size;
size.height = height;
size.width = width;
IplImage* ipl_image_p = cvCreateImage(size, IPL_DEPTH_8U, 3);
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
for (int channel = 0; channel < 3; ++channel)
*(ipl_image_p->imageData + ipl_image_p->widthStep * y + x * ipl_image_p->nChannels + channel) = pBuffer[x*y*3+channel];
However, you don't have to copy the data. You can also use your image data by IplImage (assuming pBuffer is of type char*, otherwise you need possibly to cast it):
CvSize size;
size.height = height ;
size.width = width;
IplImage* ipl_image_p = cvCreateImageHeader(size, IPL_DEPTH_8U, 3);
ipl_image_p->imageData = pBuffer;
ipl_image_p->imageDataOrigin = ipl_image_p->imageData;