|
how about you post the smallest fragment(s)/part(s) of code that demonstrate the issue - its a bit hard without seeing the function def, how you're calling it etc etc - please use the [code block] pre & /pre xml around your code as well
'g'
|
|
|
|
|
So i have two functions
void Send(Char* Input, UINT32 DisplayType)
UINT8 SwapBits(UINT8 b)
I then call
Send("Hello", 0);
Which gets the length of Input and then
for(int i=0;i < len;i++)
{
Input[i] = SwapBits(Input[i]);
}
While doing this i have WinDbg open and look at the pointer location for Input, lets say its x00500, you can see all 5 characters in Hello and their hex codes in Byte view.
Swapbits reverses the hi 4 bits for the low 4 bits in each UINT8 byte put in. It does this through a lot of bit manipulation, i dont have the code available now but it doesnt matter its not pertinent really. So instead of having a Hex of 0x25 fed in, it outputs 0x52. Sort of a ghetto encryption method.
All good so far.
Now call this again...
Send("Hello", 0);
if you look at the pointer it uses it does NOT create a new char* pointer. Instead it points to the one it made the first time at 0x500(still encrypted). Obviously passing in the bit swapped value just bit swaps it back. So swapbits outputs 0x25, from the previous example.
Every time you call Send("Hello", 0) it will point to 0x500 not knowing its been manipulated. It has to be some compiler thing trying to optimize these strings used multiple times only delcaring them in memory once, but its breaking everything.
|
|
|
|
|
Ok, I think the problem you're having is how the compiler handles string literals by default. Every sting constant such as your "Hello!" has to be stored in your .exe file. By default, I think, VC++ combines indentical string literals into one instance to save space. Most of the time, these are put into programs to be treated as constants. In your case, you're saying it's ok to modify the memory locations that hold "Hello!". Since the compiler combines all instances of "Hello!" into one, all pointers to it will point to the same block of memory. Change that memory and it's changed for all instances.
I think there's a compiler or linker flag to force code generation to not combine string literals but I couldn't find it when I looked. Maybe they did away with it since the last version I saw that had it and now you're stuck with what you're seeing.
One way around it would be to define "Hello!" once and copy it to a separate buffer each time you want to play with it.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
No, no, no, no! no.
In your example, you are sending the text as a constant - the compiler can do whatever it chooses to store/optimize constant usage. In my case something like that crashes...
What you should be doing is along the lines of:
#include <stdio.h>
#include <stdlib.h>
char *manip(char *manipMe)
{
return strrev(manipMe);
}
int main()
{
char *manipMe;
manipMe = (char*)malloc(strlen("Hello world!\n")+1);
strcpy(manipMe, "Hello world!\n");
printf("%s","Hello world!\n");
printf("%s",manip(manipMe));
printf("%s",manip(manipMe));
return 0;
}
Output:
Hello world!
!dlrow olleHHello world!
Process returned 0 (0x0) execution time : 0.031 s
Press any key to continue.
|
|
|
|
|
|
Can a DLL loaded into a memory table be used like a DLL into a file with LoadLibrary() ?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Are you wanting to know the difference between implicit and explicit linking?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I think I don't understand. The problem is that I want to avoid LoadLibrary() .
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: The problem is that I want to avoid LoadLibrary().
Then you must link implicitly.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I think I don't know the difference between implicit and explicit . I think I need an example.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: I think I need an example.
Google is your friend. See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Thanks! I've a lot to learn! ...yet...
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
LoadLibrary requires the DLL to be on the disk.
So you will need to write the contents of the memory to a disk file and then call LoadLibrary on it.
|
|
|
|
|
See the reply to David Crow
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Yes. you can load one DLL into System Memory.
|
|
|
|
|
How?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Firstly, it's far from clear what you mean by "loaded into a memory table". It sounds like your want to re-implement the loader. In general I'm not sure if this is possible from user mode. There's a lot more to getting a module into memory in a executable state then simply having the module in memory: relocating, recursively loading all dependent modules, resolving imports (building the Import Address Table, for example), etc... Even if you did do all these things (and more that I've forgotten) it's far from clear that "unusual" things, for example code that enumerated all loaded modules, would work.
Steve
|
|
|
|
|
|
Anchor and Dock properties are not available in MFC.
It is available in the .Net languages for Windows Forms.
|
|
|
|
|
tomay3000 wrote: Anchor & Dock
???
Me think they are for VS2008 ( and the MFC Feature Pack ), are you talking about the CDockingManager (class and behaviour) ?
Anyway, if you are thinking of upgrading, at least go to the latest VS2008 (fully serviced patched and with the MFC feature pack).
Max.
Watched code never compiles.
|
|
|
|
|
Visual Studio 2008 is heavy
Tomay is Back
|
|
|
|
|
Visual Studio 2010
I have my project set as a release, but of course when I run it through the IDE it runs in Debug mode.
If I run the program outside of VS2010 the app crashes when it is trying to get a COM for Common Item Dialog.

|
|
|
|
|
So what exactly is the question?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I setup my project as a release.
When I run it through VS2010, it doesn't crash.
Standalone CRASH!
When it tries to start the Common Item Dialog!
|
|
|
|
|
Can anyone suggest some good books to learn drawing in VC++?
|
|
|
|