|
teejayem wrote: I am passing 15 as the value but when i check it in the debugger it is 13045942
I don't know why that would happen.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
its wierd. everytime it is a different value. if i pass 15 it shows 1314822 in the debugger if i pass 10 it shows 13438982. I'll keep searching, mabye i might find something if i do i'll post it here.
Thanks Mark
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Without seeing your implementation, I have no idea.
How and where in the code are you checking the value?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
below is what i have for the header file. Also, i uploaded a Screenshot[^] of the implementation. i know the padright isn't correct yet but i haven't been able to test it correctly. how i am checking it is by breaking into the debugger and mouseovering the nCharsToPad. Now that i look at it furthur none of the parameters are right. The screenshot shows the values in the watch window.
namespace Server {
class StringHelper {
public:
static char* PadRight(int nCharsToPad, char *strToPad, char chPadValue);
};
}
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
That error looks like a corrupted stack to me. I would check locally declared vars (especially arrays) in the function calling your StringHelper
|
|
|
|
|
i think found out what it was (thanks to the help of you two). When i compiled it in 'release' it was messing all of the variables up when i would check them in the debugger But in debug it would look fine. At that point i knew it would have to of been something in my project settings so i went through and compared everything between 'debug' and 'release'. The culprit is in C/C++ -> Optimization -> Optimization. It was set on 'Maximize Speed (/O2)'. when i set it to 'Disabled /Od' everything looked fine. It seems like the program still works fine when the compiler is set to /O2 you just wont be able to see your variables while your debugging.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Also be careful - if your string needs to be NULL-terminated and you're not using
an ASCIIZ as a pad character...
your function doesn't NULL-terminate the string.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hey Mark, Thanks again for the help. Below is what i have for the padright function (tested it and it seems to work). It might not be the most effecient thing in the world but i'm just a little C# programmer trying to harness the power of C++. I've only been working with Unmanaged C for a week now
char* StringHelper::PadRight(int nCharsToPad, char *strToPad, char chPadValue) {
char* strPadResult;
int nCurLen = strlen(strToPad);
strPadResult = (char*)malloc(sizeof(nCharsToPad));
for (int i = 0; i <= nCharsToPad - nCurLen;i++) {
strPadResult[i] = chPadValue;
}
int nIndex = 0;
for (int j = nCharsToPad - nCurLen; j < nCharsToPad; j++) {
strPadResult[j] = strToPad[nIndex];
nIndex++;
}
strPadResult[nCharsToPad] = '\0';
return strPadResult;
}
Thanks again!
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
You're going to have problems there...
sizeof(nCharsToPad) equals 4 on a 32-bit build....is that how many bytes you want to allocate?
Even if you fix it, you need to add one char for the NULL terminator.
nCharsToPad is an ambiguous name to me...is it the number of characters to add to the string
or the desired string length?
It also looks like you're padding the left and justifying the string to the right. PadLeft sounds like a more
appropriate method name.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i see what your saying. The SizeOf is takeing the size of the actual datatype and not the actual value? to make things correct i should do
strPadResult = (char*)malloc(nCharsToPad + 1);
nCharsToPad is the total length of the string after it is padded. I guess it should be changed to make things more clear.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Yes.
Also, why did you implement a padleft when you originally asked
for a PadRight implementation?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
haha, sorry about that. I got a little confused;P. I figured Pad'Right' was when you put your pad on the left and push the orignal value to the 'Right'. I knew String.PadLeft or String.PadRight was what i was looking for in c# i just assumed padright was the one. Sorry for the confusion in this thread. Next time i'll be sure to make things more clear in the future!:->
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
teejayem wrote: how can i duplicate this in win32?
With something like:
char *padRight( char *pStr, int nLen )
{
char *pTemp = new char[nLen + 1];
sprintf(pTemp, "%-*s", nLen, pStr);
return pTemp;
} The calling function would need to delete the memory using the delete[] operator.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
See, I have this car physics simulation that uses SDL. I've placed all the lib and dll files in a sub directory and I'd like to have so that anyone can just double click the exe file and play around with it without having to copy any .dll's to the system32 directory or anywhere.
Now in the project properties > Linker > Input > Additional Dependencies I'm specifying SDL.lib (along side other libraries) and providing the relative path for SDL.lib in the project properties > Linker > General > Additional Library Directories. That works fine on my laptop because I have the SDL.dll in windows > system32 but if I copy the directory to a different computer it complains about not finding the SDL.dll and that reinstalling might help fix the problem.
So is it possible to tell it to look in a different directory than the system32 for dll's ? if so, how do I do that?
P.S. I'm using visual studio 8.
Many thanks,
Hasan.
|
|
|
|
|
|
Can LoadLibrary () help you?
I use third party dll in my programm and I dont need to copy it in system32 folder, but DO in the app folder. So you can make it running from your application folder. Or just another fixed folder and specifying it when loading.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Thanks Nelek, I'll give it a shot as soon as I get back home,
by the way, I never realised that the path of the exe is the first search path for dll's, I've been able to run the exe just by placing the SDL.dll next to the exe but I guess doing it with the LoadLibrary () would look much better.
Thanks for the help
"Low level programming is good for a programmer's soul". says John Carmack
|
|
|
|
|
Actually, as far as I know, is the actual path (when File.. Open.. it changes) the first one searched. By default is the App-Path when nothing changes it during execution time.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I eventually used the SetDllDirectory ( )... much easier than LoadLibrary ( ).
this is how it looks like:
SetDllDirectory(L"../dlls/SDL-1.2.12/lib"); // No idea what the 'L' is for
It worked out fine so thanks everybody you for the suggestion..
"Low level programming is good for a programmer's soul". says John Carmack
|
|
|
|
|
Hi!
A user maximizes the application on monitor #2 and then exits the program. When starting up again, trying to maximize the window using ShowWindow(SW_MAXIMIZE) maximizes the window on monitor #1, instead of the expected #2.
Is there any way to set the preferred/active monitor? Optimally, a subsequent call to ShowWindow(SW_MAXIMIZE) should then maximize the window on monitor #2.
Thanks and best regards
Dominik
|
|
|
|
|
Yes, use GetWindowPlacement to record the window max/min state, size, and monitor when the app exits, store the returned struct as binary data in the registry (or elsewhere), and the use SetWindowPlacement when the app boots the next time. Don't forget to handle bizarre situations as when a user discards a monitor or changes screen resolution.
|
|
|
|
|
Has anyone implemented secure IPC? I need to implement something in native code, and I need some direction.
Is there a way to have my processes dynamically generate public/private key pairs and use that kind of encryption?
|
|
|
|
|
Independent123 wrote: Is there a way to have my processes dynamically generate public/private key pairs and use that kind of encryption?
The CryptoAPI[^] tools have worked well for me. They're high level APIs
so relatively simple to use.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ah, yes! Thanks Mark, that seems to be what I need!
|
|
|
|
|
Hi friends..
Any one of you had developed the code for Integer DCT in c or C++ or in MATLAB? if so plz let have the code. I need it for my research. Plz let me share that. Thanks in advance..
Sivadanams
|
|
|
|