|
Nope.
It would be safe if your member variable were a string (Why don't you use a string ?).
Veni, vidi, vici.
|
|
|
|
|
Yes, i will use a string, just trying to get smarter about char*
I can't quite figure out why this isn't safe either:
<pre lang="c++">
func()
{
const char* test = "hello";
MyClass* my = new MyClass(test);
return my;
}
Trying to initilize the MyClass class with const char* but it does not work like this either.
|
|
|
|
|
String literals (like "hello" ) never go out of scope, hence MyClass may safely store a pointer to it.
Veni, vidi, vici.
|
|
|
|
|
I updated and changed the literal to a function which is what i have:
<pre lang="c++">
func()
{
const char* test = GetString().c_str();
std::cout << test << std::endl;
MyClass* my = new MyClass(test);
return my;
}
For some reason the initialization does not work.
|
|
|
|
|
That's wrong.
Event if 'Here test prints correct value' you shouldn't rely on it.
Veni, vidi, vici.
|
|
|
|
|
Why is it wrong? As i understand test is in func() scope and it should not go out of scope before func() exits, which is AFTER the class has been initialized with it.
|
|
|
|
|
indeed test does not go out of scope there. However the temporary (created by the string object) test points to does. So temp is a valid variable pointing to garbage.
Veni, vidi, vici.
|
|
|
|
|
CPallini wrote: Passing a reference it is usually better.
AKA, pointer. Ever seen C++ code disassembled?
==============================
Nothing to say.
|
|
|
|
|
Erudite_Eric wrote: Ever seen C++ code disassembled?
Yes, of course.
However this is not a point: the same you may say comparing a C++ program with a C one.
Veni, vidi, vici.
|
|
|
|
|
From some while, I try to setup an subitem image to an virtual listview, but I don't get it ... to setup an item image I get in follow way :
if(pItem->mask & LVIF_IMAGE)pItem->iImage = 0;
but for subitem image ? I have to mention that I set LVS_EX_SUBITEMIMAGES listview style ... thank you.
|
|
|
|
|
See here[^] for details of setting the subitem.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I read from there all, though, I don't know how to set image only for one specific column ...
|
|
|
|
|
I assume if you have added the LVS_EX_SUBITEMIMAGES property then it's just a matter of setting the appropriate status bits and links the same as for an item. Give it a try and see what happens.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi,
I have 2 apllications i.e. server and client which are communicating through socket.
The problem is this...When both application are connected to each other and I unplugged the network cable, no application gets notification. Can I get notification in anyway?
|
|
|
|
|
Hope this link will help you [^] or [^]
You can see the last comment which explains about keep-alive messages.
Every new day is another chance to change your life.
|
|
|
|
|
We are calling LoadLibary in C#. For this we have included the below code in the C# file.
[DllImport("Kernel32.dll")]
internal static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)] String lpMdoule);
We have multiple LoadLibaryW( ) calls. All of them are passing , except one. We verified the GetLastError( ). It returns 126. But the dll is physically existing in the correct path.
What could be the reason for dll failure.
|
|
|
|
|
You might get that because the DLL you are trying to load is dependent on some other DLLs which it cannot find.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
The dll's which this dll is dependent are available in the appropriate locations. Also tried verifying them in dependencyWalker. There are no dependency erros seen in it. But still the LoadLibaryW call is failing.
|
|
|
|
|
Maybe it's a "bitness" issue, are you sure you are not trying to load -directly or indirectly- a 32 bit DLL into a 64 bit process somewhere or vica versa? Altrough i supose that ahould give a different error, but who knows, maybe when trying to load a DLL which is dependent on another DLL of which it only finds the "wrong" version then it will say "module not found". Speaking of version, could it be some versioning problem? Like the DLL this module is dependent on is some incompatible verison (like, too old)?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Eh, another thing i just realized, your question is not C/C++ but rather C# related, maybe you should rather ask on the C# forum.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
This is the C/C++/MFC forum. May be you should ask in the C# forum.
Common errors are typos. So check the path again. Just to be sure: The subject of your question contains the path 'C:\abc.dll' which will fail (must be 'C:\\abc.dll').
|
|
|
|
|
Show the actual full code of your failing LoadLibrary() call, including (most importantly) the string parameter.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
V K 2 wrote: "C:\abc.dll"
You know, backslashes should be escaped in quoted strings.
[update]
I see Jochen already suggested it.
[/update]
Veni, vidi, vici.
|
|
|
|
|
Has anyone attempted to use this class and call GetWindowTextLength() to see if the control has any user-typed text in it? I often use this approach to know when to enable/disable the OK button on a dialog. If the control just has the mask in it (i.e., no user-typed text), I consider the control to be empty and thus need to disable the OK button. The problem is that GetWindowTextLength() always returns the length of the mask. I can call GetWindowText() in the EN_CHANGE handler and compare the text to the mask but it always seems to be off by one. In other words, if the mask is "___" and I type a number in that control, GetWindowText() will return "___" instead of "2__".
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|