|
I am sorry that ,I forgot the code:"++index;" in the loop.
|
|
|
|
|
kcynic wrote: I am sorry that ,I forgot the code:"++index;" in the loop.
Ok, so where do you want to put it? Like this:
int curPlayer = 12;
TCHAR Rools[12];
int index = 0;
int temp;
TCHAR* q = Rools;
while(1)
{
temp = 5;
itoa( temp, q++, 10 );
if( index >= curPlayer )
{
break;
}
++index;
}
Actually I mixed up the order of which the variables are located on the stack in my previous post. What happens is that curPlayer gets overwritten by itoa() with the terminating zero.
In the code above curPlayer will be overwritten when index equals 11.
You have basically made two errors:- You have an array with 12 elements which means that the highest index is 11 and you are deliberately accessing index 12, which is out of bounds. In C/C++ everything is zero-based so the first index is 0 and not 1.
- You haven't accounted for the fact that
itoa() adds a terminating zero to the target string after the conversion.
I suggest you debug the code and step through the loop while watching the memory window so you can see how the array contents change when itoa() is called.
If you increase the Rools array size to 13 you may find extra bytes allocated on the stack due to variable alignment between the Rools array and curPlayer . Those bytes shall never be accessed.
In my opinion you should use a for-loop instead of a "while-forever-loop". It will make more sense and it's also easier to read and understand what the code is supposed to do.
If you want a working example to compare with it could look like this:
int curPlayer = 11;
TCHAR Rools[12];
int index = 0;
int temp = 5;
TCHAR* q = Rools;
for( index = 0; index < curPlayer; ++index )
{
itoa( temp, q++, 10 );
}
Hope this helps
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks,I do know what error happened in the codes,now.
And I would be more carefully in future.
BEST WISHES.
|
|
|
|
|
How can i detect that if my process runs in remote desktop session when another PC connected to my PC ?
Additionally , how can i detect the situation if my PC connects to a remote desktop session ?
THANK YOU VERY MUCH
|
|
|
|
|
Akin Ocal wrote: How can i detect that if my process runs in remote desktop session when another PC connected to my PC ?
Read the %SessionName% environment variable and see if it contains the characters 'RDP'
Best Regards,
-Randor (David Delaune)
|
|
|
|
|
Hi all:
Scott Meyer once stated that:
In C++, when declaring a class which will involve dynamic memory allocation, an extra constructor and an extra operator should be included.
Can I ask what they are?
Thank you
|
|
|
|
|
Scott Meyers is referring to the "copy constructor" and the "copy assignment operator". If you don't create these yourself, the compiler will create default ones. However, these default methods will only do a memory copy. Thus, you will have pointers pointing to the same dynamic memory allocations.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
hi all. i face a very simple problem.
my app outputs two windows using glut. both windows have the same display function and i want to display different things on each window. therefore, within the display function, i want to switch between the windows and display accordingly...how do i go about doing that?
--
dg
|
|
|
|
|
Do you have two dialogs window?
|
|
|
|
|
no..these are two separate windows that are configured to play apps - they are not dialog boxes
--
dg
|
|
|
|
|
I was wondering does someone know any good place to learn about how to use the xloper structure that in inherently built into Excel.
I am trying to pass some Excel ranges into a C++ DLL to do some calculations. What should I do?
|
|
|
|
|
A7Zulu wrote: I am trying to pass some Excel ranges into a C++ DLL to do some calculations. What should I do?
I would use Excel Automation.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
so i actually need the excel data stored something like this
typedef struct {
unsigned short iRows, iCols;
double dArray[FPARRAY_SIZE];
} FPARRAY;
to pass to this financial package library...
i know excel has internal structures that look like this, i was just wondering how to get this...
|
|
|
|
|
I was wondering I created a dll in C++ and a function is called from Excel
typedef struct {
unsigned short iRows, iCols;
double dArray[FPARRAY_SIZE];
} FPARRAY;
I want to return a pointer to this struct back to Excel, so that I can access that new data created in my dll.
If this is impossible, how do I get data set/created in C++ back into Excel so it can be viewed?
Thanks
|
|
|
|
|
|
Hi,
I would like my VC++ client application to dynamically instantiate a class defined in a DLL knowing only (1) a DLL file name and (2) the name of a class defined in the DLL. Is this possible without using .NET?
Here's what I am currently doing...
An exported function in a DLL returns an instance of the class MyDerivedClass (which is a class derived from MyBaseClass):
extern "C" <br />
{<br />
__declspec(dllexport) MyBaseClass* getMyBaseClass()<br />
{<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState())<br />
MyBaseClass* answer = (MyBaseClass*)new MyDerivedClass();<br />
return (answer);<br />
}<br />
}
My client application loads the DLL at the appropriate time and calls the known, exported function to retrieve a pointer to a newly instantiated MyBaseClass object:
CString libraryFileName = ...<br />
<br />
HINSTANCE library = ::LoadLibrary(libraryFileName);<br />
<br />
typedef MyBaseClass* (*ExternalFunction)();<br />
ExternalFunction function = (ExternalFunction)::GetProcAddress(library, "getMyBaseClass");<br />
<br />
MyBaseClass* aBaseClass = function();
This approach works fine but I think it would be cleaner for developers of the DLL to only have to define their MyBaseClass-derived class in the DLL and not have to implement the 'C' function to return it.
Any and all help appreciated!
Peter
|
|
|
|
|
Try putting the __declspec(dllexport) on the class definition itself so the entire class is 'exported'
<br />
__declspec(dllexport) class CMyBaseClass<br />
{<br />
};<br />
//Generally what you do is include the header file in both dll and client and use something like this.
MYAPI class CMyBaseClass<br />
{<br />
};<br />
where MYAPI is #define d to __declspec(dllexport) for the Dll and __declspec(dllimport) for the client.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thanks for your response. Unfortunately, I do not believe that your solution is exactly what I was looking for. Let me clarify a few things...
Although the client knows about MyBaseClass (it includes the MyBaseClass header file), it does not know about the MyBaseClass-derived class defined in the DLL (it does NOT include the MyDerivedClass header file, nor do I want it to).
The client application's configuration file contains a DLL file name and the name of a MyBaseClass-derived class. At runtime, the client application loads the DLL (using the configured file name) and dynamically instantiates the MyBaseClass-derived class (using the configured class name).
I want my developers to be able to develop multiple DLLs, each housing a different MyBaseClass-derived class (e.g., MyDerivedClass1, MyDerivedClass2...). Custom functionality will be implemented simply by overriding the appropriate MyBaseClass methods.
Simply by configuring the client to use a different DLL and class name, the behaviour of the client can be changed without ever changing the client code!
Does anyone know if this is possible without using the .NET reflection classes?
Peter
|
|
|
|
|
I think I understand more clearly now. If you want to instantiate, possibly unknown, classes based on data then It's going to have to be COM or .NET I'm afraid. What you have at the moment is like a mini version of the way COM class factories work. There's an MSDN article in the ether somewhere called "From CPP to COM" which is what cracked COM for me. I'd take a look at that even if you eventually decide to go the .NET route.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
|
|
Hi,
after reading this thread I've maybe found a solution.
I think you could solve it with using templates.
The Base class:
class BaseClass
{
public:
BaseClass() {}
virtual void Show() = 0;
template<class T>
static BaseClass* Create()
{
return dynamic_cast<BaseClass*>(new T());
}
};
The derived class
class DeriveOne : public BaseClass
{
public:
DeriveOne() {}
virtual void Show()
{
std::cout << "DeriveOne.Show" << std::endl;
}
};
Then you could create a object like this
BaseClass* pBase = BaseClass::Create<DeriveOne>();
if(pBase != NULL) pBase->Show();
I don't know if this is what you need.
codito ergo sum
|
|
|
|
|
I'm using matlab 7.0.1 (R14 sp1)
I want to CONVERT my GUI to a stand alone application (.exe file) that dosent need Matlab to run.
I uesed the mcc function but I faild
I uesd this code
mcc -m mygui.m
it creates an .exe file and some other files
when I run the .exe file, a black window appears for seconds then nothing happen
plz I need ur help
-- modified at 15:51 Tuesday 19th June, 2007
|
|
|
|
|
I have a listview control and i would like to change the background colour of it.. How would i implement this in pure C/C++ using the Win32 API?
Thanks for your help!
--PerspX
|
|
|
|
|
BOOL bSystemColor = FALSE;
COLORREF clrNew = RGB(0,0,0);
COLORREF clrOld = (COLORREF)SendMessage(m_hWnd, EM_SETBKGNDCOLOR, bSystemColor, clrNew);
Best Wishes,
-Randor (David Delaune)
|
|
|
|