|
Maybe this little piece of code helps you. (I too hate working with strings in C++)
char* string1="are";
char* dictionar[3]={"I","are","the"};
for (int i=0;i<3;i++)
if (strcmp(string1,dictionar[i])==0) printf("%d",i);
Good luck!
Cristina
|
|
|
|
|
I seem to have a simple problem, but I didn't find a solution yet. So, please help me with any ideas.
I have a number, let's say X. I have its value.
I want to obtain in a C++ program, the (approximate) value of its cube root.
I thought I could approximate it with the function pow(number,1/3), but even cube root of 9 returns the value of 2.08008 which is too far from truth.
I know the problem is 1/3 which cannot be reprezented with accuracy because of its fractional part.
Do you have any other solution you can think of?
Thanks in advance,
Cristina
|
|
|
|
|
The cube root of 9, given to 5 decimal places (6 significant figures), *is* 2.08008. I can not see a problem with this.
Do you need more accuracy? Is the figure state the exact figure returned from the pow function?
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
How to link functions in a .asm file?
Should I compile it first, and how to compile?
|
|
|
|
|
I have been after this answer for a long time.
The easy and nice way is to use visual c++ inline assembler,because in this way you donot have to face problems like calling conventions, and seperately compiling your application and assembling your asm file.
I am not prohibiting you from doing your work.
1:- first assemble your asm file with assembler,this will give you a file with .obj extension.
2:-now only compile your other application file(s), and you will get other .obj file(s).
3:- Now link all .obj files.
this will give you the .exe file
|
|
|
|
|
Sorry if this is a dumb ? but I am fairly new to C++.
I am writing an application that has no user events. I am using only WIN32 - NO MFC - because it is basically a bootstrapper application and I do not want any dependencies other than core Windows APIs.
I display a small status dialog that provides progress messages. If all goes well, it runs, displays it's messages, and the bootstrapper application terminates after launching another application. That part works fine.
But, if a condition is not met, I would like to display a message box. When I do this, the whole thing locks up. I am creating the messagebox as a child of the dialog, but it still does not process it's messages or even receive focus.
I've tried making the main dialog modeless - did not help.
I find the SDK docs on message processing rather confusing.
Can anyone point me in the right direction?
Thanks!!!!
R
|
|
|
|
|
The problem with MessageBox is that it takes over input and doesn't allow the creating thread to run. In effect, the MessageBox takes over the focus, just like a modal dialog. So you'll want to come up with a way to run the MessageBox function in a thread separate from your main dialog's thread.
You may consider creating an additional modeless dialog that hangs off of your main dialog. You don't have to display the dialog (never call its ShowWindow(SW_SHOW) ), and it doesn't have to have any special features. It only exists to pop up the MessageBox. Maybe add a method to this modeless dialog, DisplayMessage(msg) or something, that calls MessageBox.
I'm not able to test this now, but I think it'll work. It shouldn't tie up your main dialog's message loop, only the message loop of the invisible modeless dialog. Just make sure that you don't call the DisplayMessage method in the modeless while another message is being displayed. You'll also have to make sure the modeless message box gets cleaned up correctly (via DestroyWindow and (just like all modeless dialogs) don't let it be closed by the user.
Alternately, if you're good with Win32 threads, you can define a thread that you can fire from your main dialog. Given a string to display (and the MB_OK, etc. codes), this thread's main execution function simply calls MessageBox(your params) , then exits. Just be sure you clean up the threads nicely so as not to leave "zombie" threads.
Hope this gives you some ideas.
Bob Ciora
|
|
|
|
|
Thanks for the input. I had already considered spawning a second thread but instead I kept reading the SDK info on message loops and thinking "Surely this cannot be as difficult as I am making it".
So I went with your second suggestion. I just call a wrapper function that spawns the thread and goes into a WaitForSingleObject state to suspend the main execution until the user dismisses the messagebox.
Works great!
Thanks,
Robert
|
|
|
|
|
hello,everyone!
i wirte a system service which is a serial communiction program ,it can start normly ,but when stop service at service control panel,it doen't work .pop a message box "error 1053 the service did not respond to the start or control request in a timely fashion"
if you know how to reslove it ,please tell me ,thanks a lot !
|
|
|
|
|
Your service only has about 5 - 10 seconds to come to a stop, otherwise it must post SERVICE_STOP_PENDING status to the service control manager (SCM).
It has to eventually report that it has stopped back to the service control manager, using SetServiceStatus - SERVICE_STOPPED.
Your service must periodically call (about once every 3 - 5 seconds) SetServiceStatus while you are finishing up your serial communications shutdown, so the SCM will not think your service is hung.
The best way to do this is to start another thread and inform the SCM of your service's status. Meanwhile, your main thread can continue to close down the serial communications.
|
|
|
|
|
firstly,thank you ,
i just use three threads to do it ,one is serialport ,the other is inform the scm of service' status and another is main thread.
but i don't know the reason.
|
|
|
|
|
When I create a service I always have a separate thread responsible for periodically informing the service control manager of the service status. This thread calls SetServiceStatus . I find that when the 'pending' type notifications are required, posting the service status about every 3-5 seconds is best. If no postings are necessary, the thread can be suspended or idle.
This thread periodically posts SERVICE_START_PENDING while the service is starting up, until it is initialized properly, then it posts a single SERVICE_RUNNING .
If the service is asked to puase, the thread posts SERVICE_PAUSE_PENDING periodically and then a single SERVICE_PAUSED. When the service is asked to resume, it periodically posts SERVICE_CONTINUE_PENDING followed by a single SERVICE_START_PENDING once it is running again.
When the service is asked to stop, the thread periodically posts SERVICE_STOP_PENDING and then posts a single SERVICE_STOPPED just prior to existing altogether.
I also find at least three threads a good combination for services.
1. Primary thread receives the service control notifications.
2. Second thread handles the periodic posting of the service status notifications back to the service control manager.
3. Third (and later) thread performs all the work (one or more threds may be necessary)
|
|
|
|
|
I have a multithreaded win32 console application, which I am trying to extend
to open a separate dialog window based on the CDialog class (This has been
built using the Visual Studio Resource Editor).
I am effectively trying to add a MFC resource into a Win32 console
application, but after the window opens it freezes, if other windows open
over it and are moved away the widow is not redrawn.
I have called AfxWinInit at the start of main, and declared my instance of
the dialog within main.
Any advice on where I am going wrong would be greatly appreciated.
Keith
History repeats it’s self because we don’t listen !
|
|
|
|
|
Being never seriously worked with MFC, but on general - do you have a message pump in your console app?
Do you keep the all dialog related stuff (including the message pump) in the one thread? - win32 controls are not very capable of handling MT issues.
|
|
|
|
|
Dear All,
I’m developing software using Microsoft Visual C++ 6.0 and having a problem with Remote Procedure Call (RPC). Since RPC is used as a tool to communicate between applications over networks as servers and clients, I have developed a real-time database server and also several client application programs. Both clients and servers communicate between each other through the RPC functions and services. At the beginning of a test period (around 17 days), all applications worked fine and performed their jobs very well but after that all client applications could not call some remote functions to the server. I have noticed that all clients were able to connect (bind) to the server and call some functions which implies that a listen process of the server was still exist. However, for some functions that could be called before (during the first 17 days) such as database reading functions, when called from those clients, the functions kept returning the error code: 1726 (The remote procedure call failed.). It didn’t provide much detail of that error. The specification of the server and 8 client PCs are as follows:
Server: Dell, Xeon 2.3 GHz with dual CPU, DDR Ram 1 GB, SCSI HDD Raid 5, OS Windows 2000 Server with Service Pack 4.
Clients: Acer, Pentium 4 - 2.0 GHz, DDR Ram 2 GB, OS Windows 2000 Professional with Service Pack 4.
Other Devices: 100 Mbps Switch.
I don’t know if there is any bug in the RPC run-time library of Service Pack 4. I have searched and found some Microsoft articles which report that RPC has some bugs when using with “the Cluster service” but they have been fixed already in the Service Pack 4 of Windows 2000. I would really appreciate if anyone could help solving my problem.
Thank you very much,
Nawanat
|
|
|
|
|
We have applications that use RPC and run for VERY long times (weeks and months).
I suspect you have some other problem - a memory leak, resoruce leak, or other in your system.
Perhaps you can run performance monitor on your software and check for memory usage, thread usage, GDI usage, etc. to track down the culprit. That error value from RPC is so generic in this instance, it is almost totally worthless information. Also, if you have many clients accessing a single database, perhaps you encountered a race condition - a competition for the database resources that could not be resolved.
|
|
|
|
|
hi, i've been programming in WinAPI for several years now, and somtimes I encounter MFC conversations with my mates, I ignored it coz I think I don't need it. However, I'm curious as if due to complexity I'm always encoutering with WinAPI, I sometimes wished I knew MFC, but someone told me that MFC s bloated. Most of my projects are very tight in terms of size, so I'm confused, they say that MFC is better, but bloated? while ofcourse WinAPI is really powerful (for me) however the downside is difficulties of implementing just a small function for a lot of codes. I thought MFC makes codes smaller? but why or how come that it is bloated? it is C++ anyway, right?
== rein lucien ==
|
|
|
|
|
The main advantage of MFC over WinAPI is that it's more productive, probably easier to see what's going on. But yes it may well be bloated for your requirements. However, there are alternatives (none of which I've used):
1. Qt and wxWindows which are cross-platform toolkits.
2. Windows Template Library (WTL). This was an unofficial release from Microsoft but is now open source. There are tutorials on this web site and it is highly rated, and it is I believe more elegant and less bloated than the ageing MFC.
Kevin
|
|
|
|
|
I think you also need to define your 'bloat to productivity' limits.
I mean, suppose I write a dialog app in pure WIN32 API and it takes me two weeks and it is 69K in size, and then I write a dialog app in MFC in two or three days and it is 120K in size, am I really worried it is 'twice as big' as the straight WIN32 application? Considering I am done in a fraction of the time and working on the next project already?
What I don't recall seeing is what MAKES an MFC app so 'bloated'? Linking in COM? ActiveX? Database? If you just have a few windows on the screen and a bit of data processing to go along with it, it is not 'horrible'. What might also make the MFC application seem bloated is all the DLL and other WIN32 API that get linked in to a 'generic' MFC program. It seems the memory footprint of an MFC app tends to be larger than a similar WIN32 application. If it were somehow more granular, the 'bloat factor' could probably be reduced. I think the WTL allows more granularity like this than the MFC libraries do.
If you are COMPELTELY hardcore, you could rebuild a special MFC library that did not have the extra stuff in it you did not need, and then link it into your program, you might end up with something smaller, but then consider the time involved in doing that conversion.
|
|
|
|
|
morning
I´d like to know how I can pass arrays as parameters to functions in VC++. (I´m a beginner to VC++, and have all the methods inside one class)
When I try, I get an error message saying that the array must specify __gc or __nogc. However, trying to declare the funtion like this:
bool function(__gc char array[]){return true;}
I get a msg saying that __gc can only be applied to an array !!
How should I declare the array in the firs place, and how should it be declared in the parameter list?
doneirik
|
|
|
|
|
Something like:
void function( char arr[] )
{
}
void main( void )
{
char arr[5] = {'h', 'e', 'l', 'l', 'o'};
function(arr);
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
dll doesn't know CString
what problems.
can i use directly CString?
i want to use CString::mid function.
mydll.cpp(198) : error C2065: 'CString' : undeclared identifier
|
|
|
|
|
vc-programmer- wrote:
can i use directly CString?
Yes, as long as you have correctly included the MFC header and library files.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
MFC header and library files
what i need MFC header and library..
#include "windows.h"
#include "afx.h"
i try above header files.
i can not access CString.
how can i do?
|
|
|
|
|
I would suggest using AppWizard to create an MFC DLL rather than trying to retrofit your DLL to use MFC.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|