|
Hi Davy,
I don't know of a SDK to do it, but switching endian's isn't a big deal. You can do the following:
<br />
typedef struct _tagByteBreak<br />
{<br />
unsigned char bUpperByte;<br />
unsigned char bMiddleByte1;<br />
unsigned char bMiddleByte2;<br />
unsigned char bLowerByte;<br />
} BYTE_BREAK;<br />
<br />
typedef union _tagEndianSwitch<br />
{<br />
BYTE_BREAK stBreak;<br />
unsigned long int ulFull;<br />
} ENDIAN_SWITCH;<br />
<br />
void UTIL_SwitchEndian (unsigned long int *pulIn)<br />
{<br />
ENDIAN_SWITCH Endian;<br />
unsigned char btemp;<br />
<br />
Endian.ulFull = *pulIn;<br />
<br />
btemp = Endian.stBreak.bLowerByte;<br />
Endian.stBreak.bLowerByte = Endian.stBreak.bUpperByte;<br />
Endian.stBreak.bUpperByte = btemp;<br />
btemp = Endian.stBreak.bMiddleByte1;<br />
Endian.stBreak.bMiddleByte1 = Endian.stBreak.bMiddleByte2;<br />
Endian.stBreak.bMiddleByte2 = btemp;<br />
<br />
*pulIn = Endian.ulFull;<br />
}<br />
This code takes a unsigned long int (32-bits) at swops the endian (either direction). Now all you need is a loop:
<br />
void ConvertEndian (unsigned long int szLen, unsigned long int *pulBuf)<br />
{<br />
for (unsigned long int i = 0; i < szLen; ++i)<br />
{<br />
UTIL_SwitchEndian (&pulBuf[i]);<br />
}<br />
}<br />
This will convert the buffer to the opposite endian system. It should be easy to modify for 16-bits.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Thanks for the thorough answer!
Greetings,
Davy
|
|
|
|
|
You have to know the layout of the buffer.
If it is just an array of numbers than you do something like what Richard suggests.
More often though the buffer is the contents of a struct or class.
In that case you have to swap the members.
e.g.
struct ST {
long l;
short s;
float f;
double d;
};
You get a buffer:
char *buff = ...;
Cast buffer to structure:
struct ST *st = (struct ST*)buff;
Swap members:
st->l = SWAP4(st->l);
st->s = SWAP2(st->s);
st->f = SWAP4(st->f);
st->d = SWAP8(st->d);
where SWAP*() swaps the specified number of bytes.
e.g.
#define SWAP2(x) ( ((x) << 8) | ((x) >> 8) )
#define SWAP4(x) ( ((x) << 24) | ((x) >> 24) | \
( ((x) & 0x0000ff00) << 8 ) | \
( ((x) & 0x00ff0000) >> 8 ) \
)
#define SWAP8(x) ( ((x) << 56) | ((x) >> 56) | \
( ((x) & 0x000000000000ff00) << 40 ) | \
( ((x) & 0x0000000000ff0000) << 24 ) | \
( ((x) & 0x00000000ff000000) << 8 ) | \
( ((x) & 0x000000ff00000000) >> 8 ) | \
( ((x) & 0x0000ff0000000000) >> 24 ) | \
( ((x) & 0x00ff000000000000) >> 40 ) \
)
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hi!
I'm having trouble using this API callback function, EnumSystemLanguageGroups.
When I compile I get this error message:
c:\Documents and Settings\bsosla\Desktop\Regional Settings Plugin\Regional Settings\Regional Settings\regionalSettingsPlugin.cpp(457): error C3861: 'EnumSystemLanguageGroups': identifier not found, even with argument-dependent lookup
Reading a little about this callback function I see that I have to include winnls.h and windows.h, adding the library kernel32.lib.
All this is done but without any results.
What am I doing wrong?
Thanks!
|
|
|
|
|
Hachaso wrote:
...error C3861: 'EnumSystemLanguageGroups': identifier not found, even with argument-dependent lookup
This is not a Visual Studio v6 error. Are you using Visual Studio v7.x instead?
Have you seen this?
Hachaso wrote:
Reading a little about this callback function I see that I have to include winnls.h and windows.h...
Actually, only winnls.h is required. You get that one by default if you are already including windows.h .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi!
Thanks for helping me!
I'm using Visual Studio .NET 2003. I guess that its version 7.
Do you think that the problem can be related to what kind of project I've started?
When I create a Win32 project, letting the Wizard create the base code, then add my lines I get no compile error. But adding the same lines to another existing project returns an error. This is why I'm wondering if it has to do with what kind of project I start?
Thanks!
|
|
|
|
|
At this point, I would compare the project settings of the one that works with the one that doesn't work.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi Again!
Thank you once more for helping me out.
I've compared and can't find any difference that would solve the problem.
I've looked at the weblink you gave me. That's the page that I've been looking at all
the time. My problem is that they explain what the function does and what the different
parameters do but they don't give you any example code.
For example, BOOL EnumSystemLanguageGroups(
LANGUAGEGROUP_ENUMPROC pLangGroupEnumProc, // callback function
DWORD dwFlags, // language groups
LONG_PTR lParam // callback parameter
);
LANGUAGEGROUP_ENUMPROC is retrieved from another function called EnumLanguageGroupsProc.
When I try, using the headerfiles needed and kernel32.lib I come to the conclusion that
It may not exist anymore. Cause it doesn't recognize it.
Could you maybe help med with some example how to implement the different parameters, so
that I can understand what I'm doing wrong.
Thanks!
|
|
|
|
|
Hachaso wrote:
I've compared and can't find any difference that would solve the problem.
I provided you two different links. They are completely different.
Hachaso wrote:
LANGUAGEGROUP_ENUMPROC is retrieved from another function called EnumLanguageGroupsProc.
Huh? LANGUAGEGROUP_ENUMPROC is a typedef from winnls.h .
Hachaso wrote:
Could you maybe help med with some example how to implement the different parameters, so
that I can understand what I'm doing wrong.
BOOL CALLBACK EnumProc(
LGRPID LanguageGroup,
LPTSTR lpLanguageGroupString,
LPTSTR lpLanguageGroupNameString,
DWORD dwFlags,
LONG_PTR lParam
)
{
return TRUE;
}
...
EnumSystemLanguageGroups(EnumProc, LGRPID_INSTALLED, 0);
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi!
Hope I'm not to much trouble.
I'm kind of new to this so thanks for all the help.
DavidCrow wrote:
Huh? LANGUAGEGROUP_ENUMPROC is a typedef from winnls.h.
I hope I understand this right:
How do I use this typedef?
LANGUAGEGROUP_ENUMPROC EnumProc; (like this ??)
Then declare the callback function:
BOOL CALLBACK EnumProc(
LGRPID LanguageGroup,
LPTSTR lpLanguageGroupString,
LPTSTR lpLanguageGroupNameString,
DWORD dwFlags,
LONG_PTR lParam
)
{
return TRUE;
}
Then send this to EnumSystemLanguageGroups:
EnumSystemLanguageGroups(EnumProc, LGRPID_INSTALLED, 0);
Is this how it is supposed to be used??
I read a remark in the page link you gave me;
This function can carry out any desired task. An application registers an EnumLanguageGroupsProc function by passing its address to the EnumSystemLanguageGroups function.
I'm really new to all this, so please explain in details.
Thanks!
|
|
|
|
|
Hachaso wrote:
How do I use this typedef?
LANGUAGEGROUP_ENUMPROC EnumProc; (like this ??)
Not necessary.
Hachaso wrote:
Is this how it is supposed to be used??
Yes, just like the code snippet I provided.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
How to share a variable between two classes?
Please give me a answer.
Thank you very much!
|
|
|
|
|
Could you be a little bit more specific ? What you mean exactly by sharing ?? Because you can have a lot of interpretations to that...
|
|
|
|
|
I would just use pointers from one class to the other. Then you can easily work on the other class' variables.
Or point to a common structure or something like this.
|
|
|
|
|
If you mean that you want to share a variable among several instances of the same class, just make the variable (I assume that it is a member variable of the class) static..
Behind every greak black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
By sharing if u mean the availability of the variable declared in one class in another, then there are two ways of doing it.
Lets say u want variables of Class A in ClassB
1)The first way is to include the header file of that ClassA into ClassB. Create an instance of ClassA and use the variables of ClassA in ClassB.make the constructor of ClassA to be public. But this contradicts the very meaning and concept of OOP. By doing this any class can create an instacne and use them to access the variables.
2)Make ClassB to be a friend of ClassA. By doing this ClassB can access the members of ClassA and no other class can do it.
hope this is what u were looking for...............
|
|
|
|
|
Define a instance of class A.
the instance can access to a variable of class B.
could I let class A inherit class B?
|
|
|
|
|
Hi everyone,
I have included C code which offers me a lot of hard coded "extern" callbacks.
My question is: Can I encapsulate these into some kind of class?
Currently I have just many of my functions for the callbacks, but to use data arround in many of the callbacks I have to use them kind of global, and I do not really like this.
Can I set the pointers for the callback to functions that are part of a class (or my instance of it)?
Let's take an easy example that would be comparable: You want to get callbacks into the current dialog's CDialog object. You receive a string and want to show it on the dialog. Would be silly to have a global handle to the window and to use this. Or to have a global string variable if another callback should work with it later on.
Could you not set a callback pointer to one of it's functions in a way like CP_Action=this.myFunction(), so I have not to mess arround?
Or can I at least bring some straightness into it without using classes? Suggestions would be great.
Thanks in advance!
|
|
|
|
|
No, callbacks cannot be in classes, they must be global.
The reason is very simple - when you use a callback function you use it's address and the address cannot exist until there is an instance of the class plus the instance of the class cannot exist until it has been created during execution.
Elaine
The tigress is here
|
|
|
|
|
Trollslayer wrote:
No, callbacks cannot be in classes
Callbacks can be in classes as long as the function is static . By making the function static you are effectivly making the function global.
As for member functions check out:
http://www.codeproject.com/cpp/FastDelegate.asp
This will give you a good idea of how member function pointers (which are my determination callbacks anyway) work.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Uff, a lot to read in the article about the member function pointers...
But I think this is exactly what I was searching for! Thanks a lot.
Kind regards,
Roland
|
|
|
|
|
|
Hi,
I used property sheets to display some texts. When I click the OK button then the function is normal - i.e. the dialog box closes normally. However if I press 'Enter' key to close the dialog box, I notice that the dialog box closes, but also sends a WM_KEYUP message. Is there any way I can avoid this?
I want even the 'Enter key' to function like clicking the 'OK' button.
Also I would like to know if there is any method to trace the messages? Everytime I try to it goes to the MFC source program which i dont desire.. I want to trace in my program itself.. is it possible?
Thanks.
ani
|
|
|
|
|
How would a WM_KEYUP message affect the scheme of things? Also note that when you click the OK button you do get the WM_LBUTTONDOWN and WM_LBUTTONUP messages.
|
|
|
|
|
Hi,
then what is the difference between clicking OK button and pressing the ENTER key? In the sense, I call this property sheet from a parent window. So after clicking OK or CANCEL in the property sheet, it closes and returns back to the parent window. Does it still carry the WM_LBUTTONDOWN OR WM_LBUTTONUP to the parent window? Also, what message is sent when pressing the ENTER key instead of clicking OK button directly? bcos these two seem to call different procedures in my case..
Thanks
ani
|
|
|
|