Click here to Skip to main content
15,914,795 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
Generalputting custom icons Pin
Anonymous19-May-05 3:48
Anonymous19-May-05 3:48 
QuestionSOS!Why I could not call the function from a dll? Pin
kiluar18-May-05 22:41
kiluar18-May-05 22:41 
AnswerRe: SOS!Why I could not call the function from a dll? Pin
Sergey Solozhentsev30-May-05 5:25
Sergey Solozhentsev30-May-05 5:25 
GeneralATL VC 7.xxx Pin
oscarferreira118-May-05 11:51
oscarferreira118-May-05 11:51 
Questionhelp: why a ATL control created in VC can not work well in vb? Pin
ictory18-May-05 3:29
ictory18-May-05 3:29 
AnswerRe: help: why a ATL control created in VC can not work well in vb? Pin
Jörgen Sigvardsson18-May-05 12:14
Jörgen Sigvardsson18-May-05 12:14 
Generalsimple c++ question Pin
Timothy_198217-May-05 0:53
Timothy_198217-May-05 0:53 
GeneralRe: simple c++ question Pin
James R. Twine17-May-05 1:23
James R. Twine17-May-05 1:23 
   First difference, this is the wrong forum for this post!  But, since people make honest mistakes...

   Behind the scenes, there is no difference, at least not in VC++ 6.0.  How references are implemented by a compiler is completely up to the compiler, but VC++ uses pointers.  For example, if you create a function in a DLL that takes a reference, and you call it from a C program and pass in a pointer, it will still work correctly (at least, using the same builds of VC++ 6.0).

   As far as usage, references are only available in C++, not in C.  Pointers have to be manually dereferenced in order to modify the item that it points to.  References do this automatically, so the syntax of using them is different.  For example:
int FuncA( int &iTest )
{
    iTest = 10;          // Modifies Variable Passed In As "iTest"
    *iTest = 10;         // Wrong - References Do Not Need To Be Dereferenced Like Pointers
    return;
}
 
int FuncB( int *piTest )
{
    *piTest = 10;       // Modifies Variable Pointed To By piTest
    piTest = 10;        // Wrong - Modifies The Location The Pointer Points To
    return;
}
   Think of a reference as an "atomatically-dereferencing" pointer.  Barring IntelliSense or a similar coding aid, when you use references, it becomes easy for someone else to call the function not realizing that their variable may be modified by the function.  When using pointers, they have to take the extra step to pass in the address of the variable, so they have an idea of what is going to happen (assuming non-const here).

   Additionally, you can pass in a NULL pointer to a function, to indicate "nothing", but a reference has to refer to a real instance of something.  For example, you can have an int pointer with a value of NULL, which means a pointer to nothing/nowhere, but you cannot have a reference that refers to nothing (barring some sneaking coding tricks).

   References also have to be initialized, pointers do not:
<CODE>int iValue;     // Bad Habit, But Works
int *piValue;   // Bad Habit, But Works
int &riValue;   // Wrong - Will Not Compile At All
   There are a lot more details available on pointers and references beyond what I have written here...

   Peace!

-=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites
(Please rate this post!)
GeneralRe: simple c++ question Pin
Timothy_198217-May-05 1:27
Timothy_198217-May-05 1:27 
GeneralRe: simple c++ question Pin
James R. Twine17-May-05 3:31
James R. Twine17-May-05 3:31 
GeneralRe: simple c++ question Pin
[tlg]1-Jun-05 14:29
[tlg]1-Jun-05 14:29 
GeneralImplementing and exposing multiple Event interfaces in ATL. Pin
James R. Twine16-May-05 7:47
James R. Twine16-May-05 7:47 
GeneralRe: Implementing and exposing multiple Event interfaces in ATL. Pin
Stuart Dootson16-May-05 20:54
professionalStuart Dootson16-May-05 20:54 
GeneralRe: Implementing and exposing multiple Event interfaces in ATL. Pin
James R. Twine17-May-05 1:00
James R. Twine17-May-05 1:00 
GeneralRe: Implementing and exposing multiple Event interfaces in ATL. Pin
Stuart Dootson17-May-05 1:37
professionalStuart Dootson17-May-05 1:37 
GeneralRe: Implementing and exposing multiple Event interfaces in ATL. Pin
James R. Twine17-May-05 3:35
James R. Twine17-May-05 3:35 
GeneralATL Addin Pin
Raj72315-May-05 10:44
Raj72315-May-05 10:44 
GeneralIncreasing height and width of the ActiveX Control Pin
ajalilqarshi12-May-05 19:54
ajalilqarshi12-May-05 19:54 
GeneralRe: Increasing height and width of the ActiveX Control Pin
ajalilqarshi18-May-05 19:38
ajalilqarshi18-May-05 19:38 
GeneralAdding WTL to an MFC project Pin
rajas12-May-05 18:38
rajas12-May-05 18:38 
GeneralRe: Adding WTL to an MFC project Pin
Michael Dunn13-May-05 12:22
sitebuilderMichael Dunn13-May-05 12:22 
GeneralRe: Adding WTL to an MFC project Pin
rajas15-May-05 7:08
rajas15-May-05 7:08 
GeneralRe: Adding WTL to an MFC project Pin
Michael Dunn17-May-05 17:34
sitebuilderMichael Dunn17-May-05 17:34 
GeneralIs this Possible Pin
ThatsAlok11-May-05 21:07
ThatsAlok11-May-05 21:07 
GeneralRe: Is this Possible Pin
Vi212-May-05 21:13
Vi212-May-05 21:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.