|
Hi, I have a working spin control counting in hex. The problem is the format in which the hex is displayed.
Let me explain. The buddy edit-control displays '0x0000' and I need it to display '0x00'. How can I do this? Is there a function to format the buddy control?
Do I have to use the buddy control's member functions to .Get... the data( ie: 0x0000), alter it and then .Set... the data( ie: 0x00)?
Ideally, I'd like a know of any methods that set the format of the buddy control via the spin control's interface.
Thanks a bunch.
Carl
|
|
|
|
|
I have an app that creates a mutex (to ensure only one instance of it is running). While testing the app, it crashed without having the chance to go through its usual cleanup code (which includes a call to ReleaseMutex()). So, the mutex stayed in memory, and I couldn't re-launch my app without a reboot.
Surely there's better ways to get rid of an orphaned mutex?
|
|
|
|
|
Presuming an instance of your app is already running, it would prevent the second instance from starting up, which is probably working correctly, right?
How is it that you know the mutex is orphaned? I should think if a single instance of the app is running, the mutex would automatically be closed.
When a process terminates, it takes (almost) all the handles it created with it. This may not happen immediately nor with every type of handle. But for most, the system will automatically detect such a situation and do the cleanup.
Bikram Singh
|
|
|
|
|
> Presuming an instance of your app is already running, it would prevent the
> second instance from starting up, which is probably working correctly, right?
Yes. That's the whole reason I'm using mutexes in this app--one of the first things it does at startup is verify whether it can create a mutex. If it fails to do that, then it assumes another instance is already running, so it shuts down immediately so it won't interfere with the other copy's operations.
> How is it that you know the mutex is orphaned? I should think if a single
> instance of the app is running, the mutex would automatically be closed.
Microsoft's old WINOBJ.EXE says so. I can see my mutex under BaseNamedObjects still listed after my app dies.
> When a process terminates, it takes (almost) all the handles it created with
> it. This may not happen immediately nor with every type of handle. But for
> most, the system will automatically detect such a situation and do the
> cleanup.
That's what I was hoping, and has always been my assumption.
<edit>
It turns out that the situation is a little more convoluted than I first thought. It appears that another DLL elsewhere in the system obtained the mutex (through OpenMutex() rather than CreateMutex()), but never released it. That DLL is called by a service, and never got released. So, when the EXE shut down--cleanly or not--the mutex survived.
When I stopped the service, the DLL unloaded and the mutex died along with it. The problem was with the DLL--it tried to open the mutex, but never released it if it managed to open it...
Just so I can keep this in mind in the future--do you know of any situation were it is possible for a mutex to be *truly* orphaned?
|
|
|
|
|
No, but another thing you can try is to OPEN the mutex in your app, and if that fails, CREATE it.
If you can OPEN the mutex, you might try to wait on it for a very short while, and if you can, then you own it, and you do not have to 'release' it until your app quits or dies.
Now, if you open it and try to aquire the mutex, but you get MUTEX_ABANDONED return result, your previous instance is gone, even though the mutex still exists.
If you try to aquire it and get WAIT_FAILED, then something else still has hold of the mutex (probably another instance of your app). You can choose to wait a few seconds (if you are allowed) and try again, in case other instance is in process of shutting down.
By the way, you might want to also consider Josehp NEwcomer's dialog on the mutexes, because how you name it can have sever impact on muiutple isntances fo your progrma under terminal services and Widnows XP. You REALLY have to be careful to determine exactly what you want.
Anyhow, trying to aquire the mutex as well as open or create it might be better long run, in case another process, like a diagnostic tool, has a handle open to the mutex, but is not necessarily indicative of your specific process running (it should be unlikely an unknown application will attempt to aquire your mutex).
You TOTALLY must read this first...
http://www.flounder.com/nomultiples.htm
|
|
|
|
|
Thanks Blake. I've been using the method I've described for a good while and never really ran into any problem, but my usage scenarios have always been rather straightforward. I'll look into the URL you posted.
|
|
|
|
|
I am having a bit of trouble running CInternetFile::WriteString() and seeing results appear on the server file I am trying to change.
Here is a snipet of code that open the HTTP Connection, then opens a CInternetFile pointer then sends a request to write data (I hope). "strData" is the data I am sending.
<code>
pServer = session->GetHttpConnection("www.myserver.com", 80, "username", "password");
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, "/folder/file.txt");
pFile->SendRequestEx(strData.GetLength());
pFile->QueryInfoStatusCode(dwRet);
pFile->WriteString(strData);
pFile->EndRequest();
</code>
Does anyone see any problems with what I have here? I am kinda basing this off an example I found but the file I am trying to write to is not affected. The permissions on the file are set to a+rwx but I am wondering if there is something in the code I am missing or perhaps on the server. I can read from the file just fine. I just can't write to it.
Thanks!
|
|
|
|
|
In my program, I want to set some net configuration through a dialog, and I create a IP control in it with classwizad. but when I set the ip control's value or get it, there is always an error. I guess it is caused by that I don't initialize the control. then i use the create() function to initialize it, but it is still error. Why? how should i do.
|
|
|
|
|
give us a piece of your code...
TOXCCT >>> GEII power
|
|
|
|
|
I have just find the solution. It's so simple. but still thanks.
|
|
|
|
|
Hi all,
I have following code sample
SetLastError(0)
m_lpPrevWindowProc = SetWindowLong(m_MainWindowHandle,GWL_WNDPROC,(long)OnSubClassProc);
DWORd err = GetLastError() // err = 0;
the return value is negative, and i am not sure whether it is correct return code or a false return code.
Whether its a correct Return code or FALSe,
if its correct then why its giving negative value.
Thanks in Advance.
Abhishake
|
|
|
|
|
From the MSDN :
"Return Value
If the function succeeds, the return value is the previous value of the specified 32-bit integer.
If the function fails, the return value is zero. To get extended error information, call GetLastError .
If the previous value of the specified 32-bit integer is zero, and the function succeeds, the return value is zero, but the function does not clear the last error information. This makes it difficult to determine success or failure. To deal with this, you should clear the last error information by calling SetLastError(0) before calling SetWindowLong. Then, function failure will be indicated by a return value of zero and a GetLastError result that is nonzero."
so, your call seems to be correct...
TOXCCT >>> GEII power
|
|
|
|
|
now I want to get record from a table in Access,my codes as below:
CString strHostID;
strHostID.Format("%d",HostID);
CString strSQL;
strSQL = "select HostID,AppPath,iif(TimeSpan >= 60, str(int(TimeSpan/60)) + ' Min' + str(TimeSpan Mod 60) + 'Sec',str(TimeSpan) + 'Sec') from LogRecordTotalResultTemp Where HostID="+strHostID;
adoRS.GetValueString(strTempHostID,"HostID");
adoRS.GetValueString(strAppPath,"AppPath");
adoRS.GetValueString(strTimeSpan,"TimeSpan");//Error happened
and if I Execute this SQL sentence:
strSQL = "select HostID,AppPath,TimeSpan from LogRecordTotalResultTemp Where HostID="+strHostID;
All Right,Why?
|
|
|
|
|
Hi,
I've been designing this application as an MDI application, but now it seems it doesn't need to be (customer requirements changed).
What's the quickest way to convert it to an SDI application?
If it's a long story, I'd appreciate it if you can point me to some relevant article(s) on the net.
Thanks in advance.
Have no fear of perfection - You will never reach it
|
|
|
|
|
You don't need an article for this if you haven't done anything fishy
Create a new SDI-project with the desired name. Move over the document and view files ( ProjectNameDoc.cppm ProjectNameDoc.h, ProjectNameView.cpp and ProjectNameView.h) from the original project. Voilà!
Then, you'll of course have to copy and add all the other files you've added to the MDI-project, as well as the resources...
|
|
|
|
|
I was rather thinking of creating a new sdi project with the same name, and incorporating the differences into my mdi app, but I was looking for pointers as to what is different, rather than finding out myself.
The reverse process that you are suggesting seems much more tedious, since there's a lot of code and resources to be copied onto the new project.
Have no fear of perfection - You will never reach it
|
|
|
|
|
The document and view are the same for SDIs and MDIs. Actually, the only run-time difference is the view OnInitialUpdate , where SDIs reuse the call (and you can test for the function being run a second time if you, for example, create controls in it).
As for copying classes and resources, how long time can copying the files and inserting them take You can - if you use MSVC++ 6.0 - open the two resource files and drag the contents from one to the other. All in all a few minutes work, I'd say. Far quicker than rewriting the MDI app. If you want that aggravation, however, you'll have to rewrite stuff in both the application class and the main frame, merge the mainframe and the mdi menus into one, remove the child frame, just to mention what pops up as I write - a far more involved process.
Trust me, do as I suggest Even if you have lots of libs and special settings in the project file, it will be far easier.
|
|
|
|
|
Hello,
I'd like to make a sort of image editing application.
I want to show bmp image,
draw free line by GDI brush on the new layer,
and output only this layer to the bmp file.
It is a like photoshop layer function.
How could I get some information for this application.
Please answer this question.
|
|
|
|
|
Paint the bitmap as a background and store the brush strokes as an array of points. When you save, redraw these points to a memdc, extract the bitmap from the memdc and write it. You may want to consult the good old Scribble sample app for details on how to save and draw the points.
onwards and upwards...
|
|
|
|
|
I need to use several classes like:
CString , CRecordset and e.t.c.
What should I do to include them?
|
|
|
|
|
no way.
use other classes that the WinAPI provides
TOXCCT >>> GEII power
|
|
|
|
|
Include MFC support in your project.
Or....
Dont use them.
Simple. Some of the smaller classes you can actually copy and paste into Win32 code and they work with a bit of tweaking. But there is much more to MFC than a bunch of classes that can be used independatly of the framework im affraid... So you either use MFC, or you dont.
The best bet is to forgo MFC ....
For CString - id just use std::string or one of the billion other string classes out there.
For CRecordset - well, personally I'd use ADO anyway but thats just me.
|
|
|
|
|
what is std::string and how to use it?
|
|
|
|
|
hey, do you know MSDN ?
std::string is the C++ standard string template class
have a look at the file STRING (without the .h) in you compiler includes folder to see how it work is you prefer... (if you use visual C++ 6, it could be something like that : C:\Program Files\Microsoft Visual Studio\VC98\Include\STRING[^])
TOXCCT >>> GEII power
|
|
|
|
|
It's part of the standard template library (STL).
STL is sorta like MFC, but unlike MFC it's not a framework and is more geared to data storage/manipulation etc - providing you with things such as map's, linked lists, vectors, dynamic arrays etc. IMHO it's actually better than MFC's version of these classes - far more standard and MFC's versions were only really created as a stop gap when STL was being developed.
Though while map is better than CMap, and list is better than CList (IMHO), std::string isn't quite as good as CString, but its a string class you get free.
To use it:
#include <string>
#include <algorithim>
using namespace std;
void Blah()
{
// contact
string myString = "Hello ";
myString += "word"
// make the string lower case
transform(myString.begin(), myString.end(), myString.begin(), tolower);
etc etc.
}
One word of warning. STL does have quite a learning curve (for the very basic, just learn what an iterator is) and the provided docs (with MSDN) are very poor. Search the web for "STL Documentation" and find youself a better set.
If you can't be biffed to learn STL (its worth it in the end) then just grap a free string class from CP etc - im sure there are 100's.
|
|
|
|
|