|
Perhaps GetAdaptersInfo would help?
|
|
|
|
|
I just wanted to make it clear that i have heard that it is possible to have global memory in windows 95,97 which could be shared by all. What i mean by shared memory is that some new operator works on global memory.
I need exact details that how to have memory which i allocate from any process is shared between all the processes.
I need the api or is it ka any new operation allocate memory on the global level not private memory as windows nt has private address space for each process and pointer in one process is invalid in another.
|
|
|
|
|
Please help
Here is my code. I was able to modified to go to main menu.
But If user enter a value outside the range it should not
go to the main menu. It should display only:
cout<<"Please enter 1 or 2 (3 to exit program):";
cin>>choice;
#include <iostream.h>
//using namespace std;
int main(void)
{
int choice;
float c; //Declare variable to be displayed.
float f;
//Question:Will it be the best practice to do
this: float c=0?
//Question:I used float, but I am not sure if in
this case better to use int or double?
for(;;)
// empty to promt a user to enter correct
choice value
{
cout<<"Please select the task to
perform:"<<endl;
cout<<"convert="" fahrenheit="" to=""
centigrade="" (1)"<<="" endl;
="" centigrade=""
fahrenheit(2)"<<="" cout<<"exit="" the="" program(3)"<<=""
="" do
="" use="" do-while="" loop
="" {
="" cout<<"please="" enter="" 1="" or="" 2="" (3="" exit=""
program):";
="" cin="">>choice;
switch (choice)
{
// use switch in order to do
validation and calculation
case 1:
{
cout<<"Enter value
in Fahrenheit:" ;
cin>>f;
c=((f-32)*5/9);
cout<<"The value
in Centigrade is:"<<c<<endl;
}
="" break;
="" case="" 2:
="" {
="" cout<<"enter="" value=""
in="" centigrade:";
="" cin="">>c;
f=((c+32)*9/5);
cout<<"The value
in Fahrenheit is:"<
|
|
|
|
|
You could create another function to handle the switching.. I would make that function of type BOOL and if they enter a invalid response then you could return false and prompt the user again with the same question...
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
can you give the example? I am new to C++
|
|
|
|
|
I didn't compile this so it may have errors.. At least I think you will get the basic idea...
BOOL OnPrompt();
int main(void)
{
cout<<"Please select the task to perform:"<<endl;
cout<<"Convert Fahrenheit to Centigrade (1)"<< endl;
cout<<"Convert Centigrade to Fahrenheit(2)"<< endl;
cout<<"Exit the program(3)"<< endl;
while(true)
{
if(OnPrompt())
break;
}
return 0;
}
BOOL OnPrompt()
{
int choice;
float c;
float f;
cout<<"Please enter 1 or 2 (3 to exit program):";
cin>>choice;
switch (choice)
{
case 1:
{
cout<<"Enter value
in Fahrenheit:" ;
cin>>f;
c=((f-32)*5/9);
cout<<"The value
in Centigrade is:"<<c<<endl;
return TRUE;
break;
}
case 2:
{
cout<<"Enter value in Centigrade:";
cin>>c;
f=((c+32)*9/5);
cout<<"The value in Fahrenheit is:"<<f<<endl;
return TRUE;
break;
}
case 3:
{
cout<<"Thank you for using this program."<<endl;
return TRUE;
break;
}
default:
{
cout<<"Incorrect input"<< endl;
return FALSE;
}
}
}
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
I am so sorry. But I could not compile your example.
And also I did not understand
Please explain one more time...
|
|
|
|
|
For brevity, Rob left out some of the basics. It was assumed you knew how to add the missing pieces. Work through the compiler/linker errors one by one until you encounter one that you just cannot figure out.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
DavidCrow wrote:
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
I would love to guess "two", but since that's just *way* too easy, I'm gonna go with "a number".
The kindest thing you can do for a stupid person, and for the gene pool, is to let him expire of his own dumb choices.
[Roger Wright on stupid people]
|
|
|
|
|
DavidCrow wrote:
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
None - if one bird takes off, so does the whole flock.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Your while loop is definitely testing the wrong thing. Or is there a typo?
You probably need to drop the useless for( ;; ) -loop and switch to a while-loop testing for (choice == 3) as exit-condition.
You obviously need to get the input for choice before this loop.
As last statements in this loop (after the switch block), you need to duplicate the input for choice.
That way, you will be asking for choice in any subsequent loops.
The switch-statement will then have cases only for 1, 2, and default.
Be careful what entering a letter into your float variable does!
An additional hint:
do
{ seems to be a very silly comentary. Everyone can see this.
Try not to comment what you do, but why and why exactly so and not different.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Here is my modified code. It still not going to the cout<<"Please select the task to perform:"<<endl;if user="" entered=""
value="" outside="" the="" range="" 1="" or="" 2.="" i="" dot="" need="" to="" show="" main="" menu
#include="" <iostream.h="">
//using namespace std;
int main(void)
{
int choice;
float c;
float f;
bool enter;
do
{
if (enter=true )
{
cout<<"Please select the task to perform:"<<endl;
cout<<"convert="" fahrenheit="" to="" centigrade="" (1)"<<="" endl;
="" fahrenheit(2)"<<="" cout<<"exit="" the="" program(3)"<<="" cout<<"please="" enter="" 1="" or="" 2="" (3="" exit="" program):";
="" }
="" else=""
="" {
=""
="" cin="">>choice;
switch (choice)
{
case 1:
{
cout<<"Enter value in Fahrenheit:" ;
cin>>f;
c=((f-32)*5/9);
cout<<"The value in Centigrade is:"<<c<<endl;
enter="=true;
" }
="" break;
="" case="" 2:
="" {
="" cout<<"enter="" value="" in="" centigrade:";
="" cin="">>c;
f=((c+32)*9/5);
cout<<"The value in Fahrenheit is:"<
|
|
|
|
|
Here is my updated code, but it is not doing what it should.
If user enters outside the range 1,2 it should show only cout<<"Please enter 1 or 2 (3 to exit program):"; in all other cases main menu
#include <iostream.h>
//using namespace std;
int main(void)
{
int choice;
float c;
float f;
bool enter;
enter==true;
do
{
if (enter=true )
{
cout<<"Please select the task to perform:"<<endl;
cout<<"convert="" fahrenheit="" to="" centigrade="" (1)"<<="" endl;
="" fahrenheit(2)"<<="" cout<<"exit="" the="" program(3)"<<="" cout<<"please="" enter="" 1="" or="" 2="" (3="" exit="" program):";
="" }
="" else=""
="" {
="" cin="">>choice;
switch (choice)
{
case 1:
{
cout<<"Enter value in Fahrenheit:" ;
cin>>f;
c=((f-32)*5/9);
cout<<"The value in Centigrade is:"<<c<<endl;
enter="=true;
" }
="" break;
="" case="" 2:
="" {
="" cout<<"enter="" value="" in="" centigrade:";
="" cin="">>c;
f=((c+32)*9/5);
cout<<"The value in Fahrenheit is:"<
|
|
|
|
|
sardinka wrote:
if (enter=true )
The compiler could have easily detected this error had it been written like:
if (true=enter)...
It's always good practice to place constants on the left of the operator and variables on the right of the operator. That way, if you ever decice to use = instead of ==, you'll receive a compiler error.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I am creating a simple drawing application to draw lines.Also fill an enclosed space with color.After i draw the lines to get an enclosed space i use the right mouse button up to fill it with black color. again when i right click it, it should become white. i am not able to get that part. can you help me??
|
|
|
|
|
When I want to see Call Graph on
DevPartner 7.1 for C++,
of some of enlisted method in performance session,
they shows rectanle with pluses for traversing tree,
but when I press on this pluses
The
"Format Exception: Wasi not in a correct format".
What to do to find place in my code where it happen?
How to see MFC or ATL code where it nearest happen?
thanks you.
|
|
|
|
|
cout<<"Please enter 1 or 2 (3 to exit program):";
cin>>choice;
|
|
|
|
|
1
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Chris Richardson
|
|
|
|
|
Is it possible by profiler output to gather what probles is ?
I have ActiveX(ATL) in CDialog (MFC)
Visible problems:
Much time to load,
to unload,
(and leak of memory)
Does this ActiveX in -Process ?
(according to Profiler output )
they marked as appartment,
and MFC app I initialized as Appartment-Threaded.
but accidencial cases can happen...
- does I have in-proc case?
To understand output:
I use interface IPictureDisp for direct loading
pictures from CDialog resource to ActiveX.
(code is below)
Profiler - DevPartner 7.1
Made folowing output:
(is it possible to understand where problem is in, by anylizing it?)
thanks you
list ----------------------------------
Method Name,"% in Method","% with Children","Called","Average"
WaitForSingleObject,"10,16","10,16","31я064","55,19"
#6274 (mfc71d.dll),"5,69","11,23","2я627","365,10"
PtAllSet::baseGet,"3,69","6,35","158","3я939,56"
WaitForMultipleObjects,"3,50","3,50","3я677","160,52"
#6849 (mfc71d.dll),"2,53","52,69","24я929","17,11"
OutputDebugStringA,"2,41","2,41","6я807","59,67"
CallWindowProcA,"2,38","26,62","25я311","15,88"
BitBlt,"2,32","2,32","2я630","148,83"
rand,"2,29","2,42","82я220","4,70"
GetMessageA,"2,02","2,75","3я700","91,93"
#7017 (mfc71d.dll),"1,65","27,88","2я956","94,32"
RtlAllocateHeap,"1,63","1,63","86я808","3,17"
PtAllSet::SetFilter,"1,53","2,08","156","1я655,03"
#6045 (mfc71d.dll),"1,53","8,20","18","14я328,79"
PtVArray::Search,"1,47","1,50","1я898","130,91"
recv,"1,42","1,47","843","283,93"
#5954 (mfc71d.dll),"1,36","2,32","6я821","33,51"
PtAdmin::CloseDictionary,"1,24","2,07","3","69я695,58"
SendMessageA,"1,15","10,41","13я858","13,97"
SetDIBitsToDevice,"1,10","1,10","825","224,15"
PtAdmin::OpenDictionary,"1,02","1,98","3","57я179,20"
#1718 (mfc71d.dll),"0,99","1,08","12я802","13,05"
RtlFreeHeap,"0,89","0,89","85я679","1,76"
PtOnDemandSet::baseGet,"0,88","1,71","47","3я148,29"
#7007 (mfc71d.dll),"0,84","19,16","2я311","61,26"
WaitForMultipleObjectsEx,"0,82","0,82","3я600","38,42"
---------------------------------
code of loading Picture into activeX
<br />
<br />
HRESULT PutImage(IPictureDisp* pPicture, int nEntry)<br />
{<br />
m_isChanged = true;<br />
<br />
if (FireOnRequestEdit(DISPID_PICTURE) == S_FALSE)<br />
return S_FALSE;<br />
m_spPictures[nEntry] = 0;<br />
if (pPicture)<br />
{<br />
CComQIPtr<IPersistStream, &IID_IPersistStream> p(pPicture);<br />
if (p)<br />
{<br />
ULARGE_INTEGER l;<br />
p->GetSizeMax(&l);<br />
HGLOBAL hGlob = GlobalAlloc(GHND, l.LowPart);<br />
if (hGlob)<br />
{<br />
CComPtr<IStream> spStream;<br />
CreateStreamOnHGlobal(hGlob, TRUE, &spStream);<br />
if (spStream)<br />
{<br />
if (SUCCEEDED(p->Save(spStream, FALSE)))<br />
{<br />
LARGE_INTEGER l;<br />
l.QuadPart = 0;<br />
spStream->Seek(l, STREAM_SEEK_SET, NULL);<br />
OleLoadPicture(spStream, l.LowPart, FALSE, IID_IPictureDisp, (void**)&m_spPictures[nEntry]);<br />
}<br />
spStream.Release();<br />
}<br />
GlobalFree(hGlob);<br />
}<br />
}<br />
}<br />
m_bRequiresSave = TRUE;<br />
FireOnChanged(nEntry + 3);<br />
FireViewChange();<br />
SendOnDataChange(NULL);<br />
<br />
<br />
return S_OK;<br />
<br />
}<br />
|
|
|
|
|
First: despite the names, <pre> produces better-formatted code than <code> .
If your control is implemented as a DLL, it will be loaded into the container's process. I'm not sure that OLE Controls/ActiveX Controls work out-of-process, in any case.
COM may introduce a proxy if the thread creating the control is not in a single-threaded apartment at the time the control is created.
Your profiler output lists, in order of time spent in the function and the functions it called (children above), the functions that were called in the profiler run. The top function called (i.e., the one in which most time was spent) was WaitForSingleObject .
WaitForSingleObject , of course, is a system function. There's not a lot you can do to that, apart from ensuring that you're only holding synchronisation objects as long as you need them, and no longer.
Function names beginning with '#' are functions where the DLL exports the function by ordinal, not by name. The MFC DLLs do this to save about 1MB of space for the name table, and to improve loading speed. To find the function, ensure that you have the MFC source code installed, then look for the file mfc71d.def - typically in C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\src\Intel (IIRC). This file lists the decorated name of the function (on the left) and its ordinal (on the right, after the '@' symbol). Use the SDK tool undname to undecorate the name. If there are multiple overloads of the function, use the -f switch to find out which one.
For example, MFC 6 has the following for ordinal #1718:
?CreatePointFontIndirect@CFont@@QAEHPBUtagLOGFONTA@@PAVCDC@@@Z @ 1718 NONAME undname -f gives
C:\>undname -f ?CreatePointFontIndirect@CFont@@QAEHPBUtagLOGFONTA@@PAVCDC@@@Z
Microsoft(R) Windows NT(R) Operating System
UNDNAME Version 5.00.1768.1Copyright (C) Microsoft Corp. 1981-1998
>> ?CreatePointFontIndirect@CFont@@QAEHPBUtagLOGFONTA@@PAVCDC@@@Z == public: int
__thiscall CFont::CreatePointFontIndirect(struct tagLOGFONTA const *,class CDC
*) Working across the profiler's output, you have: the name of the function, the percentage of time spent in this function's code (not including functions it called), the percentage of time spent in this function and the functions it called, the number of times this function was called, and the average time to execute each call.
The function that spent the most time, that you wrote, is PtAllSet::baseGet. You should probably look to see whether the algorithm this function uses can be improved.
|
|
|
|
|
I know what have written.
except I think
STA is included to APARTMENT, as sub-circle.
just some STA can be as APARTMENT settled to application.
But what about mutli-threading at STA?
than,
I need explanation what problem code makes
so WaitForSingleObject() so much?
What is the DLL and exports I know.
|
|
|
|
|
I am trying to have shrared data in dll and i have got no of option using memory mapped files and #pragma data_seg(".SHARDAT")
The problem i am running into is that i have a pointer of a root of the linked list now what i want to do is allocate memory to it and i have put this in to
#pragma data_seg(".SHARDAT")
CLinkedList *pRoot;
#pragma data_seg
now i want to fill the linked list with contents based on some input and its dynamic memory allocation all right chain formed.
Any process can add into it
My question here is that i have taken a look at number of tutorials on memory mapped files and shared data seq but in all the case the data of the object was fixed
class Cobj
{
int i;
char str[255];
}
etc and sizof was used to allocate memory to it both in case of memory mapped and shared data.
i want to keep a pointer and memory could be allocated by any proces number of instance of application connecting.
Is there any method of global memory allocation visible to all processes and at the same time dynamic at runtime.
I actually want to shared data through dll any help, suggestions,links etc are more than welcomed.
|
|
|
|
|
You need to create a shared memory section, which the Win32 API refers to as a file mapping object.
See the documentation for CreateFileMapping .
You will need to allocate memory from and resize your mapping as appropriate.
Another method would be to have one process be responsible for managing the memory and the shared data, and have the others communicate with that process via Windows messages.
The implementation is left as an exercise for the reader
|
|
|
|
|
As i have mentioned that i have done study on them but they all let you have to specify memory(exact) and in which you cannot store pointers.
Pointers in one address space invalid in another.
Should i make it this way that same pointer offset stroed
i.e. 0xabcdef12 in one process then all the processes have same memory place reserved.
Ok vc++.net bible there is a mechanism which uses placement new operator by specifying a physical memory address but for that the author has already reserved memory in the shared data segment of dll using
#pragma data_seg(".SHARDAT")
static char lpszMemory[sizeof(CTest)];
CTest* g_pTest=NULL;
#pragma data_seg
g_pTest = :: new (lpszMemory) CTest;
but the same problem size specified.
As you might have seen i need it for the linked list any length, growing and growing using new from any process.
Ok let's keep the problem to windows 95.
Could it be that on windows 95 whatever memory i allocate all the process that address and access it.I need help on the mechanism should i use globalalloc or what.
Thank you in advance.
|
|
|
|
|