|
Not sure what is the problem with your code but this works
CString s(_T("Hello world"));
CString sout;
int nDestLen = Base64EncodeGetRequiredLength( s.GetLength());
int outLen = s.GetLength();
LPSTR encoded = new CHAR[ nDestLen];
ZeroMemory( encoded, sizeof(CHAR) * nDestLen);
LPCSTR inPtr = s;
Base64Encode((const BYTE*)inPtr, s.GetLength(), encoded, &nDestLen);
LPSTR decoded = new CHAR[ outLen + 1];
ZeroMemory( decoded, sizeof(CHAR) * (outLen+1));
Base64Decode( encoded, nDestLen, (BYTE *)decoded, &outLen);
sout = decoded;
std::cout << (LPCTSTR)sout << std::endl;
delete [] encoded;
delete [] decoded;
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Are you compiling this in a Multibyte project ? then it works.... but if I try to compile it in a UNICODE project, I get this error:
error C2440: 'initializing' : cannot convert from 'CString' to 'LPCSTR'
on the line where you set LPCSTR inPtr = s;
since s, the CString, is LPCTSTR.
I ended up using something like this, which converts the unicode to LPSTR first, but not sure if it's the best... (also on my Decode function, I needed to convert the decoded string from MultiByte back to WCHAR to get it to match the original:
//since we're unicode, first let's convert to UTF-8
int iRes = WideCharToMultiByte(CP_UTF8, NULL, csSource, csSource.GetLength()*sizeof(TCHAR), NULL, 0, NULL, NULL);
LPSTR szMultiByte = new CHAR[iRes];
iRes = WideCharToMultiByte(CP_UTF8, NULL, csSource, csSource.GetLength()*sizeof(TCHAR), szMultiByte, iRes, NULL, NULL);
//convert to b64
int iDestLen = Base64EncodeGetRequiredLength(iRes);
LPSTR szDest = new CHAR[iDestLen];
Base64Encode((BYTE*)szMultiByte, iRes, szDest, &iDestLen, NULL);
CString csDest(szDest);
delete szMultiByte;
delete szDest;
return csDest;
|
|
|
|
|
So you have a solution now or no?
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Yes, it seems ok now, thanks for the feedback.
|
|
|
|
|
|
|
Sachin .S .Potdar wrote: am looking out for a code for Encryption and Decryption of data using RC4 algorithm in VC+
try HERE[^]
Sachin .S .Potdar wrote: Student persuing Masters in Computer Application.
Where?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
hi all,
I have problem in msflexgrid, its scrolls don't take the theme of xp.
please answer me..
best regards
-- modified at 13:33 Thursday 11th May, 2006
|
|
|
|
|
How do I get notification that a button is being held down.
In my app I want a single click to advance to the next record and I want a click and hold to advance records slowly.
I was going to set a Timer in the LBUTTONDOWN while tracking in the rectangle of the button but the button eats the LBUTTONDOWN notification for the dialog.
How do I get a button to pass on the LButtonDown notification to its parent dialog? (I tried setting the Notify flag but it didn't change anything)
Thanks in advance.
Dave
I'm pretty sure I would not like to live in a world in which I would never be offended.
I am absolutely certain I don't want to live in a world in which you would never be offended.
Dave
|
|
|
|
|
|
Hi All
I have a window which auto-refreshes every 5 minutes. Now I want to,
1. Once window gets auto-refreshed I need to capture the window message. How should I do that, probably by capturing WM_REFRESH in a windows service or so?
2. Once auto-refresh message has been captured, I need to check whether window contents had been changed from previous display. How can i do that?
Many thanks for your inputs
Ramesh
|
|
|
|
|
Each time the window refreshes, you have to capture it into a bitmap then compare the bitmap with the last screen capture. So to capture the screen:
HDC hMemDC;
HBITMAP hBitmap;
HBITMAP hBitmapOld;
BITMAPINFO bmi;
LPBYTE data;
int width, int height;
RECT rc;
GetWindowRect( hwnd, &rc );
width = rc.right - rc.left;
height = rc.bottom - rc.top;
hMemDC = CreateCompatibleDC( hDC );
hBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS, (void**)&data, NULL, NULL );
hBitmapOld = (HBITMAP)SelectObject( hMemDC, hBitmap );
if( hBitmap )
{
BitBlt( hMemDC, 0, 0, width, height, hDC, 0, 0, SRCCOPY );
SelectObject( hMemDC, hBitmapOld );
}
At this point your buffer given by "data" will have the pixel contents from the screen. You will need to load the previous bitmap and compare pixels. To load a previous bitmap you can use the LoadBitmap and GetBitmapBits functions.
I hope this helps.
Deus caritas est
|
|
|
|
|
if (st_x >= 0 && st_y >= 0)
if (st_x <= dForme.Width && st_y <= dForme.Height)
//change button position
button2.SetBounds(st_x, st_y, button2.Width, button2.Height);
else
{
textBox2.Text = st_x.ToString();
textBox3.Text = st_y.ToString();
}
visual c++ position of button little code That is a little code for visual c++. That code change position of button.
is that ok ?
-- modified at 11:00 Thursday 11th May, 2006
|
|
|
|
|
|
I think yes
I see Control.SetBounds Method in (.NET Framework Class Library)
|
|
|
|
|
|
I saw one question C# here i think yesterday that of course cedric answer to the qeustion
|
|
|
|
|
xcar wrote: visual c++ position of button little code That is a little code for visual c++. That code change position of button.
Uuhhh . I didn't understand anything. Could you please rephrase your sentence ?
Ans also, post a question .
|
|
|
|
|
|
|
Hi,
i get a 32 bit RGBA Image from my firewire camera...and i want to display a gray scale image to a Picture Control with MFC!
convert function:
<br />
void CImageProcView::RGBA2Gray(char *Img1, char *Img2, unsigned int ByteSize)<br />
{<br />
for(int i = 0; i<ByteSize/4; i++)<br />
{<br />
Img2[i]=((signed char)Img1[4*i]+(signed char)Img1[4*i+1]+(signed char)Img1[4*i+2])/3;<br />
}<br />
}<br />
<br />
char *CurrentImage;<br />
char *GrayMap;<br />
CStatic m_Img1;<br />
CBitmap Bitmap1;<br />
memcpy(Current,FireCapture->FlippedBuffer,FireCapture->grabBufferSize);<br />
<br />
RGBA2Gray(CurrentImage, GrayMap, FireCapture->grabBufferSize);
<br />
Bitmap1.CreateBitmap(FireCapture->pVih->bmiHeader.biWidth, FireCapture->pVih->bmiHeader.biHeight, 1, 8, GrayMap);<br />
<br />
m_Img1.SetBitmap(Bitmap1);<br />
somthing dont work with this CStatic Picture Control;/ any idea? i think the CreateBitmap dont take the cBitsPerPel;/
bye
|
|
|
|
|
Only about the algorithm:
surfman19 wrote: void CImageProcView::RGBA2Gray(char *Img1, char *Img2, unsigned int ByteSize)
{
for(int i = 0; i {
Img2[i]=((signed char)Img1[4*i]+(signed char)Img1[4*i+1]+(signed char)Img1[4*i+2])/3;
}
}
I think that this will generate some overflows, I like more this:
Img2[i]=signed char(((int)Img1[4*i]+(int)Img1[4*i+1]+(int)Img1[4*i+2])/3);
and why signed ? Is it better using unsigned char/int ?
bye
|
|
|
|
|
<br />
the output of the camera is a RGBA32 image!<br />
<br />
CStatic m_Img1;<br />
unsigned char *ActImage;<br />
unsigned char *GrayMap;<br />
<br />
ActImage = new unsigned char[FireCapture->grabBufferSize];<br />
GrayMap = new unsigned char[FireCapture->grabBufferSize];<br />
<br />
memcpy(ActImage,FireCapture->FlippedBuffer,FireCapture->grabBufferSize);<br />
RGB2Gray(ActImage, GrayMap, FireCapture->grabBufferSize);<br />
<br />
Bitmap1.CreateBitmap(FireCapture->pVih->bmiHeader.biWidth, FireCapture->pVih->bmiHeader.biHeight,<br />
1,8,GrayMap);<br />
m_Img1.SetBitmap(Bitmap1);<br />
<br />
<br />
<br />
<br />
void CImageProcView::RGB2Gray(unsigned char *Img1, unsigned char *Img2, unsigned int ByteSize)<br />
{<br />
for(int i = 0; i<ByteSize/4; i++)<br />
{<br />
Img2[i] = ((char)Img1[4*i] + (char)Img1[4*i+1] + (char)Img1[4*i+2]) / 3;<br />
}<br />
}<br />
why could the CStatic dont display the grayscale image????hm;/
cu
|
|
|
|
|
Your loop is already wrong. Img2 is an unsigned char *, so Img2[0] refers to byte 0, Img2[1] refers to byte 1, etc. And you should be creating your bitmap using CreateDIBitmap().
void CImageProcView::RGB2Gray(unsigned char *Img1, unsigned char *Img2, unsigned int ByteSize)
{
for(int i = 0; i<ByteSize/4; i++)
{
Img2[i] = ((char)Img1[4*i] + (char)Img1[4*i+1] + (char)Img1[4*i+2]) / 3;
}
}
If you find it difficult to think in terms of bytes, you can always cast it to RGBQUAD.
void CImageProcView::RGB2Gray(unsigned char *Img1, unsigned char *Img2, unsigned int ByteSize)
{
RGBQUAD *pSource = static_cast<RGBQUAD*>(Img1);
RGBQUAD *pDest = static_cast<RGBQUAD*>(Img2);
for(int i = 0; i<ByteSize/sizeof(RGBQUAD); i++)
{
pDest[i].rgbRed = pDest[i].rgbGreen = pDest[i].rgbBlue = (pSource[i].rgbBlue + pSource[i].rgbGreen + pSource[i].rgbRed) / 3;
pDest[i].rgbReserved = 0;
}
}
|
|
|
|
|
<br />
RGBQUAD *pSource = static_cast(Img1);<br />
static cast need a type to cast!! do you mean static_cast<RGBQUAD>(Img1); ?<br />
<br />
i always get a error C2440: 'static_cast' : cannot convert from 'unsigned char *' to 'RGBQUAD'<br />
your grayscale is now 32 bit right? cant i use 8 bit?
cu
-- modified at 6:28 Friday 12th May, 2006
|
|
|
|
|