|
transoft wrote: while ((DWORD)lpHeader < (DWORD)(((LPSTR)lpStart) + size) && pt != NULL)
I have just reread this and it seems to me that your casts are redundant. lpStart and lpHeader are both LPTTPOLYGONHEADER types, so they should be comparable without the need for casting. Try rewriting as
while (lpHeader < (lpStart + size) && pt != NULL)
|
|
|
|
|
I'm recently learning C#. In C# you can pass parameters by value or by reference, and as you know, there are value types and reference types in C#.
I don't know if reference in C# means the same thing as in C++. But I think passing a reference type by reference in C# is similar to passing a pointer "by reference" in C++ (Reference to Pointer). As in both cases, the callee can change the values of the object’s state data as well as the object the ref type/pointer is referencing/pointing to.
What do you think?
I've written a program in C++ using "Reference to Pointer".
#include <iostream>
#include <string>
using namespace std;
class Person
{
private:
string name;
public:
Person(string s)
{
name = s;
}
Person()
{
name = "";
}
void SayHello()
{
cout << "Hello, my name is " << name << "!" << endl;
}
};
void Swap(Person *& a, Person *& b)
{
Person *temp;
temp = a;
a = b;
b = temp;
}
int main()
{
Person *p1 = new Person("Alice");
Person *p2 = new Person("Bob");
cout << "Before swapping:" << endl;
p1->SayHello();
p2->SayHello();
cout << endl << "Memory address of *p1:" << p1 << endl;
cout << "Memory address of *p2:" << p2 << endl;
Swap(p1, p2);
cout << endl << "After swapping:" << endl;
p1->SayHello();
p2->SayHello();
cout << endl << "Memory address of *p1:" << p1 << endl;
cout << "Memory address of *p2:" << p2 << endl;
delete p1;
delete p2;
return 0;
}
This program swaps the objects that p1 and p2 points to by passing them to Swap() by reference.
However, if I define Swap() like this:
void Swap((Person *) &a, (Person *) &b)
the compiler would display some error messages.
Swap.cpp(27) : error C2065: 'a' : undeclared identifier
Swap.cpp(27) : error C2065: 'b' : undeclared identifier
Swap.cpp(28) : error C2448: 'Swap' : function-style initializer appears to be a function definition
Swap.cpp(47) : error C3861: 'Swap': identifier not found
I really don't know why there would be errors. Why are those two definitions different?
Finally, I wonder if you know how to do the same swapping job in Java. As you know, in Java I can only pass parameters by value. Do you have any solutions?
|
|
|
|
|
You really don't need a reference to a pointer here.
It can be a reference to an object.
void Swap(Person& a, Person& b)
{
Person& temp = a;
a = b;
b = temp;
}
Then in the above case it would be called as -
Swap(*p1, *p2);
But objects need not be always created using new like in C#.
In C++ you can create objects on the stack using the syntax -
Person p1("Alice");
Person p2("Bob");
Now the Swap call would be -
Swap(p1, p2);
«_Superman_»
I love work. It gives me something to do between weekends.
modified on Friday, September 18, 2009 10:18 AM
|
|
|
|
|
«_Superman_» wrote: void Swap(Person& a, Person*& b)
Superman, you have one more * than common men, of course.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The perils of HTML editing.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thank you for replying.
Yes I know I can use a ref to obj directly.
But in C#, classes can only be ref types.
If I pass an object to a method, I'm passing a ref type.
And I can pass this ref type either by value or by ref (using the ref kerword).
I don't know if C# reference is the same as C++ reference, but I think passing a ref type by value/ref in C# is similar to passing a pointer by value/ref in C++.
If I pass a ref/pointer by ref, I can change the state of the obj it references/points to, and I can reference/point to other objects.
My questions are:
Why void Swap((Person *) &a, (Person *) &b) doesn't work?
And how do I write a similar Swap() method using Java? Can I?
|
|
|
|
|
lhyblue wrote: But in C#, classes can only be ref types.
This isn't C#, it's C++. A C++ reference is more like the ref keyword thing. For example, the following function definition will modify the parameter value that's passed in, such that the underlying variable is altered:
void Modify(int & a) { a += 2; }
lhyblue wrote: I don't know if C# reference is the same as C++ reference, but I think passing a ref type by value/ref in C# is similar to passing a pointer by value/ref in C++.
No. Passing a C# ref type by value is like passing a C++ object by value, by const reference or by const pointer. Passing a C# ref type by reference is like passing a C++ object either by non-const reference or by pointer.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote:
No. Passing a C# ref type by value is like passing a C++ object by value
I disagree: C++ makes a copy of the original object, while C# always pass a reference of the original object.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Mmmmmm - if that's the case, then C# always passes ref types by reference - what's the difference between ref and non-ref.
Can we just agree that C# is fundamentally wrong and be done with it
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: if that's the case, then C# always passes ref types by reference
Nope, C# (like Java ) pass all objects as references, (the reference to the object is passed by value). On the other hand, C++ makes a copy of an object passed by value.
Stuart Dootson wrote: what's the difference between ref and non-ref.
void foo(Goo goo)
can change the state of the object referenced by goo (similar to C++ reference or pointer to the object).
void fooWithSuperpowers(ref Goo goo)
can change goo itself, i.e. goo may be a reference to another object after function call (similar to a double indirection in C++ ).
Stuart Dootson wrote: Can we just agree that C# is fundamentally wrong and be done with it
Stuart Dootson wrote: Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Java, C#, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
FFY
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Give me Haskell, where all data is immutable and we don't need to worry about passing things by value, reference, pointer or anything else - oh, and it's so lazy that it might just decide not to pass anything anyway, if it decides it's not required.
PS - thanks for explaining ref vs non-ref - I guess in C++ that is a reference to a pointer vs. a pointer?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: I guess in C++ that is a reference to a pointer vs. a pointer?
Yes a reference to a pointer (or a pointer to a pointer) vs a pointer.
BTW Real men (aka Klingon programmers), you know, don't use C++ or C# sissy features like references, they go straight with pointers.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Saturday, September 19, 2009 6:38 AM
|
|
|
|
|
Na - real men are programming in assembly, so it's all just (untyped) addresses...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Real men leave assembly to Rajesh's coding monkeys...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Possibly not, if they want it done right…
Sometimes (especially in an embedded world), assembly's the only way...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have an MFC dialog based application which calls CoCreateInstance() to create an instance of internet explorer.After Navigating to the html page I need to call a javascript function in my html page. But when calling GetIdsOfNames through the dispatch interface I get DISP_E_UNKNOWNNAME error.can any one suggest me I get this error.
MOHANRAJ
|
|
|
|
|
Well, that says you're accessing a name that doesn't exist...but what name are you looking for , and which object are you querying for that name?
Give some detail, man!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
From MSDN [^]:
An IDispatch implementation can associate any positive integer ID value with a given name. Zero is reserved for the default, or Value property; -1 is reserved to indicate an unknown name; and other negative values are defined for other purposes. For example, if GetIDsOfNames is called, and the implementation does not recognize one or more of the names, it returns DISP_E_UNKNOWNNAME, and the rgDispId array contains DISPID_UNKNOWN for the entries that correspond to the unknown names.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi, all
I have a problem during applying custom visual-style to my mfc application.
I want to apply custom style from my ShellStyle.dll file, (not from the default %windir%/shellstyle.dll)
How can I avoid the loading of system file to load my custom file as visual style for my application ?
Thanks in advance,
themilan
|
|
|
|
|
Howdy,
I've never seen any mention of specifying a different DLL file to be used by windows to draw your app.
I've seen instances of people using the DrawThemeXXXXXXXX() functions found in uxtheme.h & UxTheme.dll,
though have never been able to see a possible way to load your own theme data.
Reading from "http://msdn.microsoft.com/en-us/library/bb762202(VS.85).aspx": SHGetShellStyleHInstance first attempts to load the version of Shellstyle.dll from the current active visual style. If that is unsuccessful, the version stored in the System32 directory is used.(EDIT: however, that function is deprecated after winXP sp2, so that rules out placing a hook on the function and returning a handle to your own DLL)
In short, the only way I've ever themed applications is myself, the hard-way. I.e define all of the bitmaps to be used for your window edges/features/controls etc and then code in the rules that define how they'll be applied (think about the 'behaviour' of WMP11 as it's resized)
Of course, you could just search for one of the many styling libraries out there. There's a great one floating around here somewhere. I think it's called the StyleToolkit by (Darren Sessions)
Here: 'ave a look at this: http://www.codeproject.com/KB/GDI-plus/Style_Toolkit.aspx
|
|
|
|
|
Thanks to 'enhzflep' for the reply,
I also want to know that, how can I hook system function to avoid returning of system dll by supplying my custom dll handle ?
From,
themilan.
|
|
|
|
|
Hello
I have a code where 2 double data types are added,
double = double1 + double2;
I am purposefuly not declaring a variable of type double and writing
what the issue am facing is,
sometime the double2 becomes negative. but i want to ignore the negative and just ad the 2 numbers.
so can i do like,
double = double +- double2;
Let me know.
|
|
|
|
|
I believe what you are looking for is abs , that will give you the "absolute value" of whatever you feed it, so if your value is 123, it will give you 123, if it is -321, it will give you 321. Is that what you want?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
modified on Friday, September 18, 2009 8:47 AM
|
|
|
|
|
Ya i want to avoid the negative that sometimes comes up with double2.
so how to do that programmatically?
can you show a sample code?
so does that mean, there is a better way to do that, rather than doing,
double = double1 +- double2; ?????
|
|
|
|
|
This:
dipuks wrote: double = double1 +- double2;
translates into this:
double = double1 + (-1 * double2);
Thus, it will turn your negative double2 to positive BUT it will also turn positive double2 to negative which is i supose not what you want.
But this:
double = double1 + abs(double2);
will ALWAYS work with a "positive double2 ".
You could also do this:
double = double1 + ((double2 > 0)?double2:-double2)
or
if (double2 > 0) double = double1 + double2;<br />
else double = double1 + -double2;
or
if (double2 > 0) double = double1 + double2;<br />
else double = double1 - double2;
Or i don't understand what you want to do.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|