|
Dylan,
The GetBuffer() member function of the CString class returns the pointer to the actual character data used by the class. This can be used to directly modify the CString object data (though I think this is very dangerous).
This means the the moment you call ReleaseBuffer(), the address returned may very well be invalid.
try:
CString str = GetAt(nIndex);
LPTSTR czBuffer = str.GetBuffer(1);
strcpy(sz, czBuffer);
str.ReleaseBuffer();
Richard Chin
|
|
|
|
|
Why do you need 'char *' (LPSTR)? 'const char *' wouldn't be appropriate?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Dylan Kenneally wrote:
__forceinline void CFStrArray::GetAt(int nIndex, LPSTR sz) const{ CString str = GetAt(nIndex); sz = str.GetBuffer(1); str.ReleaseBuffer();}
This releases the buffer before you return it
you should use something like
__forceinline void CFStrArray::GetAt(int nIndex, LPSTR sz,int nCount) const<br />
{<br />
CString str = GetAt(nIndex);<br />
if (str.GetLength() < nCount)<br />
strcpy(sz,str);<br />
else<br />
{<br />
strncpy(sz,str,nCount-1);<br />
sz[nCount-1]="\0";<br />
}<br />
}
Ofcource it is now the responsibility of the calling function to reserve space for sz
|
|
|
|
|
Hi all,
which is the best place to learn about "Sound card Audio Mixers"
thankQ
|
|
|
|
|
I don't know about the best place, but you could try right here at CP[^] for starters.
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
hi all,
i want to know any character can trigger return of recv() function?
i used java to send data to VC++ client. for example, i send 5 lines to VC client and i want to have 5 times of return in recv().
what can i do?
example:
while(y=recv(pSoc->conn,buff,512,0))
{
// i want to run 5 times of this loop.
// for 5 lines of data
// e.g.
// loginlist
// Jim
// Mary
// Joe
// Ken
// 5 lines of data, want to have 5 returns in recv(), any help?
}
thanks,
jim
|
|
|
|
|
That's not how sockets work. You may get all lines in one recv() response, or one character per recv() , and your code must be able to deal with it.
|
|
|
|
|
thanks!
so, do you know how can i control when the recv() return? or, it is in random manner?
pls give me some idea!
jim
|
|
|
|
|
Hi,
I have very big Visual C++ project I undertook after the other programmer. Now, I found out irregular fatal errors. Windows write something like "....instruction on address blahblah....memory cant be written...". I really cant go through source code and find possible problems because it is really big project. So how can I fix it ?? I say again, this error is very irregular and sometimes, the program finishes its work perfectly...I am very confused. Is there any way to find the error ? I have VC++ 6.0.
Thanks in advance, any suggestion will be appreciated !
Celebrate Mr. Cesilko!
|
|
|
|
|
You'll need some automated error detection tool, like BoundsChecker or Purify. The problem smells like heap corruption or writing past the end of array.
s_k wrote:
sometimes, the program finishes its work perfectly
Forget about it. Treat your app as a 2-engine plane with first engine totally broken. Second may fail any moment now leading to disaster.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Thanks for your reply!
But, where can I get BoundsChecker, trial version, because I havent got money enough to buy commercial version...?
Celebrate Mr. Cesilko!
|
|
|
|
|
in VB theres the app path that you can tack on before the filename. How can you automatically detect your location in VC?
Thanksd,
ns
|
|
|
|
|
void getAppDir
(CString& strAppDir)
{
char* pSlash;
char szFilespec [_MAX_PATH];
::GetModuleFileName (AfxGetInstanceHandle(), szFilespec, _MAX_PATH);
pSlash = strrchr (szFilespec, '\\');
ASSERT (pSlash != NULL);
pSlash++;
*pSlash = '\0';
strAppDir = szFilespec;
} /ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Looks great! I thought I'd have to go via cfiledialog which wasnt acceptable.
Thanks so much!
|
|
|
|
|
hi
how is it possible to call an oracle procedure from my vc++ application. i have tried it with the oracle ole c++ library, but this method doesn´t work because this library isn´t maturad enough, like there are several exceptions, when i connect to the db or when i call MoveNext in a dynaset object. I have read about an solution with the ole db dataprovider from oracle, but the problem is, that this works with COM and COM+ and so it is to complicated for me, because i am not experienced in COM.
Is there any simple solution for my problem?
thanks
ownlife
|
|
|
|
|
I use ADO all the time to call Oracle stored procedures from VC++ applications.
Simply create an ADO connection, create a command object and execute it. There are some issues with returning Recordsets but these can be sorted by a few changes to the stored procedures.
Michael
Time flies like an arrow. Fruit flies like a banana
|
|
|
|
|
I have a lot of fields in my database. I want to include all but one in my search. I dont want to have to type the names of all the fields in my SQL search like this:
SELECT Aa,b,c,d....FROM Table
Is there something like
SELECT * From Table BUT NOT xyz
?
Thanks,
ns
|
|
|
|
|
nope, not possible.
But (unless the field is type text or ntext or some other blob), it's probably quicker to use * and just not use the field. If you specify a finite set of columns to return, you'll slow your query down some.
STL is a religeon. Enquiries to Reverend Christian Graus
|
|
|
|
|
Okay, thanks. I am putting my fields in a listbox, and didnt want my blob field to show up. SO ii suppose I'll test for it and exclude it while populating the box.
ns
|
|
|
|
|
You can go the lazy route and just use *. But if your blob data can be large I would consider it a worthy optimization to type out all of the fields. You could use a stored procedure to keep from having to type it multiple times.
Todd Smith
|
|
|
|
|
Great optimization observation. I'm in a catch-22 situation though - I dont know how many fields there are, or what the names are. SO I do a select * and iterate through the fields to get that info. (I populate a listctrl with the names, so I was contemplating catching the blob field name and filtering it out). I f I'm missing something obvious, I'd like to know....
Thanks,
ns
|
|
|
|
|
Try to use view instead of table for search.
|
|
|
|
|
WEll,
This means I go in search of what a view is. None of the simple SQL stuff and basic db stuff I've seen (and its very little) speaks of views. If you have any links let me know.
Thanks,
ns
|
|
|
|