|
Add the number of bits after the member names:
struct foo
{
BYTE Repaint:1;
BYTE Offset:4;
};
|
|
|
|
|
Thanks Mike, that's exactly what I was looking for. Can't think why I thought a union had something to do with it, possibly one of MS's wierd structs...
Waldermort
|
|
|
|
|
There is usefulness in using a union as well.
Below is a code snippet from my software:
union __ChannelsOn
{
BYTE Mask;
struct {
BYTE On1 : 1;
BYTE On2 : 1;
BYTE On3 : 1;
BYTE On4 : 1;
BYTE OnTOF : 1;
BYTE Unused : 1;
BYTE MasterOn: 1;
BYTE ScanOn : 1;
} Bits;
} ChannelsOn;
This is mirroring a register in some hardware I talk to. I can set the variable by twiddling individual bits: ChannelsOn.Bits.MasterOn = 1<code>, and also use it as a whole byte... <code>SendStuffToHardware (...., ChannelsOn.Mask, ....);
So, while its not a linked language construct, it's often handy.
Unions can also be usedto ensure the overall variable ends up the correct size.
Iain.
|
|
|
|
|
I am having trouble understanding what it is your trying to accomplish, however I believe you want to manipulate the bits in these bytes indirectly without accessing struct members, although I can't imagine why you would want to do this. Perhaps you have a high performance application and are attempting to shave off a few operations in a critical function.
If speed is your goal, then you should work with the fastest datatype on a 32 bit operating system, sizeof(int). On a modern Intel Core 2 Duo the following function is the fastest, you should define bit masks in your application. The function does not generate any branching op codes, quite fast.
unsigned int bitset(unsigned int bits,unsigned int mask,bool flag)
{
bits = (bits & ~mask) | (-flag & mask);
}
Best Wishes,
-Randor (David Delaune)
|
|
|
|
|
void CDisplayBody::OnNavigateComplete2(LPCTSTR strURL)<br />
{ <br />
CString pszText="<html><head><body>Hi How r u</body></head></html>";<br />
if (GetBusy())
Stop(); <br />
<br />
IDispatch * pDisp = GetHtmlDocument();<br />
if (!pDisp)<br />
return;<br />
<br />
IHTMLDocument2* pDoc;<br />
if (SUCCEEDED(pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc )))<br />
{<br />
CComBSTR bstrURL;<br />
CComVariant varDummy;<br />
pDoc->open(bstrURL, varDummy, varDummy, varDummy, NULL);<br />
<br />
SAFEARRAY *pSA;<br />
SAFEARRAYBOUND saBound = {1, 0};<br />
pSA = SafeArrayCreate(VT_VARIANT, 1, &saBound);<br />
<br />
VARIANT *pVar;<br />
CComBSTR bstrHTML = pszText;
varDummy = bstrHTML;
<br />
SafeArrayAccessData(pSA, (void**)&pVar);
pVar[0] = varDummy;
SafeArrayUnaccessData(pSA);
<br />
pDoc->write(pSA);
pDoc->close();
<br />
SafeArrayDestroy(pSA);
pDoc->Release();
<br />
}<br />
<br />
}<br />
This code is to display html in html view But the statement (IDispatch * pDisp = GetHtmlDocument();)return Null .Why ? plz help
|
|
|
|
|
Where do you use of strURL and do you want to show a html file?
|
|
|
|
|
hi every one
i wrote one mfc project and called StartService Api .
it work in windows xp correctly but in vista this Api returned 0;
please help me.
|
|
|
|
|
Did you use of GetLastError for see error information?
|
|
|
|
|
hi ,
first tell me did u start u r service under system or admin. context. i think if u start under admin context then in vista u need to give Manifest.
|
|
|
|
|
thanks of my dear friends
i fined my problem.it was in registery .
when i deleted some key in Windows registry ,my program worked correctly.
Good Luck
|
|
|
|
|
hi every one
whats the means of \\\\.\\ in path?
current directory or system directory?
please help me.
|
|
|
|
|
\\.\ is used when opening a device or device driver on the local computer. The dot is used in place of a computer name.
|
|
|
|
|
thanks dear Michal
in all windows?
(vista????)
|
|
|
|
|
|
Hello Friends.
I am Using RegEnumValue() to Obtain the Names of the Values in the Specified Registry. But Its Not Working correctly. I dont know where I am doing the mistake. According to me the code is perfectly OK. But see if u can Find any Bug and can HELP me.
When I debug the Following in Code it just Show me the Last Value Name int he Registry MyApplication while there is eight Values. I get Other Values as Empty String.(String Values).
HKEY hKey;<br />
DWORD dValue;<br />
RegOpenKey(HKEY_CURRENT_USER,L"Software\\MyApplication",&hKey);<br />
RegQueryInfoKey(hKey,NULL,NULL,NULL,NULL,NULL,NULL,&dValue,0,0,0,0);<br />
for(int i=0;i<dValue;i++)<br />
{<br />
RegEnumValue(hKey,i+0,ValueName,&size,0,0,0,0);<br />
SendMessage(hCombo,CB_ADDSTRING,(WPARAM)0,(LPARAM)ValueName);<br />
}
|
|
|
|
|
The 4th parameter to RegEnumValue() ?
lpcValueName [in/out] should be the size of the buffer before the call, after the call its the number of characters returned, being in a for loop you should be setting that before the call everytime.
|
|
|
|
|
Thnx a lot for Your Help. Now Its Woking Correctly.
|
|
|
|
|
I have a PE file a.exe, I hope that during a.exe is running, it can write some bytes to a.exe's .rdata block. If you have any idea helpful to me, please tell me, thanks a lot.
|
|
|
|
|
Why would you want to do that? The PE header is only used for the initialization of the process, once the main thread has started execution it is not used anymore.
What are you trying to do exactly, perhaps there is another method?
Waldermort
|
|
|
|
|
I am writting register part of my software. When user enter the right register code, I want to modify some Bytes in the a.exe file's to remember this. And it means I need write some bytes to the a.exe file when it is running.
|
|
|
|
|
I don't believe it is possible to modify an exe while it's running, but what you can do is use a second exe to launch the first in a suspended state, modify what you need, then set it running.
Waldermort
|
|
|
|
|
You first need to reserve space in the EXE for this, and be able to locate it code-wise, either by offset or by special signature bytes (I presume you have already done this).
I do not believe that you can modify the EXE file while it is mapped into memory (i.e. running). You should have read-only access to the EXE file, so your executable can make a copy of itself and launch that copy passing it a special command line parameter (which means run, do not copy yourself ) so that it does the real launching. I think you can then mark that copy-of-yourself with the Delete On Close flag, so that it cleans itself up when it exits. The process would work like this:
1: When launched, check for the run, do not copy yourself parameter
2a: If found, the application runs normally
2b: If not found, copy yourself (the EXE file) to a temporary location
3: Launch the temporary copy passing the run, do not copy yourself parameter
4: Flag the temporary copy for delete-on-close (lookup the FILE_FLAG_DELETE_ON_CLOSE flag)
5: Exit
Once you do this, your application's copy can modify the original EXE on disk, and whatever you change will have an effect the next time it is started.
This is also a way to handle automatic updates without a satellite or worker/helper application handling the replacing of files that are in use.
Be sure to give the temporary copy a meaningful filename, and document it, so that users do not worry when they see an unknown executable filename in Task Manager.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
So you want to modify the file while it's being used? I don't believe this is possible.
Steve
|
|
|
|
|
Hi Experts,
I want to display html in htmlview.Please tell how to use CHtmlview or give any related link.
|
|
|
|
|