|
char *BufferToHexString(char *cpBuffer, int iBufferLength )<br />
{<br />
if (iBufferLength < 0)<br />
iBufferLength = strlen(cpBuffer);<br />
<br />
char *cpRetval = new char[(iBufferLength*2)+1];<br />
if (cpRetval)<br />
{<br />
unsigned char *cpSource = (unsigned char *)cpBuffer;<br />
unsigned int iChar;<br />
<br />
char *cpDest = cpRetval;<br />
<br />
for (int iLup = 0; iLup < iBufferLength; iLup++)<br />
{<br />
iChar = *cpSource;<br />
sprintf(cpDest,"%02X",iChar);<br />
<br />
cpSource++;<br />
cpDest += 2;<br />
}<br />
<br />
*(cpRetval+(iBufferLength*2)) = 0;<br />
}<br />
<br />
return cpRetval;<br />
}
onwards and upwards...
|
|
|
|
|
Do you mean a string representing a number? Or just the hex for an aribtrary string? Use atoi() for parsing a number. To convert an arbitrary string to a hex encoded string try something like this:
CString csYourString = "Something.";<br />
CString csHex, csEditContents;<br />
int i;<br />
for (i=0; i<csYourString.GetLength(); i++)<br />
{<br />
csHex.Format("%02X", csYourString.GetAt(i));<br />
csEditContents.Append(csHex);<br />
}<br />
csEditContents will then contain "536F6D657468696E672E"
Is this what you meant?
|
|
|
|
|
The append method won't work, not a member of CString, any suggestions on a workaround
|
|
|
|
|
Oh well, stuff like Append() is the whole reason for having a class like CString.
You can write your own append code then. Its only a few lines.
|
|
|
|
|
THANKS FOR ALL THE SUGGESTIONS
|
|
|
|
|
Hi,
I m creating an add in for visual studio in C++/ATL, i have already created a button with which i want to call a dialog box. this button work but i c ant load the dialog box. so, that is what i have made: I have created a new class which herits from the CAxDialogImpl class. I have added an instance of this class as member of the CConnect class created by the VS wizard in order to create an addin. and in the OnConnection methode of CCOnnect i do MyWindow->Create(::GetActiveWindow(),0) and it doesn t work....
Can anybody help me to find my mistake?
|
|
|
|
|
Hi there,
I have a nice toll written in Delphi, and I need to make some changes to it. But I prefer C++ over Delphi, so I'd like to convert it into a C++-based project.
Does anyone have a tool to convert Delphi code into C++? I'd very appreciate it, because I just don't like converting it by hand (I'm not much of a Delphi star ).
Thank you in advanc,
Boudewijn Ector
|
|
|
|
|
Would the following cause a memory leak?
class MyClass
{
~MyClass()
{
for(short i=0; i<10; ++i)
delete *pMySt[i];
}
struct MyStruct
{
} *pMySt[10][10];
}; MyStruct objects are created properly using 'new' and correctly assigned to 'pMySt'. For example:
pMySt[i][j] = new MyStruct(); Thanks for any insight.
William
Fortes in fide et opere!
|
|
|
|
|
WREY wrote:
Would the following cause a memory leak?
Why ask? Running your code in the debugger will tell you (upon exit) if any memory was not freed.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
To add to that you should run the code in Debug Mode. by pressing F5
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
|
|
|
|
|
That was a given. Running the program in any other fashion does not invoke the debugger and thus does not show any memory leaks.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
It might be a given to you, but reading some of the other questions in here lead me to believe that we must assume nothing when posting replies
I thought some of the people I'd worked with didn't know much...
Steve S
|
|
|
|
|
True. I did consider past posts by WREY and felt that he at least had that much know-how. He does have an air of confidence about him, and thus I was willing to forgo a more detailed answer.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Occasionally when reading some of the questions I think to myself
"an MSDN search for x and y would tell you that", and then something comes along that makes me think of the things I thought I knew that just got corrected.
In quiet moments, I consider some of the comments I've read in other people's code or in documentation, such as
"lint's tiny little mind is fried!" - actual program output from a UNIX lint run
"Stop the forking loggers" - comment in /etc/init source code
"Abandon hope all ye who enter here" - seen in Emacs memory management code
and my personal favourite:
"Wisdom and informed courage count for much" - fsdb* man page
Steve S
* fsdb, for the younger generation, is a file system debugger, often used to patch a damaged filesystem to recover data, in the days when dinosaurs ruled the Earth, and Peter Norton did not grace the cover of a book.
|
|
|
|
|
You presumed I did not run the debugger, and you presumed I would not have run it in Debug Mode. How thoughtful of you.
Thank you for your presumptions.
William
Fortes in fide et opere!
|
|
|
|
|
Thanks for your reply.
I did run debug, but some of the things I saw I didn't fully understand. For example, I was looking to see if the value of certain pointers would be 0x00000000 at the conclusion of the program where breakpoints were set (that, plus any message about unfreed memory). When none of those indications were observed, I didn't know what to believe.
My decision now is to just delete all members of the array (the long way) using embedded 'for' statements.
William
Fortes in fide et opere!
|
|
|
|
|
If you can set a breakpoint (that is reached) on the delete *pMySt[i] statement, and not see a "Detected memory leaks!" message in the Debug tab of the Output window, you have no memory leaks.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Thank you again for your reply.
No "Detected memory leaks!" message was observed anywhere!!
I believe, looking for values of certain pointers was not a good thing to do. I thought those pointers would show no values (sort of equivalent to NULL) which would then indicate they were NOT pointing to anything, and therefore indicating (memory of) the array had been properly deleted.
Thanks for your help. I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
As an afterthought, I commented out the "delete" statement to which you refered, compiled and run the program over, and saw no message about any memory leak detected!!
Shouldn't I have seen a memory leak message (considering quite a number of those objects were created)?
Yes, I did run the debugger. (VC++ 6.0, using Win2K)
William
Fortes in fide et opere!
|
|
|
|
|
Well, not having everything in front of me, I may not be 100% accurate in reproducing this. I added the following to an existing project I was working on:
class CMyDialog : public CDialog
{
public:
CMyDialog();
~CMyDialog()
{
delete pMySt[0][0];
}
BOOL OnInitDialog()
{
CDialog::OnInitDialog();
pMySt[0][0] = new MyStruct();
return TRUE;
}
struct MyStruct
{
} *pMySt[10][10];
}; If the delete statement was commented out, a memory leak was indeed detected.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Any array value that you assign to needs to have delete called on it. If you need to use delete rather then using one of the various smart pointers out there, then I've found the following very helpful.
1. Always initialize all pointers to NULL.
2. Set the pointer to NULL after you call delete.
Note. it is always safe to call delete NULL, but smart pointers are much better.
BTW. it looks like you are only deleting the first 10 entries in a 121+ element array. You might just need to fix by changing your destructor loop to
for(int i=0; i
|
|
|
|
|
HI u all gurus on code project
i am a beginner in vc++ . i am trying to make a plugin like visualisation ..for wmp.I read info from msdn. but i need some more .
anybody done this kind of stuff.Can anybody give me some sample code.so that i can understand..
or suggest any link about this.
Reply me soon
rahul
|
|
|
|
|
|
I have a small dialog based code that proceeds through several dialogs to input data into a database. I have developed this on two separate machines and it works fine, when I copy the files to a third machine the code fails to open the second, or any subsequent, dialogs. I am using peekmessage to handle WM_DESTROY.
Many Thanks for any suggestions
|
|
|
|
|
This could be due to a number of reasons. Anything from invalid database connection, to differences in Operating Systems.
A little more information is needed to trace this problem down.
I Dream of Absolute Zero
|
|
|
|