|
SilverShalkin wrote:
Hex Dec Oct: What is the differance and why use them seperat from each other.
The difference is what base they use. We use decimal because we have 10 fingers, so it was natural in the evolution of math that we consider 10 to be the number that requires one more significant figure. Computers think in binary, which meshes nicely with base 8 (octal ) and base 16 (hex). I've never seen oct used for anything in particular.
The Windows calculator program can show you how the same number is displayed in the different bases, or look at my ostringstream article for a way to stream a number out as different bases. It works the same way if you're just streaming to cout.
SilverShalkin wrote:
Globals: How do you decalare a global inside of a little program?
Just by declaring it. Any variable declared outside of a class or function is global. When you're doing it in C++, the best way is to use extern, which tells the compiler a variable exists, but does not declare it. use extern int i in stdafx.h, and int i in stdafx.cpp to make a variable visible everywhere.
You would be foolish not to wrap such variables in a namespace, so that they have some protection from corruption. Even then, avoid globals if you can.
SilverShalkin wrote:
MFC - C++: Ive asked this question before... im going to build a game engine that would allow me to build 2D games that i would like to host over the internet... The engine i would like it to be all in windows, but what language or toolkit should i use? MFC or C++, what one would give me more flexibility and make the job allot less work than it already seems to be?
MFC is a library that you use in C++, you probably mean MFC or Win32. MFC will take a lot of work away because of the stuff it gives you for networking and so on, but I'd suggest Win32 with DirectX, because you'll need DX anyhow for DirectDraw, and it gives you the networking stuff as well, in DirectPlay.
SilverShalkin wrote:
Null: Ive seen the 'null' statement used all the time, but i dont know what it is used for. "i think this is a vary newbie question but you know
A pointer that does not point to a valid address should point ot 0. Calling delete on such a pointer will not do anything. NULL is a #define, it equates to (void*) 0.
SilverShalkin wrote:
Switch (break and continue): I understand the switch "I think" but im not to sure on break and continue commands... How do i use them?
You don't use continue in break statements. If you don't use a break in a switch, it falls through, like this:
int i = 0;
switch (x)
case 0:
i = 7;
default:
i = 10;
In this case i will always equal 10, because even the case 0 will fall through and the defaul will also execute.
contine and break are used in loops, break stops the loop and continue jumps to the next iteration, so the loop continues but any other code is not executed for this iteration only.
SilverShalkin wrote:
Delete: how do i use this? and what is the syntax?
If a variable is a pointer, then it vecomes an object when it is created with new, and the memory is deallocated and the destructor called when delete is called. You should also set this pointer to NULL.
int * p = new int;
*p = 7; // NOT p = 7, that sets the memory address, not the value )
// use p
delete p;
*p = 5; // ERROR - memory is deallocated
p = NULL;
SilverShalkin wrote:
Public: I looked this one up, but didnt understand. Public: its not a goto statment is it? (dont think so) why use this? also, there is a private: one, how do you use these and why?
In a class, you have functions and members. Anything that is public is visible by anyone who has an instance of a class. private is visible only to the class itself. Often variables are made private and exposed through methods that can validate the data being put into a variable. For exmaple if 0-100 is a valid range for a variable, the closest I can get is a char or unsigned char, but I need to validate the values coming in, or I could get values between -127 and 127, or 0 and 255.
SilverShalkin wrote:
return: Return like in the int main() and return 0; i understand, but... there is other things that you can do with the return statment that i dont quit get... can any one help?
All you can do is return a value. What don't you get ?
SilverShalkin wrote:
~#if and #define and #endif #else... : why is there a # sign on these? and the define, what does it do, or what is its purpose?
Because they are processed by the preprocessor. They can be used to create different versions ( such as debug and release ) or to create macros. The preprocessor uses them to decide what code is passed to the compiler.
SilverShalkin wrote:
~std::stream: What does this do?
~std::fstream: what does this one do, and what is its differance to the other one?
~if stream and stream: what do these do? "these last ones are just a (curiosity) and could probably help allot in the future.
Is there a std::stream ? Surely it's a base class. IOStreams are part of the standard library. A fstream is a bidirectional file stream, ofstreams and ifstreams also exist. Read my article on ostringstream - ofstream works the same way, and both work the same way as cin/cout.
SilverShalkin wrote:
Class: what is a class used for?
To encapsulate a block of logic. For exmaple, MFC has a CPoint class, it encapsulates the data and operations one might do on a point. I can create an instance of a CPoint and I can add them together, compare them, etc. It's a powerful tool to hide implimentation details from users of an object, and also simple to organise code.
SilverShalkin wrote:
Sound: I really desire to make a sound engine for my game, "and if not in my game" just somthing that would be fun to program and mess around with. But i dont know exactly where to start with the sound and how to send sound to the speakers. Can anyone help in this?
For games you should use DirectSound, so you can play more than one sound at the same time.
SilverShalkin wrote:
Well, thats all, "allot of questions like i said" but this is like a week of reading and toiling with out asking any at all " Some of the questions may be stupid and some maybe so lame or easy that maybe a quick syntax would help Sorry for the annoyance "to those who this annoys..."
Anyone who gets annoyed that you're trying to learn something is best ignored, not apologised to. The number of questions probably means I've given brief answers, but just ask if no-one here has yet clarified any of these points sufficiently.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
Thanks guys, the info that ive recieved is going to help allot Im off to program a little more and ask questions a little less "I dont know if that'll ever happend though "
~There is an end, when you cant learn any more... isnt there?
Thanks Again!
~SilverShalkin
ps... To those whom this annoys,...
I see thee no more
Christian Graus wrote:
Anyone who gets annoyed that you're trying to learn something is best ignored, not apologised to.
right when you think you have
learned it all, there is always
somthing that'll come allong just
to annoy you. I guess thats why
programming could be considered as the
unsolvable puzzle
where you recieve a peice of the picture
ever so often but still have thousands
of peices left.
|
|
|
|
|
SilverShalkin wrote:
~There is an end, when you cant learn any more... isnt there?
IMO
Other than when your dead...nope...
Programming is like:
The more you know, you more you realize the less you know.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
HockeyDude wrote:
Other than when your dead...nope...
Hockey
I think what he meant is that once you get too old you cannot learn anything more, not that you reach a stage where there is nothing more to learn. I might be wrong though, in which case, your statement that till death, human beings can learn and learn and learn is correct
Nish
I am the Keyboard Smasher
|
|
|
|
|
Age doesn't have a bearing on anyones ability to learn I don't think.
Certainly some go crazy, but even crazy people probably learn...like OUCH better not smash my head into the wall like that again...
Everything/body learns until the end, then it's your guess against mine to what happens after that. Maybe it's like the Matrix and we come back and learn some more...?
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
HockeyDude wrote:
Programming is like:
The more you know, you more you realize the less you know.
Not Only programming Hockey,everything..everything.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I knew somebody was gonna jump on me for that.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hi,
I'm trying to programmatically create some virtual directories for a release process and I've run into a strange problem. If I create the virtual directory using the Internet Information Services control panel, the directory is fine and it has an icon of a box with a ball coming out of it. If I use the code shown below, it looks like it creates an application instead of a virtual directory like I think it should. The resulting icon is a folder with a little world on the right lower corner.
Can anyone see what I'm doing wrong with the code below?
Thanks in advance,
Craig
USES_CONVERSION;
try
{
HRESULT hr; // Generic COM result variable
_variant_t variant; // Variant used to set some properties in the metabase
IADsContainer* virtDirRoot; // Virtual root
IADs* virtDir; // The new virtual directory
IDispatch* pDisp = NULL;
//
// Get the virtual directory root
//
hr = ADsGetObject(L"IIS://Localhost/W3svc/1/ROOT",
IID_IADsContainer,
(void**) &virtDirRoot);
if(FAILED(hr))
{
return hr;
}
//
// Create the new virtual directory
//
_bstr_t virtPath("c:\\inetput\\wwwroot\\Test");
hr = virtDirRoot->Create(L"IIsWebVirtualDir", // Name of the virtual directory schema class
L"Test", &pDisp); // Relative name of the object to create
if(FAILED(hr))
{
IErrorInfoPtr error;
HRESULT hr;
CComBSTR description;
hr = GetErrorInfo(0, &error);
if (SUCCEEDED(hr) && error != NULL
&& SUCCEEDED(error->GetDescription(&description)))
{
//return description;
}
}
// Get the IADsContainer interface
hr = pDisp->QueryInterface(IID_IADs, (void**) &virtDir);
// Set the AspAllowOutOfProcess switch
variant = L"true";
virtDir->Put(METABASE_ALLOW_OUT_OF_PROC_COMPONENTS, variant);
virtDir->Put(L"AccessExecute", variant);
// Set the physical path
variant = physDirPath;
virtDir->Put(L"Path", variant);
//
// Set the info
//
virtDir->SetInfo();
return 0;
}
|
|
|
|
|
Using the MFC fn AfxBeginThread requires:
UINT MyFunc(LPVOID);
But using the API call CreateThread requires:
DWORD WINAPI MyFunc(LPVOID);
whats going on here?
|
|
|
|
|
AfxBeginThread calls internally CreateThread. But the address of your function isn't passed directly to Win32 API. In the middle there's also CWinThread object which accepts a function with slightly different header.
Just step into AfxBeginThread with the debugger and you'll see the details.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
hmm I checked the code. AfxBeginThread actually ends up calling _beginthreadex.
If I guess right, this is cos of the extensive C library calls MFC makes.
Someone please clarify this. sigh.
|
|
|
|
|
Satheesh wrote:
AfxBeginThread actually ends up calling _beginthreadex.
Make one step further. Step into _beginthreadex and you'll see the light (I mean, the CreateThread call). FYI, it'll be line 125 of THREADEX.C (on VC6 SP5).
MFC needs to prepare a environment for its thread. It's done via CWinThread object. And - since MFC is a C++ library, it needs to create threads with _beginthreadex to ensure that CRT works OK.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Too bad there aren't thread creation vectors you can set so that when a thread is created, the routine gets called automatically. Then MFC and CRT can install their own vectors and we could all call CreateThread.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
If you're a perverse enough process, you can probably launch yourself as a debugee and use WaitForDebugInfo.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
LOL...
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
The whole point is that the two functions are prototyped different. If they were both DWORDS it'd have been easy. Now one is an UINT. Thus we cant use both AfxBeginThread and CreateThread on the same function without changing the prototype manually. After all most of us do a return 0
Nish
I am the Keyboard Smasher
|
|
|
|
|
The mess gets a little worse when you are trying to produce a add on library. If your add-on requires that MFC or CRT has been initialized in a thread, then you have to depend on the user invoking the right routine. IMHO, a perfect world would be one where I could do something and then the programmer would only have to call CreateThread and CRT is initialized for my via some back door method.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
think I am doing somthing wrong here. I cant find threadex.c even though I have SP5 installed. The debugger cant find it and I cant either!!Satheesh
|
|
|
|
|
Hi,
I have been loading images from memory directly into GDI+ Bitmap Objects. This involved creating a stream. Somebody recommended that I used CreateStreamOnHGlobal, which works great.
Now I am looking at doing the reverse, saving JPEG data represented by the Bitmap object into memory again through a stream and createstreamonhglobal. My question is how do i know how big I have to make the global alloc, do i just have to make sure it's sufficient or is there anyway of determining the size or making the size of the stream dynamic. Hope this is clear, any advice or comments would be grately appreciated.
Thanks Again
Rich
|
|
|
|
|
You do not have to worry about the size of the stream, it will automatically resize itself as space is needed.
There is no real way to determine how large a JPEG will be until you compress it as if you were going to save it to a file. So allocate a small memory buffer with CreateStreamOnHGLOBAL and then pass the stream object to Save in the bitmap, the memory will be taken care of for you.
If you do find a way to determine how mush space your image will take, you can use the SetSize method to reallocate memory in your stream.
|
|
|
|
|
When I'm using a DialogBar, with controls on it (particulartly Frames, and Buttons)..... do standard procdedures using a dialogBar in a Doc/View application, make a dialogresource, set an ID for the dialog bar, ID's for the controls...etc...
When I implement the code for the button in a dialogbar it works fine.. but when i implement code for a frame control(the message map in CLASSWIZARD is only BN_CLICKED), when i click on the frame when i run the program, it doesn't get executed...
How come when iclick on the button control in the dialogbar something gets executed, but when i click on the frame control, nothing gets executed?? is this a bug in Visual C??
|
|
|
|
|
AFAIK, buttons send messages to their parent window, not their owner. (when a dialog bar is not docked, it's parent is no longer the frame window; instead it is a child of a mini-frame created to float it)
You'll have derive a class CDialogBar and put the code to handle the button press in that. Then you can forward it on to your frame window if necessary.
And if words were wisdom, I'd be talking even more. The Offspring, I Choose
|
|
|
|
|
Actually the messges of my buttons in my Dialog Bars works fine...even if the dialog bar is docked or floating but the messges of the Frame Controls in the Dialog Bar doesn't....
How do I forward messages to my FrameWIndow??
|
|
|
|
|
Sorry, i'm misunderstanding you. Do you mean the controls on the frame, like the close or maximize buttons, or do you mean a STATIC control drawing an etched frame w/ in the dialog bar?
And if words were wisdom, I'd be talking even more. The Offspring, I Choose
|
|
|
|
|
I mean the Static Control drawing an etched frame within the dialog bar.... when you make a dialog resource, VS has toolbars that lets you draw any kinds of controls in the dialog resource.... The toolbar button that says picture control....
|
|
|
|
|