|
|
|
I have the following declaration:
TCHAR uniChar = _T("\xFEFF");
The problem is, on compile it whines that if TCHAR is 8 bits then I'm trying to put an array of chars into 1 char. How would I keep the above statement but so that if TCHAR is set to 8, it cuts off either FE or FF?
|
|
|
|
|
Hello,
You declare one variable of type TCHAR, but you try to assign an array! Try the following instead:
<br />
const TCHAR* pszUniChar = _T("\xFEFF");<br />
Hope this helps
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
If you want it to be a string, do what Bob says. If you want it to be a single character, you need to surround the Unicode character with single quotes instead of double quotes:
<br />
wchar_t uniChar = L'\xFEFF';<br />
It doesn't make sense to use TCHAR for a single character, as in a non-Unicode build it would equate to a char, which can't handle a value as large as 0xfeff.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Thx, I also noticed another problem now that my program compiles. When I open unicode files and process them, the output ends up being weird. Then when I opened the file in hex editor and compared to original I noticed that it reads the first three bytes of the unicode file (FEFF tag and the first character, except that it processes them as FF 00 FE 00 3C as opposed to FF FE 3C ) and then instead of all the other text I just see end of line characters: 00 0D 0A repeated over and over again. Any idea where my strings are disappearing to?
|
|
|
|
|
I figured out what was causing this, I needed to use CFile::typeBinary tag when opening files
|
|
|
|
|
I have the following structures and unions defined and I have created a DataHolderUnion object using new.
struct Filler
{
unsigned int f : 16 ;
} ;
struct DataHolder
{
Filler filler1 [42] ;
Filler filler2 [192] ;
Filler filler3 [192] ;
Filler filler4 [384] ;
} ;
typedef union
{
struct DataHolder data_holder ;
} DataHolderUnion ;
What I then have is an array of unsigned chars whose size matches the total size of DataHolder, so I then do:
DataHolderUnionPtr = (DataHolderUnion*) myUCharArr ;
however the data then contained in DataHolderUnionPtr is not what I expect. I have located the problem (*I think*) to the DataHolder structure and in particular to the arrays used (I found this by changing "Filler filler1 [42] ;" to 42 variables declared as:
unsigned int f1 : 16 ;
....
unsigned int f42 : 16 ;
when I did this all of the data I expected to see in each of the 'f' variables was there and correct.
So after this long winded explanation can anyone tell me if its possible to continue using an array (or similar method) in my struct or of anyways around this problem?
many thanks,
|
|
|
|
|
Hello,
I think that you have a problem with the bitfields and alignment. Your struct is aligned at 32bit (if I'm correct) and you have 16 bit sized structures. So what happens with your array is the following: you have a struct with a member of 2 bytes and a size of 4 (the alignment). So your struct is 4 bytes. Your array consist of Filler objects, which are 4 bytes. You want them to be 2 bytes, not?
Assuming that, you can one of the following things: turn off the alignment, or don't use bitfields, but just a short or a WORD instead of your struct:
#pragma pack(push, 1) // store old alignment and set new alignment of 1 byte
#pragma pack(pop) // restore aligmnent.
struct DataHolder
{
WORD filler1 [42] ;
WORD filler2 [192] ;
unsigned __int16 filler3 [192] ;
unsigned short filler4 [384] ;
};
Hope this helps
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
cheers, changing it to be a short did the trick
|
|
|
|
|
You're welcome
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Not sure if this is applicable, however you declared your members as
mcsherry wrote:
unsigned int f : 16
an unsigned int is 32 bits long, so each one takes 4 bytes. Perhaps changing these to
unsigned short f : 16
would solve your problem?
Good luck.
Karl - WK5M
PP-ASEL-IA (N43CS)
<kmedcalf@ev1.net>
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
thanks, changing it to be a short did the trick
|
|
|
|
|
I want to respond the message VK_LEFT and VK_DOWN at the same time so I can
move a object to the buttom-left coner, and I don't want to use DirectInput,
is there some way to make that, please?
劍客
賈島
十年磨一劍,
霜刃未曾試。
今日把示君,
誰有不平事?
|
|
|
|
|
|
Thank you all guys,
GetAsyncKeyState solves my probelm
劍客
賈島
十年磨一劍,
霜刃未曾試。
今日把示君,
誰有不平事?
|
|
|
|
|
On a uniprocessor machine, you won't be able to do this as messages are handled one at a time.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
since they are handled one at a time, shouldn't GetAsyncKeyState work for what he's trying to do. Since if both keys are down, one had to be pressed first, I would think this should work.
Pseudocode:
if nChar == VK_LEFT
{
If GetAsyncKeyState(VK_DOWN)
DoStuff();
}
if nChar == VK_DOWN
{
If GetAsyncKeyState(VK_LEFT)
DoStuff();
}
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
BlackDice wrote:
since they are handled one at a time, shouldn't GetAsyncKeyState work for what he's trying to do.
Having never used that function, I do not know.
Unlike the Ctrl, Alt, Windows, and Shift keys, I don't think the keyboard is going to let both the left and down arrows be pressed simultaneously. I've not verified this, however, other than trying it in a text editor. Whichever key happened to get pressed first is the direction in which the cursor moves.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
for a while, I was dabbling in DirectX game programming fundamentals. This was a simple way of making an object move diagonally by pressing a vertical and horizontal arrow key at the same time. I know that it works in that situation, so I think it should work for this one also
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
I wonder if that is specific to DirectInput (which was apparently not an option for the OP), or if it would apply to all of Windows.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Well, I wasn't actually using DirectInput. But this was more a Windows program with the keydown being handled in the message loop. Something like this:
if(GetAsyncKeyState(VK_LEFT)
m_object.left -= .01.
if(GetAsyncKeyState(VK_RIGHT)
m_object.left += .01.
if(GetAsyncKeyState(VK_UP)
m_object.top -= .01.
if(GetAsyncKeyState(VK_DOWN)
m_object.top += .01.
DrawScene();
at any time if you check the GetAsyncKeyState() function (there's also an additional parameter that escapes me right now), any key that is pressed will return true
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Uniprocessor really has nothing to do with it. Yes, the message is sent one at a time to an application, but the same happens if it's multi-processor. The message the window gets is serialized because the message queue and a single threaded window proc make it that way.
The keyboard interrupt is free to generate another scan code/send the next byte when the the interrupt handler sends the EOI (End Of Interrupt) control. This happens almost immediately after you've read the key scan code from the port.
Then the key is put into the keyboard buffer and sent off to generate the message. While that is going on, the keyboard is still a hardware device that can interrupt a thread's processing (just like anything else) based on it's current IRQL. So, even on a single processor, the next key press could be retrieved and processed all before the application ever gets dispatched the first key.
The only thing the multi-processor could do is if the first processor got caught on a disk I/O and is at high IRQL, the other processor could handle the next keyboard interrupt at the same time.
However, after the Disk I/O was done the keyboard would have gone and done it's turn before the thread was allowed to reschedule to a lower IRQL anyway. The other funny thing is that actually one processor could be delievering the current key while the other one is processing the next, so it actually could make the situation worse since if it was single processor the hardware interrupt would definately interrupt the keystroke delivery while processing the other key. This is a minor detail though, processing a scan code is farily quick.
Pressing multiple keys the keyboard ends up continously generating one of the keys usually, the last one pressed. So a series of keystrokes could be:
(Make Code) UP (Make Code) DOWN (Make Code) DOWN (Make Code) DOWN (Break Code) UP (Break Code) DOWN
So, even though both keys are pressed the second action is continous so depending on how the application handles this it could move the cursor up then continously down because the application doesn't track the UP key's state. The UP key never provided a break code (key unpress) yet.
So, it depends on how the application tracks the keyboard state. There are also special keys, I don't remember if the keyboard itself handles these or it if was solely a process done by the BIOS, but as you know certain keys maintain a "shift" type state, such as Alt, Control and Shift.
It's been a while since I wrote a keyboard filter driver though or messed with the keyboard locations in bios.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
You cannot process those messages at the same time. You can however, simulate the behaviour by using some boolean states of which key is down and which key is up:
bool m_bIsVKLeftDown, m_bIsVKRightDown;
Second, you need to process the WM_KEYDOWN[^] and WM_KEYUP[^] messages:
afx_msg void OnKeyDown(UINT nChar, UINT nRepCount, UINT nFlags)
{
switch( nChar )
{
case VK_LEFT: m_bIsVKLeftDown = true; break;
case VK_RIGHT: m_bIsVKRightDown = true; break;
}
CYourDerivedClass::OnKeyDown(nChar, nRepCount, nFlags);
}
afx_msg void OnKeyUp(UINT nChar, UINT nRepCount, UINT nFlags)
{
switch( nChar )
{
case VK_LEFT: m_bIsVKLeftDown = false; break;
case VK_RIGHT: m_bIsVKRightDown = false; break;
}
CYourDerivedClass::OnKeyUp(nChar, nRepCount, nFlags);
}
After that, you can move your window how you want depending on the different states.
Hope this helps
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
My app needs access to a drive on another system on my network - however, the system may not be powered on and therefore a permanent system mapping will be a problem at boot-up time. How can I set up a network mapping programmatically when my app starts (and premsumably drop that mapping when the app closes) ? Many thanks for help !
Doug
|
|
|
|