|
Hello,
i have a structure and i want to change the structure data to bytearray
struct test {
char a;
int b;
};
could any one help in this regard.
Jalsa
|
|
|
|
|
did you try with memcpy.
hope that should work for you.
but, if you can let us know the purpose, we can give better suggestions.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
I need to send the data on tcp socket before that i have MD5 the packet data data.
so i want to convert the structure data to byte.
regards
Jalsa
|
|
|
|
|
try with memcpy.
jalsa G wrote: before that i have MD5 the packet data data
can you explaing this a bit more clearer?
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Well a struct is a just bunch of (adjacent) bytes, hence you can pass the address of the struct (and the proper size) to the sending function.
Of course if endianess is a issue then you have to handle it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Also the byte alignment can sometimes cause problems.
For example with a byte alignment of 4 bytes, the following structure would be of 8 bytes length.
struct test {<br />
char a;<br />
int b;<br />
};<br />
Doing a memcpy will write 8 bytes to a byte array while the needed size is 5 bytes.
In such cases you would need a #pragma pack(1) before declaring the structure.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi if possible please try to suggest me any solution for the thread Setting Font.. which
i posted below...
|
|
|
|
|
Indeed. Anyway you may send only sizeof(char)+sizeof(int) bytes. Of course then you've to make sure sizeof(int) is the same on both the sides.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I've found the C/C++/MFC, but not found the C++ builder, does it have one for C++ builder in this website?
|
|
|
|
|
Do you mean a forum for C++ Builder? No we haven't. Anyway you try to ask your question here.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
How to read footer at a sector using C++/VC++
|
|
|
|
|
Hi!
I want to write to PE run on empty OS.
It help winAPI run on "Empty OS"
Please,full code & guide
Thanks : -D
-D -D -D -D -D -D
Vietnam.
by:tuan1111
modified on Monday, July 20, 2009 9:24 PM
|
|
|
|
|
You're not giving up, are you?
tuan1111 wrote: I'm reading bootloader
Try to read an English course first.
Alternatively, run your post through several, randomly selected languages on translate.google.com, I'm sure it will make more sense then.
tuan1111 wrote: I say the hard things I want them
What?
tuan1111 wrote: Please provide code
Let me correct that for you:
Pleeze sendz codez
|
|
|
|
|
The above post wouldn't be out of place in this site[^]
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Hello,
I'm developing an MFC application that I'd like to provide context sensitive help for. Does MFC provide such a facility? I think that .chm files are deprecated in Windows vista - something called MAML is used instead.
My questions is, what is the modern, preferred way to create context sensitive help within MFC?
Regards,
Sternocera
|
|
|
|
|
Is there anbody out there who has a working code snippet that uses WinApi function Alphablend()?
Can Alphablend() be used with a bitmap that has no alphachannel?
Thanx
modified on Sunday, June 28, 2009 5:00 AM
|
|
|
|
|
I use it on a splash screen.
header file:
typedef BOOL (WINAPI ALPHABLEND)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION);
typedef ALPHABLEND* LPALPHABLEND;
class ...
{
...
HINSTANCE m_hLib;
LPALPHABLEND m_lpfnAlphaBlend;
...
};
source file:
m_hLib = LoadLibrary(_T("msimg32.dll"));
if (m_hLib != NULL)
{
m_lpfnAlphaBlend = (LPALPHABLEND)GetProcAddress(m_hLib, "AlphaBlend");
}
if (m_hLib != NULL)
{
FreeLibrary(m_hLib);
m_hLib = NULL;
}
BOOL C*********::OnEraseBkgnd(CDC* pDC)
{
CDialog::OnEraseBkgnd(pDC);
if (m_lpfnAlphaBlend != NULL)
{
CRect rc;
GetClientRect(rc);
BITMAP b;
if (GetObject(m_hBitmap,
sizeof(BITMAP),
&b))
{
CDC DC;
DC.CreateCompatibleDC(pDC);
int s = DC.SaveDC();
DC.SelectObject(m_hBitmap);
BLENDFUNCTION bf = {0};
bf.BlendOp = AC_SRC_OVER;
bf.SourceConstantAlpha = 0x20;
m_lpfnAlphaBlend(*pDC,
(rc.Width() - b.bmWidth) / 2,
(rc.Height() - b.bmHeight) / 2,
b.bmWidth,
b.bmHeight,
DC,
0,
0,
b.bmWidth,
b.bmHeight,
bf);
DC.RestoreDC(s);
}
}
return TRUE;
}
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Tnx for an answer..
I spelled your code character by character and it seems that i do essentially the same. So this leaves me to ask you some stupid questions:
1. Is bf.BlendOp = AC_SRC_OVER; the same as: bf.BlendOp = 0; ??
2. To my opinion you do nothing to add an alpha channel to your bitmap. Thus your bitmap has no alpha channel - do you agree on that?
3. Because i use another language then you: what does int s = DC.SaveDC() ; do? Is this one essential to Alphablend?
Thanks
Rozis
|
|
|
|
|
Rozis wrote: 1. Is bf.BlendOp = AC_SRC_OVER; the same as: bf.BlendOp = 0; ??
from wingdi.h:
#define AC_SRC_OVER 0x00
Rozis wrote: 2. To my opinion you do nothing to add an alpha channel to your bitmap. Thus your bitmap has no alpha channel - do you agree on that?
From MSDN[^]:
When the AlphaFormat member is AC_SRC_ALPHA, the source bitmap must be 32 bpp. If it is not, the AlphaBlend function will fail. So you are correct, I did not worry about the alpha channel. I just set the AlphaFormat value to zero.
Rozis wrote: 3. Because i use another language then you: what does int s = DC.SaveDC() ; do? Is this one essential to Alphablend?
See http://msdn.microsoft.com/en-ca/library/dd162945(VS.85).aspx[^] and http://www.flounder.com/savedc.htm[^]
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
hmmm... im out of questions but it still doesn't run. This my code: (warning: this is not C-code, but i'll explain when needed)
hMemDC:=CreateCompatibleDC(hdc)
if hMemDC!=NULL_PTR
hbitmap:=CreatecompatibleBitmap(hdc,w,h)
hold:=SelectObject(hMemDC,hBitmap)
Rectangle(hmemDC,0,0,w,h)
blendfunc.BlendOp:=0
blendfunc.BlendFlags:=0
blendfunc.SourceConstantAlpha:=128
blendfunc.AlphaFormat:=0
AlphaBlend(hdc,x,y,w,h,hMemDC,0,0,w,h,@blendfunc)
SelectObject(hMemDC,hold)
DeleteObject(hBitmap)
DeleteDC(hMemDC)
endif
When i use StretchBlt() or BitBlt() instead it works (altough not transparent). I checked if x,y,w and h are possitive - they are. Think you may ask whats '@blendfunc'. It means 'pointer to structure'. Use this construct for years so must be correct (for example in GetClientRect()). Tried a demo-exe from the code project to find out if problem is system related - it worked ok. Checked the prototype and the structure. I must do something really stupid...
Rozis
|
|
|
|
|
Rozis wrote: Think you may ask whats '@blendfunc'. It means 'pointer to structure'.
That is the problem right there. AlphaBlend takes the structure, not a pointer to a structure, as the final parameter.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Guess what, you're right!! That was the thing i was overlooking. You're a genius!!!
Did a quick try, made 0x00800000 as the last parameter to Alphablend() and it does the job. And it is lightyears faster then the workaround i made with getpixel(). Problem solved!
The reason i never questioned it, is because a struct is a chunk of memory so i expected this would always be a pointer when used as a parameter. I mean: when a have a struct of let's say 200 bytes and use it as a parameter to a function would this mean these 200 bytes are allocated on the stack?
Saw you're living in Canada, although you have a dutch name. So whenever you are in holland, call me, i have a present for you. Thanks for taking your time.
Rozis
|
|
|
|
|
Rozis wrote: You're a genius!!!
Not really, I just read the documentation , I am just glad to be able to help.
Rozis wrote: Saw you're living in Canada, although you have a dutch name.So whenever you are in holland, call me, i have a present for you
My grandparents emigrated from Holland to Canada in the fifties. I would love to go there some day and see where my heritage comes from. Maybe when I do finally manage the trip I will try to look you up and take you up on your offer.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Hi,
i have a resource file in which i have changed the font property of the dialog to "Arial" regular
20....
then the font inside the dialog got increased...along with the text of the controls inside dialog..
and now i tried changing from the code in initDialog function like...
CFont newfont;
LOGFONT lf;
SecureZeroMemory(&lf, sizeof(lf));
lf.lfHeight = 20;
lf.lfWeight = FW_MEDIUM;
lstrcpy(lf.lfFaceName, _T("Arial"));
newfont.CreateFontIndirect(&lf);
GetDlgItem(IDC_CHECK1)->SetFont(&newfont);
GetDlgItem(IDC_STATIC)->SetFont(&newfont);
newfont.Detach();
and now when i build and see the output the look of the dialog with new font is not same and even the font looks smaller than the font of the dialog which i have tried to change manually the font property of the Dialog....
Please suggest me how can i make changes to my code so that both look similar....
modified on Friday, June 26, 2009 4:20 PM
|
|
|
|