|
ok ! could some one quide in this :- we have game project where each room is currently run by running the same game server application for each room , in other words for multiple rooms multiple instances of same game server exe are run . Because threads are not used it takes more memory if we need to run large number of rooms by running the same server exe number of time equlal to the rooms .
The current application is developed in a single dialogue box which has all the code and which manages the sockets . now we need to make whole thing in single game server application using threads to run numtiple rooms within . so can some one tell that , can we use the current version and us it into new appication and have it run the same code into new threads to add new room each time and will we need to make the application communicate from one main port or can we have the old code run in new thread and let it open an unique port for ecah room .
What would be a right approach to making such an application which can run 500 such rooms in other words 10000 concurrent users as each room have 10 live players .
|
|
|
|
|
Respected Dears
How i can write code for Static text control at run time.
david
|
|
|
|
|
Assuming you are using MFC:
- Add CStatic *m_pMyStatic as member of your CWnd(-derived) object
- When it is required, create the control:
m_pMyStatic = new CStatic;
m_pMyStatic->Create(...);
m_pMyStatic->SetWindowPos(...);
etc. - Don't forget to delete the control when it is no longer needed (for instance in the destructor):
delete m_pMyStatic;
|
|
|
|
|
Hello,
There is an exe that:
1.I want to send this file to a client from server but that client haven't the client program.How?
2.How to run (Install) this file?
Cheers,
Thanks.
|
|
|
|
|
Respected All
Regards!
How i can write Code for Creating STATIC TEXT control at RunTime.
best wishes
david
|
|
|
|
|
Good Morning everybody,
i'd like to get your help on that too deep problem for my mind for the moment i am reflecting on.
I have a Dialog based MFC project that i am programming on VS7.1.
It's been compiling well, and i can execute it well as far as i enter in a certain state that causes the crash (so, if there is any syntactic/writing mistake on the code exposed, it is only on this post i make an error - as i don't Copy/Paste all the code given here).
i have two main classes, plus some extra types defined outside the classes as they are used by the two classes :
<code>CFactEditorDlg</code> (the main dialog of the program)
- FactEditorDlg.h
- FactEditorDlg.cpp
<code>COptionsDlg</code> (the option dialog of the program, that allow the user to set some display parameters)
- OptionsDlg.h
- OptionsDlg.cpp
FactEditorTypes.h (sample) :
<font color=blue>typedef enum</font> {
<font color=green>
} TStartingCallCountry;
<font color=blue>typedef enum</font> {
<font color=green>
} TEditorLanguage;
<font color=blue>typedef unsigned char</font> TDigitsInYears;
<font color=blue>typedef unsigned char</font> TDigitsInPhones;
<font color=blue>typedef struct</font> {
TStartingCallCountry _StartingCallCountry;
TEditorLanguage _EditorLanguage;
CString _FileViewer;
TDigitsInYears _NbDigitsInYears;
TDigitsInPhones _NbDigitsInPhones;
} TEditorOptions;
TEditorOptions is a type made to transfer the 5 fields it encapsulates from CFactEditorDlg to the COptionsDlg , and to get them back (maybe modified) then.
This is done in the OnSclickOptions button as follow :
<font color=blue>void</font> CFactEditorDlg::OnSClickOptions() {
<font color=green>
TEditorOptions EditorOptions = {
m_StartingCallCountry,
m_EditorLanguage,
m_strFileViewer,
m_ucNbDigitsInYears,
m_ucNbDigitsInPhones
};
<font color=green>
COptionsDlg OptDlg(EditorOptions, m_strEditorVersion, <font color=blue>this</font>);
<font color=blue>int</font> iResult = OptDlg.DoModal();
<font color=blue>if</font> (iResult == IDOK) {
<font color=green>
<font color=green>
}
<font color=blue>else</font> { <font color=green>
}
}
...and here is how the constructor of COptionsDlg treats the TEditorOptions parameter :
COptionsDlg::COptionsDlg(TEditorOptions& EditorOptions,
CString EditorVersion,
CWnd* pParent <font color=green></font>)
: CDialog(COptionsDlg::IDD, pParent),
m_EditorOptions(EditorOptions) <font color=green>
{
::strcpy(m_strEditorVersion, EditorVersion);
<font color=red>m_strEditorVersion = EditorVersion</font>; <font color=green>
m_strDigitsInYears.Format(<font color=gray>"%d"</font>, m_EditorOptions._NbDigitsInYears);
m_strDigitsInPhones.Format(<font color=gray>"%d"</font>, m_EditorOptions._NbDigitsInPhones);
}
now, the problem is that the Options dialog modifies well the datas, returns them to the CFactEditorDlg::OnSClickOptions() event handler correctly (i displayed the resulting values with a MessageBox), but just when i get out the OnSClickOptions() function, i get such a weird error :
Run-Time Check Failure #2 - Stack around the variable 'EditorOptions' was corrupted.
this is exactly what i get from the Run-Time, and i really can't understand what it can mean.
if it is of any help, i tried to see what happens in the debugger, and i saw that the local EditorOptions (local to OnSClickOptions() ) is staying with the values it got from the option dialog, except the fact that the CString member _FileViewer is leaving its content.
the debbugger gives this :
Before :
_FileViewer {0x002fa000 "notepad"} ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > >
After :
_FileViewer {0x002fa000 "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ"} ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > >
if anybody knows, i'm all listening at you guys...
[edit]
i modified the m_strEditorVersion in both DialogBox classes into CString.
The error remains the same...
[/edit]
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
Run-Time Check Failure #2 - Stack around the variable 'EditorOptions' was corrupted.
This means that some variable on your stack was overflowed or underflowed. Also that the program asserts when you leave the handler indicates that that the stack is corrupted in that function, not in the DoModal .
toxcct wrote:
::strcpy(m_strEditorVersion, EditorVersion);
I think that the problem is here. You call un unsafe C function on a variable with an uninitialized length! If my assumtions are correct, m_strEditorVersion is of type CString .
If I'm correct, see what the following gets you:
::strncpy(m_strEditorVersion.GetBufferSetLength(256), EditorVersion, 255);
m_strEditorVersion.ReleaseBuffer();
Your problem was because you were writing to a CString buffer that had a size which was too small. A better solution would be:
COptionsDlg::COptionsDlg(TEditorOptions& EditorOptions, <br />
CString EditorVersion,<br />
CWnd* pParent )<br />
: CDialog(COptionsDlg::IDD, pParent),<br />
m_EditorOptions(EditorOptions),
m_strEditorVersion(EditorVersion) <br />
{
m_strDigitsInYears.Format("%d", m_EditorOptions._NbDigitsInYears); <br />
m_strDigitsInPhones.Format("%d", m_EditorOptions._NbDigitsInPhones);<br />
}<br />
May I ask why you use ::strcpy to copy CString contents?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Bob Stanneveld wrote:
m_strEditorVersion(EditorVersion)
{ // or just try:
// m_strEditorVersion = EditorVersion;
in fact, i did this first, but the compiler told me to put this in the constructor initialization list...
Bob Stanneveld wrote:
May I ask why you use ::strcpy to copy CString contents?
i do ::strcpy(m_strEditorVersion, EditorVersion); because m_strEditorVersion is defined as a char[10] ...
so, the code you suggest me with ReleaseBuffer() won't be able to work...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
i do ::strcpy(m_strEditorVersion, EditorVersion); because m_strEditorVersion is defined as a char[10]...
so, the code you suggest me with ReleaseBuffer() won't be able to work...
Your naming convention is a little bit misleading. m_strEditorVersion suggests that is is a normal string instead of a C-Style string. Use m_pszEditorVersion instead.
Back to the problem. Did you check the length of the EditorVersion string? You are just copying the string without length checking. This is a horrible mistake! You should use ::strncpy and copy up to 10 characters if you don't care about the '\0' or only 9 and set the NULL-terminator yourself. I'm almost 100% sure that this solves your problem.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
eBob Stanneveld wrote:
Did you check the length of the EditorVersion string? You are just copying the string without length checking
currently, yes you're right, but as i use the debugger to confirm, m_strEditorVersion is a char[10] and contains only "2.10" (correctly terminated with its trailing '\0' character)...
well, i'll test the changes on the afternoon, but now, i dont have enough time to tell you if the changes are useful or not. however, i think i'll change the char[10] to a CString, regardless to the memory occupied...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Do you still get the error with the range checking code?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
hi bob, i'm back
i've edited my first post on this thread... the error remains the same, even when i changed the m_strEditorVersion into CString...
i think it is not the source of the problem because the Run-Time talks about TEditorOtions ...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hey,
toxcct wrote:
i've edited my first post on this thread... the error remains the same, even when i changed the m_strEditorVersion into CString...
At least that will not cause any problems in the future anymore.
toxcct wrote:
i think it is not the source of the problem because the Run-Time talks about TEditorOtions...
I cannot see what the problem is because I don't know your code, but you could set a memory breakpoint at the address of the variable that gets overwritten. Your debugger will do its trick at the moment the memory is changed.
See here[^] and here[^] for more information about memory breakpoints.
Good luck!
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Want to uninstall a U disk by VC++ program under windows2000
how to coding the program? have the api function about this?
|
|
|
|
|
What is a "U disk?"
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I have created a simple sitch(), it takes integers
int choice;
switch(choice)
case 1:
break
.
.
default
message
break;
this works fine as long as the user enters a number (integers) but if I enter leters a,b,XD ..etc
it goes out in a loop.
how to chakec data type to ensure it is 1-9, if not display a message
Any way would be good
thanx
|
|
|
|
|
Do this before your switch statement:
It just checks if the values are in the specified range.
if (choice >= 48 && choice <= 57)
{
switch (choice)
...
}
this is this.
|
|
|
|
|
Anonymous wrote:
how to chakec data type to ensure it is 1-9, if not display a message
Your switch does this automatically with the default block. What else do you want?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Don't think you read the question right. The default works fine if an interger is entered (any number) but if a character is enter, it won't work!!!!!
|
|
|
|
|
Anonymous wrote:
ForumVisual C++
Subject:Re: switch() function
Sender:Anonymous
Date:14:18 7 Jul '05
Don't think you read the question right. The default works fine if an interger is entered (any number) but if a character is enter, it won't work!!!!!
I don't think that you can program very well. That's OK since we are here to help.
I read the question and I can assure you that I understand it perfectly well! Your problem is that you don't know what you are doing. Let me elaborate: characters (I'll stick to single byte characters for simplicity) are represented by integral values in the range 0x0 to 0xFF. Integers (the usual 32bit integers) have values in the range 0x0 to 0xFFFFFFFF. What did we learn from this is that you can store an character into an int without problems. So a simple static_cast will solve your problem.
If you work with the datatype char however, the following code will do the trick:
std::cin >> cYourChar;
switch( cYourChar )
{
case '0': { break; }
case '1': { break; }
case '2': { break; }
case '3': { break; }
case '4': { break; }
case '5': { break; }
case '6': { break; }
case '7': { break; }
case '8': { break; }
case '9': { break; }
default:
}
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
as above, the exception will be caught in the "default" case.
it's not necessarilly the fault of the switch but of the input.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
hi all
I want to use mfc in win32 dll. but this error happens.how to deal with this error?
fatal error C1189: #error :WINDOWS.H already included. MFC apps must not #include <windows.h>
I love you not for whom you are, but who i am when I'm by your side
|
|
|
|
|
gohappy_1999 wrote:
I want to use mfc in win32 dll.
Thats not possible, as MFC is Upgrade/wrapper of Win32 api's. So according to Windows Programming Thumb Rule, Any upgraded thing will not be supported in condition prior to upgrade.
So,In order to use MFC in dll,You have to create MFC based DLL.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
I have done some work recently in C#, integrating the product I work on with another project that exposes a COM object for this purpose. Now a third party has asked me to do the same in C++. This product in C# took an array of objects as a parameter, and returned an array of objects. The objects were strings. In C++, I've done this:
const char * pClientFields[11] = {"CLIENT_RECD",<br />
"CLIENT_FIRST",<br />
"CLIENT_LAST",<br />
"CLIENT_ADDRESS",<br />
"CLIENT_CITY",<br />
"CLIENT_STATE",<br />
"CLIENT_ZIP",<br />
"CLIENT_AREA",<br />
"CLIENT_PHONE",<br />
"CLIENT_BUSINESS",<br />
"CLIENT_EMAIL"};<br />
<br />
_variant_t * ClientFields = NULL;<br />
<br />
_variant_t * GetClientFields()<br />
{<br />
if (ClientFields == NULL)<br />
{<br />
CComSafeArray<BSTR> array;<br />
for(int i=0; i < 11; ++i)<br />
{<br />
array.Add(_bstr_t(pClientFields[i]));<br />
}<br />
<br />
VARIANT * pVar = new VARIANT();<br />
pVar->vt = VT_ARRAY | VT_BSTR;<br />
pVar->parray = array.Detach();<br />
<br />
ClientFields = new _variant_t(pVar);<br />
}<br />
<br />
return ClientFields;<br />
}
because the COM interface is expecting a _variant_t( and it returns one, too ). ClientFields at the end of this does not know what sort of variant it is, and so I get an exception. Can anyone please show me what I need to do here to get a _variant_t full of strings, and also how to read one at the other end ? I need it to compile in VC6 ( although the above is written in VC7 )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Can anyone please show me what I need to do here to get a _variant_t full of strings, and also how to read one at the other end ?
You can create the variant with something like this:
void BstrArrayFromWcharArray(VARIANT& var, WCHAR** pStrings, int size)
{
var.vt = VT_ARRAY | VT_BSTR;
var.parray = SafeArrayCreateVector(VT_BSTR, 0, size);
for (long ix = 0; ix < size; ix++)
SafeArrayPutElement( var.parray, &ix, ::SysAllocString(pStrings[ix]) );
}
WCHAR* pClientFields[] =
{
L"CLIENT_RECD",
L"CLIENT_FIRST",
L"CLIENT_LAST",
L"CLIENT_ADDRESS",
L"CLIENT_CITY",
L"CLIENT_STATE",
L"CLIENT_ZIP",
L"CLIENT_AREA",
L"CLIENT_PHONE",
L"CLIENT_BUSINESS",
L"CLIENT_EMAIL"
};
_variant_t ClientFields;
_variant_t* GetClientFields()
{
if (ClientFields.vt == VT_EMPTY)
{
UINT size = sizeof(pClientFields)/sizeof(*pClientFields);
BstrArrayFromWcharArray(ClientFields, pClientFields, size);
}
return &ClientFields;
}
You can access the elements of the array inside the variant with something like this:
void ShowBstrArray(const VARIANT var)
{
if (var.vt != (VT_ARRAY | VT_BSTR))
return;
SAFEARRAY* psa = var.parray;
for (long i = 0; i < (long)psa->rgsabound[0].cElements; i++)
{
BSTR bstr;
SafeArrayGetElement(psa, &i, &bstr);
CString s = bstr;
AfxMessageBox(s);
}
}
void Test()
{
_variant_t* pFields = GetClientFields();
ShowBstrArray(*pFields);
}
However, when accessing most or all of the elements in the array, the following alternatives, which make use of SafeArrayAccessData , are more efficient:
void BstrArrayFromWcharArray2(VARIANT& var, WCHAR** pStrings, UINT size)
{
var.vt = VT_ARRAY | VT_BSTR;
var.parray = SafeArrayCreateVector(VT_BSTR, 0, size);
BSTR HUGEP* pbstr = NULL;
if (FAILED(SafeArrayAccessData(var.parray, (void HUGEP**)&pbstr)))
return;
for (UINT ix = 0; ix < size; ix++)
pbstr[ix] = ::SysAllocString(pStrings[ix]);
SafeArrayUnaccessData(var.parray);
}
void ShowBstrArray2(const VARIANT var)
{
if (var.vt != (VT_ARRAY | VT_BSTR))
return;
SAFEARRAY* psa = var.parray;
BSTR HUGEP* pbstr = NULL;
if (FAILED(SafeArrayAccessData(psa, (void HUGEP**)&pbstr)))
return;
for (UINT i = 0; i < psa->rgsabound[0].cElements; i++)
{
CString s = pbstr[i];
AfxMessageBox(s);
}
SafeArrayUnaccessData(psa);
}
I tried it with VS6 and it seemed to work fine. Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|