|
The Main dialog has a timer in it which still runs whilst the sub-dialog is open. I read in data from the parallel port, which I want the sub-dialog program to have access to, and write data out of the port.
Thanks for looking!
69 Bay
|
|
|
|
|
|
CString::GetBuffer() . Use CString::ReleaseBuffer() after using buffer.
|
|
|
|
|
no. GetBuffer() is not to convert but to get a pointer to the buffer encapsulated within the CString.
if you have to convert a CString, use the cast operators it provides instead, like (LPCTSTR) ...
|
|
|
|
|
toxcct wrote: no. GetBuffer() is not to convert but to get a pointer to the buffer encapsulated within the CString
How it is different? It returns class's NULL terminated buffer, so can be used as char* . What you would term as if not Convert?
toxcct wrote: if you have to convert a CString, use the cast operators it provides instead, like (LPCTSTR)...
It's does same thing as above, get pointer to the buffer encapuslated within CString .
|
|
|
|
|
prasad_som wrote: How it is different?
One is changeable, one is not. It's a bad design to frivolously provide access to CString 's character buffer via GetBuffer() unless it is absolutely necessary. The LPCSTR cast will suffice in most cases.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: One is changeable, one is not.
Agree. I was puzzled by " is not convert" thing. Anyway, it is one of solutions.
|
|
|
|
|
Usually you don't need that, because there is the operator LPCTSTR ( ) const; . However there is the method GetBuffer but use it with care...
hope it helps
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
In my (non-unicode) programs I do like this:
char * cp = (char *) (LPCTSTR) CString;
It's not completely safe, since cp is a non-const char *, and LPCTSTR is a const pointer.
But as long as the resulting pointer (cp in this case) is used for reading only, it's perfectly safe.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
as you said, it's not "completely safe" (actually, not safe at all... lol).
first of all, you use C-Style cast, which is deprecated for using static_cast<>()
moreover, by using (char*) after that, you remove the constness of the string return, which is very very bad ! if you have to modify a CString string, use GetBuffer(), or copy its content into your own modifiable char array.
at last, if you have to deal with the Unicode/Ansi conversion, you should use T2A()-like (in your case) macros...
|
|
|
|
|
Did you even read what I wrote?
toxcct wrote: as you said, it's not "completely safe" (actually, not safe at all... lol).
Using a const pointer as a const pointer IS perfectly safe, IMO. Any objections?
toxcct wrote: you remove the constness of the string return, which is very very bad
What I wrote:
It's not completely safe, since cp is a non-const char *, and LPCTSTR is a const pointer.
But as long as the resulting pointer (cp in this case) is used for reading only, it's perfectly safe.
toxcct wrote: if you have to modify a CString string, use GetBuffer(), or copy its content into your own modifiable char array.
Other answers covered this case. There was no need to say it again.
toxcct wrote: at last, if you have to deal with the Unicode/Ansi conversion, you should use T2A()-like (in your case) macros...
What I wrote:
In my (non-unicode) programs I do like this:
One thing though, static_cast is nice, but then again:
What I wrote:
In my (non-unicode) programs I do like this:
And I do what I want in my programs, as long as they works as expected. Which they usually does...
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Yeah, but when you have to deal with bad written functions requiring char * instead of const char * but in fact never accessing the buffer for writing, you have to do it (of course you may also rewrite the bad written functions...)!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
That goes for quite a few functions in the RTL too...
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
See Mike's FAQ[^]
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb
|
|
|
|
|
|
Hi, I am making one application using win32 and VC++.NET. I have one ‘list control’ and one ‘edit control’ in my dialog box. Now I select one item in list control and then I tried to click in edit box to write something in it, I lost selection from list control. Can I know what kind of style I have to use in my list control so it will not lost selection.
Thanks in advance.
Priyank.
|
|
|
|
|
Use LVS_SHOWSELALWAYS style while creating list control.
Or go to control poperties -->Appearance-->Always Show selection , and set it to true .
|
|
|
|
|
Thanks
|
|
|
|
|
Hello,
I have a dll which get injected into every running process.
I want all of my dll instances to share a certain char * variable.
However, even if I use the #pragma data_seg(...) definition, the variable holds the correct value only for one instance of it, which is the instance created to work with my app.
What can I do to share the variable?
Thanks in advance,
Shy.
|
|
|
|
|
Hi
Do you supply the value to the variable at the time of initialization in the shared data segment. Because your dll must be loading first of all in your process, and then in others, therefore, the shared pointer contains value correct only for your app's process.
Generally, pointer variables should not be shared among different mappings of a dll. The pointer variable will contain address pertaining to the address space of a particular process, and which will be invalid for other processes.
Pankaj
|
|
|
|
|
pnkj wrote: Do you supply the value to the variable at the time of initialization in the shared data segment?
This is my #pragma snippet:
#pragma data_seg("SHARED")<br />
char *myString = new char[100];<br />
#pragma data_seg()<br />
#pragma comment(linker, "/section:SHARED,RWS")
I also tried the following:
char myString[100];
pnkj wrote: Generally, pointer variables should not be shared among different mappings of a dll.
How would I use a string then?
Added:
I forgot to mention that I get a link error which appears only once, and if I compile again it disappears:
--------------------Configuration: HookingCore - Win32 Debug--------------------
Compiling...
HookingCore.cpp
Linking...
Creating library Debug/HookingCore.lib and object Debug/HookingCore.exp
LINK : warning LNK4039: section "SHARED" specified with /SECTION option does not exist
HookingCore.dll - 0 error(s), 1 warning(s)
|
|
|
|
|
The pointer itself may be shared among processes, but the data it points to is not. Use shared memory for that, check out CreateFileMapping() and MapViewOfFile()
|
|
|
|
|
Because this error \"SQL:Statement too long"\ i must write an SQL statement for 3 columns , because when i say CRecordset pSet;
pSet.Update(); The cause of this error ! (Update) because he is try to update all columns in my table , i have 400.000 records !
all i want is to Edit a field pSet.Edit();
My SQL statement is too long , but i dont write an SQL statement how can i short him ? or how can i write an SQL statement to retrieve just 3 columns from my table , please help me !?!?
Bravoone
|
|
|
|
|
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb
|
|
|
|
|
I think you must read a sql book else you can not write a good program
|
|
|
|